Fix rare firefly in volume equiangular sampling when sampling short distance.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Fri, 8 Sep 2017 23:37:54 +0000 (01:37 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Tue, 12 Sep 2017 10:50:44 +0000 (12:50 +0200)
intern/cycles/kernel/kernel_path_branched.h
intern/cycles/kernel/kernel_path_volume.h
intern/cycles/kernel/kernel_volume.h

index dde40674ee615f3fae76f75dd57b8e7533b3cfea..d4cfe461ac442683fff9a074b34a6377e4543408 100644 (file)
@@ -376,10 +376,8 @@ ccl_device void kernel_branched_path_integrate(KernelGlobals *kg,
                                        VolumeIntegrateResult result = kernel_volume_decoupled_scatter(kg,
                                                &ps, &pray, &sd, &tp, rphase, rscatter, &volume_segment, NULL, false);
 
-                                       (void)result;
-                                       kernel_assert(result == VOLUME_PATH_SCATTERED);
-
-                                       if(kernel_path_volume_bounce(kg,
+                                       if(result == VOLUME_PATH_SCATTERED &&
+                                          kernel_path_volume_bounce(kg,
                                                                     &sd,
                                                                     &tp,
                                                                     &ps,
index fb6b8d56a38d76e1a1ee8506b674e3682a060974..3fd34ed10e27f35dec1c02dc888ac993d918e813 100644 (file)
@@ -165,11 +165,9 @@ ccl_device void kernel_branched_path_volume_connect_light(
                                VolumeIntegrateResult result = kernel_volume_decoupled_scatter(kg,
                                        state, ray, sd, &tp, rphase, rscatter, segment, (ls.t != FLT_MAX)? &ls.P: NULL, false);
 
-                               (void)result;
-                               kernel_assert(result == VOLUME_PATH_SCATTERED);
-
                                /* todo: split up light_sample so we don't have to call it again with new position */
-                               if(lamp_light_sample(kg, i, light_u, light_v, sd->P, &ls)) {
+                               if(result == VOLUME_PATH_SCATTERED &&
+                                  lamp_light_sample(kg, i, light_u, light_v, sd->P, &ls)) {
                                        if(kernel_data.integrator.pdf_triangles != 0.0f)
                                                ls.pdf *= 2.0f;
 
@@ -213,11 +211,9 @@ ccl_device void kernel_branched_path_volume_connect_light(
                                VolumeIntegrateResult result = kernel_volume_decoupled_scatter(kg,
                                        state, ray, sd, &tp, rphase, rscatter, segment, (ls.t != FLT_MAX)? &ls.P: NULL, false);
                                        
-                               (void)result;
-                               kernel_assert(result == VOLUME_PATH_SCATTERED);
-
                                /* todo: split up light_sample so we don't have to call it again with new position */
-                               if(light_sample(kg, light_u, light_v, sd->time, sd->P, state->bounce, &ls)) {
+                               if(result == VOLUME_PATH_SCATTERED &&
+                                  light_sample(kg, light_u, light_v, sd->time, sd->P, state->bounce, &ls)) {
                                        if(kernel_data.integrator.num_all_lights)
                                                ls.pdf *= 2.0f;
 
@@ -252,11 +248,9 @@ ccl_device void kernel_branched_path_volume_connect_light(
                VolumeIntegrateResult result = kernel_volume_decoupled_scatter(kg,
                        state, ray, sd, &tp, rphase, rscatter, segment, (ls.t != FLT_MAX)? &ls.P: NULL, false);
                        
-               (void)result;
-               kernel_assert(result == VOLUME_PATH_SCATTERED);
-
                /* todo: split up light_sample so we don't have to call it again with new position */
-               if(light_sample(kg, light_u, light_v, sd->time, sd->P, state->bounce, &ls)) {
+               if(result == VOLUME_PATH_SCATTERED &&
+                  light_sample(kg, light_u, light_v, sd->time, sd->P, state->bounce, &ls)) {
                        /* sample random light */
                        float terminate = path_state_rng_light_termination(kg, state);
                        if(direct_emission(kg, sd, emission_sd, &ls, state, &light_ray, &L_light, &is_lamp, terminate)) {
index 42094a9c3f80d077a55c222fc9c22f0e91599788..d00714e4ed71bdfb0c59a6dbf4eb5e294bb95bae 100644 (file)
@@ -997,8 +997,8 @@ ccl_device VolumeIntegrateResult kernel_volume_decoupled_scatter(
                        mis_weight = 2.0f*power_heuristic(pdf, distance_pdf);
                }
        }
-       if(sample_t < 1e-6f || pdf == 0.0f) {
-               return VOLUME_PATH_SCATTERED;
+       if(sample_t < 0.0f || pdf == 0.0f) {
+               return VOLUME_PATH_MISSED;
        }
 
        /* compute transmittance up to this step */