Practical and theoretical implementation discussion.

tuomlarsen
 Posts: 16
 Joined: Mon Oct 29, 2012 6:02 am
Post
by tuomlarsen » Fri Nov 02, 2012 2:49 pm
Hi,
please, I have two questions regarding path tracing:
 when doing "importance sampling" (is this the same as "emitter sampling"?), do I have to "[l]oop over any lights" and add their contributions to final result or is it also ok just to pick one light randomly, multiply its contribution by the number of lights and add this to the result?
 when reading the source of
http://kevinbeason.com/smallpt/, on line #55 there is this
. Why is it there? What that is do?

graphicsMan
 Posts: 166
 Joined: Mon Nov 28, 2011 7:28 pm
Post
by graphicsMan » Sun Nov 04, 2012 2:31 am
You can either loop all the lights, or pick one or any number at random. If you're importance sampling, you probably want to pick fewer lights. The idea is that you could pick one light, say based on total emission power, and then you divide by the probability of picking that light.
This is the same as your example of picking one light and dividing by the number of lights, but only if all lights have the same power.
In Kevin's code, he is performing russian roulette. The idea is that you can decide whether or not to continue tracing. You do this based on a probability. If you decide to terminate, you have zero further contribution. But if you do not terminate, you have to divide by the probability. This will scale the values by an amount greater than 1 in order to compensate for the times you decide to terminate.

tuomlarsen
 Posts: 16
 Joined: Mon Oct 29, 2012 6:02 am
Post
by tuomlarsen » Sun Nov 04, 2012 10:53 am
Thank you for the explanations!
One more question though regarding the importance samling, if I were to pick a light and scale by the number of lights, why does it matter that they have to be of the same strength? If I pick the lights at random, on average it should be the same as picking based on total emission power. I mean, some time I pick strong light, another time a weak one, ..?
Also, in Kevin's code, why does he uses "the maximum of R, G, B" for the Russian Roulette? Why not, say their average or mean or something else? I assume the image converges whether is maximum or average, perhaps it's just some heuristic to make it converge faster?