@@ -968,14 +968,14 @@ SimpleRaytracer::subpixel_radiance(float x, float y, Sampler& sampler,
968968 Color3 path_radiance (0 , 0 , 0 );
969969 int prev_id = -1 ;
970970 float bsdf_pdf = inf; // camera ray has only one possible direction
971-
972971 MediumStack medium_stack;
973972
973+
974974 for (int b = 0 ; b <= max_bounces; b++) {
975975 ShaderGlobalsType sg;
976+
976977 // trace the ray against the scene
977978 Intersection hit = scene.intersect (r, inf, prev_id);
978-
979979 if (hit.t == inf) {
980980 // we hit nothing? check background shader
981981 if (backgroundShaderID >= 0 ) {
@@ -994,9 +994,8 @@ SimpleRaytracer::subpixel_radiance(float x, float y, Sampler& sampler,
994994 }
995995 break ;
996996 }
997-
998- if (medium_stack.integrate (r, sampler, hit, path_weight, path_radiance,
999- bsdf_pdf)) {
997+
998+ if (medium_stack.integrate (r, sampler, hit, path_weight, path_radiance, bsdf_pdf)) {
1000999 continue ;
10011000 }
10021001
@@ -1026,9 +1025,8 @@ SimpleRaytracer::subpixel_radiance(float x, float y, Sampler& sampler,
10261025 int shaderID = scene.shaderid (hit.id );
10271026
10281027#ifndef __CUDACC__
1029- if (shaderID < 0 || !m_shaders[shaderID].surf ) {
1028+ if (shaderID < 0 || !m_shaders[shaderID].surf )
10301029 break ; // no shader attached? done
1031- }
10321030
10331031 // execute shader and process the resulting list of closures
10341032 shadingsys->execute (*ctx, *m_shaders[shaderID].surf , sg);
@@ -1094,7 +1092,6 @@ SimpleRaytracer::subpixel_radiance(float x, float y, Sampler& sampler,
10941092 Ray::SHADOW);
10951093 Intersection shadow_hit = scene.intersect (shadow_ray, inf,
10961094 hit.id );
1097-
10981095 if (shadow_hit.t == inf) // ray reached the background?
10991096 path_radiance += contrib;
11001097 }
@@ -1124,30 +1121,37 @@ SimpleRaytracer::subpixel_radiance(float x, float y, Sampler& sampler,
11241121 Ray shadow_ray = Ray (sg.P , sample.dir , radius, 0 , 0 ,
11251122 Ray::SHADOW);
11261123 // trace a shadow ray and see if we actually hit the target
1124+ // in this tiny renderer, tracing a ray is probably cheaper than evaluating the light shader
11271125 Intersection shadow_hit
11281126 = scene.intersect (shadow_ray, sample.dist , hit.id , lid);
11291127
11301128#ifndef __CUDACC__
11311129 const bool did_hit = shadow_hit.t == sample.dist ;
11321130#else
1131+ // The hit distance on the device is not as precise as on
1132+ // the CPU, so we need to allow a little wiggle room. An
1133+ // epsilon of 1e-3f empirically gives results that closely
1134+ // match the CPU for the test scenes, so that's what we're
1135+ // using.
11331136 const bool did_hit = fabsf (shadow_hit.t - sample.dist )
11341137 < 1e-3f ;
11351138#endif
1136-
11371139 if (did_hit) {
1140+ // setup a shader global for the point on the light
11381141 globals_from_hit (light_sg, shadow_ray, sample.dist , lid,
11391142 sample.u , sample.v );
11401143#ifndef __CUDACC__
1144+ // execute the light shader (for emissive closures only)
11411145 shadingsys->execute (*ctx, *m_shaders[shaderID].surf ,
11421146 light_sg);
11431147#else
11441148 execute_shader (light_sg, shaderID, light_closure_pool);
11451149#endif
11461150 ShadingResult light_result;
11471151 process_closure (light_sg, r.roughness , light_result,
1148- medium_stack,
1149- ( const ClosureColor*)light_sg. Ci , true );
1150-
1152+ medium_stack, ( const ClosureColor*)light_sg. Ci ,
1153+ true );
1154+ // accumulate contribution
11511155 path_radiance += contrib * light_result.Le ;
11521156 }
11531157 }
@@ -1164,13 +1168,13 @@ SimpleRaytracer::subpixel_radiance(float x, float y, Sampler& sampler,
11641168 // Just simply use roughness as spread slope
11651169 r.spread = std::max (r.spread , p.roughness );
11661170 r.roughness = p.roughness ;
1167-
1171+
11681172 if (sg.backfacing ) { // if exiting
11691173 medium_stack.pop_medium ();
11701174 }
1171-
1172- if (!(path_weight.x > 0 ) && !(path_weight.y > 0 ) && !(path_weight. z > 0 )
1173- && b > 10 )
1175+
1176+ if (!(path_weight.x > 0 ) && !(path_weight.y > 0 )
1177+ && !(path_weight. z > 0 ) && b > 10 )
11741178 break ; // filter out all 0's or NaNs
11751179 prev_id = hit.id ;
11761180 r.origin = sg.P ;
@@ -1179,6 +1183,7 @@ SimpleRaytracer::subpixel_radiance(float x, float y, Sampler& sampler,
11791183}
11801184
11811185
1186+
11821187OSL_HOSTDEVICE Color3
11831188SimpleRaytracer::antialias_pixel (int x, int y, ShadingContext* ctx)
11841189{
0 commit comments