Page 1 of 1

Importance sampling, color scaling

Posted: Fri Nov 02, 2012 2:49 pm
by tuomlarsen

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, on line #55 there is this

Code: Select all

. Why is it there? What that is do?

Re: Importance sampling, color scaling

Posted: Sun Nov 04, 2012 2:31 am
by graphicsMan
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.

Re: Importance sampling, color scaling

Posted: Sun Nov 04, 2012 10:53 am
by tuomlarsen
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?