Cycles: add Russian roulette termination for volume multiple scattering.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Tue, 20 Feb 2018 14:36:07 +0000 (15:36 +0100)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Wed, 21 Feb 2018 23:55:32 +0000 (00:55 +0100)
This mainly helps with dense volumes, rendering can be 30% faster with
little noise increase in such scenes.

intern/cycles/kernel/kernel_path_volume.h

index b6a856baf2416bd64aae2ecc20ffd8359a5ae92d..6275d0d65621f721f6624d7a5ebe82ec8e29351f 100644 (file)
@@ -99,6 +99,23 @@ bool kernel_path_volume_bounce(
        /* update path state */
        path_state_next(kg, state, label);
 
+       /* Russian roulette termination of volume ray scattering. */
+       float probability = path_state_continuation_probability(kg, state, *throughput);
+
+       if(probability == 0.0f) {
+               return false;
+       }
+       else if(probability != 1.0f) {
+               /* Use dimension from the previous bounce, has not been used yet. */
+               float terminate = path_state_rng_1D(kg, state, PRNG_TERMINATE - PRNG_BOUNCE_NUM);
+
+               if(terminate >= probability) {
+                       return false;
+               }
+
+               *throughput /= probability;
+       }
+
        /* setup ray */
        ray->P = sd->P;
        ray->D = phase_omega_in;