(L) [2015/02/13] [tby mgamito] [Russian Roulette for terminating volumetric ray marching?] Wayback!Hello,
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: [LINK # 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: [LINK # 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: [LINK # Select all] if (Tr.y() < 1e-3) {
const float continueProb = .5f;
if (rng.RandomFloat() > continueProb)
{
Tr = 0;
break;
}
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.
Thanks,
manuel
(L) [2015/02/14] [tby MohamedSakr] [Russian Roulette for terminating volumetric ray marching?] Wayback!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"
(L) [2015/02/22] [tby citadel] [Russian Roulette for terminating volumetric ray marching?] Wayback!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.