ssloy / tinyraytracer

A brief computer graphics / rendering course
https://github.com/ssloy/tinyraytracer/wiki
5.04k stars 333 forks source link

question on Step 6: shadows #30

Closed simin75simin closed 1 year ago

simin75simin commented 1 year ago

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 1 year ago

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 1 year ago

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 1 year ago

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

https://github.com/ssloy/tinyraytracer/blob/ce6b7852b7de11d485c017e16a9b990b94a66322/tinyraytracer.cpp#L74