ssloy/tinyraytracer

question on Step 6: shadows

simin75simin opened this issue · 3 comments

the instruction for step 6 has this line:
Vec3f shadow_orig = light_dir*N < 0 ? point - N*1e-3 : point + N*1e-3;
but i modified it to be something like
if (light_dir*N<0) continue; Vec3f shadow_orig=point+N*1e-3;
and still got the same result given the spheres and lights in the tutorial.
i am kinda convinced that this is another correct way to write it, and it potentially speeds things up a little. am i right?
thanks in advance.

ljgdsq commented

yea.i think so too.light_dir * N <0 means the point behind the sphere.it should in the shadow. we need't calc offset.because it aways in the shadow. am i right?

ssloy commented

Nope, light_dir * N < 0 means that the point is behind the sphere, but the sphere can be transparent, so we can't ditch the point directly.

ssloy commented

N*0.001 is better to move to ray-sphere intersection routine as it is done in the newest version:

if (t0>.001) return {true, t0}; // offset the original point by .001 to avoid occlusion by the object itself