1
$\begingroup$

For those familiar with smallpt, the ray tracer in 99 lines: I am checking the code, and there is something that is not clear to me in the DIFFUSE ray scattering. After the rays are shot, they keep bouncing until the if-statement with the Russian Roulette stops them.

if (++depth>5) if (erand48(Xi)<p) f=f*(1/p); else return obj.e;

This means that, when rays are scattered and hit the light source, they don't actually stop there (which is what I thought at first: rays bounce until they hit the light source, or until they reach a specific amount of bounces). Am I missing something?

$\endgroup$
  • $\begingroup$ p is gonna be zero for light sources. Light sources are defined by emission variable and color is zero for them. Hence the reflectance parameter calculated previous to this line (p) would be zero giving us obj.e $\endgroup$ – gallickgunner Mar 29 at 15:41
  • $\begingroup$ Getting a bounce off a lightsource is normal - imagine that your light source actually reflects light (like in the real world). However as @gallickgunner mentioned in the specific scene that you have the light source does not reflect any light (this doesn't need to be the case however). $\endgroup$ – lightxbulb Mar 29 at 19:27
  • $\begingroup$ @lightxbulb - wouldn't the contribution by the reflected light in that case be negligible unless the light's emission is very dim. I've always wondered that we could model real world light sources by an outer non-emissive shell and an inner emissive part. That way we can safely say that we stop when ever we hit a light souce or more specifically the core emissive part. $\endgroup$ – gallickgunner Mar 30 at 23:20
  • $\begingroup$ @gallickgunner What does the lightsource being dim have to do with its reflectivity? On what basis do you say it's "negligible"? And why do you believe you can throw away "negligible" contributions? You can always model a light the way you said, but that's only if that model is accurate to your use case. Note that the proposed model also ruins NEE. $\endgroup$ – lightxbulb Mar 31 at 6:32
  • $\begingroup$ I mean if the light source isn't dim, you aren't going to see the outer shell anyway. The emission part will be much stronger than an indirect reflection off the surface of the light source. It's gonna be "negligible" in the sense that it's not gonna add much to what's already there due to the emission part. $\endgroup$ – gallickgunner Mar 31 at 7:12
0
$\begingroup$

p is gonna be zero for light sources. Light sources are defined by emission variable and color is zero for them. Hence the reflectance parameter calculated previous to this line p would be zero giving us obj.e

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.