Skip to content

Commit

Permalink
Fix incorrect double coordinate space conversion by passing volume tr…
Browse files Browse the repository at this point in the history
…ansforms to OptixScene objects; hopefully fixes the issue in #89.
  • Loading branch information
NBickford-NV committed Jul 13, 2020
1 parent 9ffc6b7 commit 439179d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 29 deletions.
3 changes: 1 addition & 2 deletions source/gFluidSurface/main_fluid_surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ void Sample::RebuildOptixGraph ()
// are both 0).
Vector3DF volmin = fluid.GetGridMin();
Vector3DF volmax = fluid.GetGridMax();
Matrix4F xform;
xform.Identity();
Matrix4F xform = gvdb.getTransform();
int atlas_glid = gvdb.getAtlasGLID(0);
optx.AddVolume( atlas_glid, volmin, volmax, xform, m_mat_surf1, 'L' );

Expand Down
3 changes: 1 addition & 2 deletions source/gInteractiveOptix/main_interactive_optix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ void Sample::RebuildOptixGraph ( int shading )
}
Vector3DF volmin = gvdb.getWorldMin ();
Vector3DF volmax = gvdb.getWorldMax ();
Matrix4F xform;
xform.Identity();
Matrix4F xform = gvdb.getTransform();
int atlas_glid = gvdb.getAtlasGLID ( 0 );
optx.AddVolume ( atlas_glid, volmin, volmax, xform, matid, isect );

Expand Down
3 changes: 1 addition & 2 deletions source/gPointCloud/main_point_cloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ void Sample::RebuildOptixGraph(int shading)
}
Vector3DF volmin = gvdb.getVolMin();
Vector3DF volmax = gvdb.getVolMax();
Matrix4F xform;
xform.Identity();
Matrix4F xform = gvdb.getTransform();
int atlas_glid = gvdb.getAtlasGLID(0);
optx.AddVolume( atlas_glid, volmin, volmax, xform, mat_list[ m_pntmat ].id, isect );

Expand Down
3 changes: 1 addition & 2 deletions source/gPointFusion/main_point_fusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ void Sample::RebuildOptixGraph ()
nvprintf("Adding GVDB Volume to OptiX graph.\n");
Vector3DF volmin = gvdb.getVolMin();
Vector3DF volmax = gvdb.getVolMax();
Matrix4F xform;
xform.Identity();
Matrix4F xform = gvdb.getTransform();
int atlas_glid = gvdb.getAtlasGLID(0);
optx.AddVolume( atlas_glid, volmin, volmax, xform, m_mat_surf1, 'S' );

Expand Down
37 changes: 16 additions & 21 deletions source/sample_utils/optix_vol_intersect.cu
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,12 @@ RT_PROGRAM void vol_intersect( int primIdx )
float4 hclr = make_float4(1,1,1,1);
float t;

//-- Ray march
// Transform from application space to GVDB's coordinate space
const float3 orig = mmult(SCN_INVXFORM, ray.origin);
const float3 dir = normalize(mmult(SCN_INVXROT, ray.direction));
//-- Ray march
// If the Optix transform node has been set up correctly, then the ray is in GVDB's coordinate system.
const float3 orig = ray.origin;
const float3 dir = ray.direction;
rayCast(&gvdbObj, gvdbChan, orig, dir, hit, norm, hclr, raySurfaceTrilinearBrick);
if ( hit.z == NOHIT) return;

// Transform from GVDB's coordinate space to application space
hit = mmult(SCN_XFORM, hit);
t = length ( hit - ray.origin );

// report intersection to optix
Expand All @@ -94,41 +91,40 @@ RT_PROGRAM void vol_deep( int primIdx )
float4 clr = make_float4(0,0,0,1);
if (ray_info.rtype == MESH_RAY ) return;

// Transform from application space to GVDB's coordinate space
float3 orig = mmult(SCN_INVXFORM, ray.origin);
float3 dir = normalize(mmult(SCN_INVXROT, ray.direction));
float3 orig = ray.origin;
float3 dir = ray.direction;

// ---- Debugging
// Uncomment this code to demonstrate tracing of the bounding box
// surrounding the volume.
/*hit = rayBoxIntersect ( orig, dir, gvdbObj.bmin, gvdbObj.bmax );
/* hit = rayBoxIntersect ( orig, dir, gvdbObj.bmin, gvdbObj.bmax );
if ( hit.z == NOHIT ) return;
const float t2 = length(mmult(SCN_XFORM, orig + hit.x * dir) - ray.origin);
const float t2 = hit.x;
if ( rtPotentialIntersection ( t2 ) ) {
shading_normal = norm;
geometric_normal = norm;
front_hit_point = mmult(SCN_XFORM, orig + hit.x * dir);
back_hit_point = mmult(SCN_XFORM, orig + hit.y * dir);
front_hit_point = orig + hit.x * dir;
back_hit_point = orig + hit.y * dir;
deep_color = make_float4( front_hit_point/200.0, 0.5);
rtReportIntersection( 0 );
}
return;*/
return; */

//-- Raycast
rayCast ( &gvdbObj, gvdbChan, orig, dir, hit, norm, clr, rayDeepBrick );
if ( hit.x==0 && hit.y == 0) return;

// Note that rayDeepBrick sets hit.x and hit.y to the front and back brick intersection points in GVDB's coordinate
// system, in contrast to the other functions in this file.
const float t = length(mmult(SCN_XFORM, orig + hit.x * dir) - ray.origin);
const float t = hit.x;

if ( rtPotentialIntersection( t ) ) {

shading_normal = norm;
geometric_normal = norm;
// Transform from GVDB's coordinate space to the application's coordinate space
front_hit_point = mmult(SCN_XFORM, orig + hit.x * dir);
back_hit_point = mmult(SCN_XFORM, orig + hit.y * dir);
front_hit_point = orig + hit.x * dir;
back_hit_point = orig + hit.y * dir;
deep_color = make_float4 ( fxyz(clr), 1.0-clr.w );

rtReportIntersection( 0 );
Expand All @@ -145,8 +141,8 @@ RT_PROGRAM void vol_levelset ( int primIdx )
//if (ray_info.rtype == SHADOW_RAY && ray_info.depth >= 1) return;

// Transform from application space to GVDB's coordinate space
float3 orig = mmult(SCN_INVXFORM, ray.origin);
float3 dir = normalize(mmult(SCN_INVXROT, ray.direction));
float3 orig = ray.origin;
float3 dir = ray.direction;

//-- Ray march
if (ray_info.rtype == REFRACT_RAY) {
Expand All @@ -158,7 +154,6 @@ RT_PROGRAM void vol_levelset ( int primIdx )
if ( hit.z == NOHIT) return;

// Transform from GVDB's coordinate space to application space
hit = mmult(SCN_XFORM, hit);
t = length ( hit - ray.origin );

// report intersection to optix
Expand Down

0 comments on commit 439179d

Please sign in to comment.