Page 1 of 1

Russian Roulette for terminating volumetric ray marching?

Posted: Fri Feb 13, 2015 3:30 pm
by mgamito

I have a question about how to implement Russian Roulette termination while marching a ray through a volume and accumulating transmittance.
The only example I've found on how to implement this is in the Physically Based Rendering book. In there, the following code snippet is included in the ray marching loop:

Code: Select all

        // Possibly terminate ray marching if transmittance is small
        if (Tr.y() < 1e-3) {
            const float continueProb = .5f;
            if (rng.RandomFloat() > continueProb) break;
            Tr /= continueProb;
The way I understand Russian Roulette, there is some expensive computation F that we wish to perform only with probability q, otherwise F is replaced by some value c (usually zero). For the
expected value to stay the same, however, in those cases where we choose to compute F, it needs to be transformed into F' = (F - qc)/(1-q).

In the code above, when we choose to terminate, we break out of the loop so the output transmittance is the transmittance Tr up to the termination point. In that case, c = Tr: the value we wish to use instead of F (the full ray marching solution with no early terminations) and the line

Code: Select all

            Tr /= continueProb
cannot be correct. For that update to be correct, it would have to be c = 0, in which case the code would be:

Code: Select all

        if (Tr.y() < 1e-3) {
            const float continueProb = .5f;
            if (rng.RandomFloat() > continueProb)
               Tr = 0;
            Tr /= continueProb;
This modified version does not seem very helpful because, as one keeps marching along the ray, so many 50/50 coin tosses are taken that inevitably the ray will be terminated and the transmittance will come out zero, except in a few very rare cases where all consecutive coin tosses come up the same way.

I would appreciate if anyone could elucidate me on this. I'm sure the Pharr & Humphreys implementation is correct, I'm just not being able to work out the maths in my head.


Re: Russian Roulette for terminating volumetric ray marching

Posted: Sat Feb 14, 2015 7:56 pm
by MohamedSakr
Tr = 0; is wrong for this reason:
you have a ray which is entering a volume sphere, you have "entering ray Lenter, exiting ray Lexit"
in this case Lexit is depending mainly on the absorption of the volume sphere, and in general if the volume is homogenous: Lexit = Lenter * someConstant;

here if you are animating the value of Lenter "a simple light intensity animation" , if the Lexit < 1e-3 it will mean Lexit = 0, you will find in the generated video values goes from 0 for some frames and SUDDENLY they jump to a seen color!! "you made the function non continuous"

Re: Russian Roulette for terminating volumetric ray marching

Posted: Sun Feb 22, 2015 5:32 pm
by citadel
Not sure if the PBRT implementation is using direct lighting.
If it's not the case, it makes no sense to set Tr to zero, which should be used for radiance composition when the ray exits volume.
And it is important to notice that Russian Roulette does not have memory effect for the random ray walking(memoryless Markov chain something),
so terminating the ray does not mean denying the previous integration of Tr, it only accounts for integrating the incident radiance
at the termination point using Russian Roulette.