Code cleanup: abstract shadow catcher logic more into accumulation code.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Mon, 28 Aug 2017 11:33:37 +0000 (13:33 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Wed, 13 Sep 2017 13:24:14 +0000 (15:24 +0200)
intern/cycles/kernel/kernel_accumulate.h
intern/cycles/kernel/kernel_bake.h
intern/cycles/kernel/kernel_passes.h
intern/cycles/kernel/kernel_path.h
intern/cycles/kernel/kernel_path_branched.h
intern/cycles/kernel/kernel_path_subsurface.h
intern/cycles/kernel/kernel_types.h
intern/cycles/kernel/kernel_volume.h
intern/cycles/kernel/split/kernel_buffer_update.h
intern/cycles/kernel/split/kernel_split_common.h

index 82d3c15..5e60458 100644 (file)
@@ -226,9 +226,9 @@ ccl_device_inline void path_radiance_init(PathRadiance *L, int use_light_pass)
        L->path_total = make_float3(0.0f, 0.0f, 0.0f);
        L->path_total_shaded = make_float3(0.0f, 0.0f, 0.0f);
        L->shadow_background_color = make_float3(0.0f, 0.0f, 0.0f);
-       L->shadow_radiance_sum = make_float3(0.0f, 0.0f, 0.0f);
        L->shadow_throughput = 0.0f;
        L->shadow_transparency = 1.0f;
+       L->has_shadow_catcher = 0;
 #endif
 
 #ifdef __DENOISING_FEATURES__
@@ -279,13 +279,22 @@ ccl_device_inline void path_radiance_bsdf_bounce(PathRadiance *L, ccl_addr_space
        }
 }
 
-ccl_device_inline void path_radiance_accum_emission(PathRadiance *L, float3 throughput, float3 value, int bounce)
+ccl_device_inline void path_radiance_accum_emission(PathRadiance *L,
+                                                    ccl_addr_space PathState *state,
+                                                    float3 throughput,
+                                                    float3 value)
 {
+#ifdef __SHADOW_TRICKS__
+       if(state->flag & PATH_RAY_SHADOW_CATCHER) {
+               return;
+       }
+#endif
+
 #ifdef __PASSES__
        if(L->use_light_pass) {
-               if(bounce == 0)
+               if(state->bounce == 0)
                        L->emission += throughput*value;
-               else if(bounce == 1)
+               else if(state->bounce == 1)
                        L->direct_emission += throughput*value;
                else
                        L->indirect += throughput*value;
@@ -304,6 +313,18 @@ ccl_device_inline void path_radiance_accum_ao(PathRadiance *L,
                                               float3 bsdf,
                                               float3 ao)
 {
+#ifdef __SHADOW_TRICKS__
+       if(state->flag & PATH_RAY_STORE_SHADOW_INFO) {
+               float3 light = throughput * bsdf;
+               L->path_total += light;
+               L->path_total_shaded += ao * light;
+
+               if(state->flag & PATH_RAY_SHADOW_CATCHER) {
+                       return;
+               }
+       }
+#endif
+
 #ifdef __PASSES__
        if(L->use_light_pass) {
                if(state->bounce == 0) {
@@ -321,14 +342,6 @@ ccl_device_inline void path_radiance_accum_ao(PathRadiance *L,
        {
                L->emission += throughput*bsdf*ao;
        }
-
-#ifdef __SHADOW_TRICKS__
-       if(state->flag & PATH_RAY_STORE_SHADOW_INFO) {
-               float3 light = throughput * bsdf;
-               L->path_total += light;
-               L->path_total_shaded += ao * light;
-       }
-#endif
 }
 
 ccl_device_inline void path_radiance_accum_total_ao(
@@ -357,6 +370,18 @@ ccl_device_inline void path_radiance_accum_light(PathRadiance *L,
                                                  float shadow_fac,
                                                  bool is_lamp)
 {
+#ifdef __SHADOW_TRICKS__
+       if(state->flag & PATH_RAY_STORE_SHADOW_INFO) {
+               float3 light = throughput * bsdf_eval->sum_no_mis;
+               L->path_total += light;
+               L->path_total_shaded += shadow * light;
+
+               if(state->flag & PATH_RAY_SHADOW_CATCHER) {
+                       return;
+               }
+       }
+#endif
+
 #ifdef __PASSES__
        if(L->use_light_pass) {
                if(state->bounce == 0) {
@@ -383,14 +408,6 @@ ccl_device_inline void path_radiance_accum_light(PathRadiance *L,
        {
                L->emission += throughput*bsdf_eval->diffuse*shadow;
        }
-
-#ifdef __SHADOW_TRICKS__
-       if(state->flag & PATH_RAY_STORE_SHADOW_INFO) {
-               float3 light = throughput * bsdf_eval->sum_no_mis;
-               L->path_total += light;
-               L->path_total_shaded += shadow * light;
-       }
-#endif
 }
 
 ccl_device_inline void path_radiance_accum_total_light(
@@ -417,6 +434,18 @@ ccl_device_inline void path_radiance_accum_background(
         float3 throughput,
         float3 value)
 {
+
+#ifdef __SHADOW_TRICKS__
+       if(state->flag & PATH_RAY_STORE_SHADOW_INFO) {
+               L->path_total += throughput * value;
+               L->path_total_shaded += throughput * value * L->shadow_transparency;
+
+               if(state->flag & PATH_RAY_SHADOW_CATCHER) {
+                       return;
+               }
+       }
+#endif
+
 #ifdef __PASSES__
        if(L->use_light_pass) {
                if(state->bounce == 0)
@@ -432,18 +461,31 @@ ccl_device_inline void path_radiance_accum_background(
                L->emission += throughput*value;
        }
 
-#ifdef __SHADOW_TRICKS__
-       if(state->flag & PATH_RAY_STORE_SHADOW_INFO) {
-               L->path_total += throughput * value;
-               L->path_total_shaded += throughput * value * L->shadow_transparency;
-       }
-#endif
-
 #ifdef __DENOISING_FEATURES__
        L->denoising_albedo += state->denoising_feature_weight * value;
 #endif  /* __DENOISING_FEATURES__ */
 }
 
+ccl_device_inline void path_radiance_accum_transparent(
+        PathRadiance *L,
+        ccl_addr_space PathState *state,
+        float3 throughput)
+{
+       L->transparent += average(throughput);
+}
+
+#ifdef __SHADOW_TRICKS__
+ccl_device_inline void path_radiance_accum_shadowcatcher(
+        PathRadiance *L,
+        float3 throughput,
+        float3 background)
+{
+       L->shadow_throughput += average(throughput);
+       L->shadow_background_color += throughput * background;
+       L->has_shadow_catcher = 1;
+}
+#endif
+
 ccl_device_inline void path_radiance_sum_indirect(PathRadiance *L)
 {
 #ifdef __PASSES__
@@ -501,7 +543,36 @@ ccl_device_inline void path_radiance_copy_indirect(PathRadiance *L,
 #endif
 }
 
-ccl_device_inline float3 path_radiance_clamp_and_sum(KernelGlobals *kg, PathRadiance *L)
+#ifdef __SHADOW_TRICKS__
+ccl_device_inline void path_radiance_sum_shadowcatcher(KernelGlobals *kg,
+                                                       PathRadiance *L,
+                                                       float3 *L_sum,
+                                                       float *alpha)
+{
+       /* Calculate current shadow of the path. */
+       float path_total = average(L->path_total);
+       float shadow;
+
+       if(path_total == 0.0f) {
+               shadow = L->shadow_transparency;
+       }
+       else {
+               float path_total_shaded = average(L->path_total_shaded);
+               shadow = path_total_shaded / path_total;
+       }
+
+       /* Calculate final light sum and transparency for shadow catcher object. */
+       if(kernel_data.background.transparent) {
+               *alpha -= L->shadow_throughput * shadow;
+       }
+       else {
+               L->shadow_background_color *= shadow;
+               *L_sum += L->shadow_background_color;
+       }
+}
+#endif
+
+ccl_device_inline float3 path_radiance_clamp_and_sum(KernelGlobals *kg, PathRadiance *L, float *alpha)
 {
        float3 L_sum;
        /* Light Passes are used */
@@ -578,8 +649,6 @@ ccl_device_inline float3 path_radiance_clamp_and_sum(KernelGlobals *kg, PathRadi
                        L_sum = L_direct + L_indirect;
                }
 #endif
-
-               return L_sum;
        }
 
        /* No Light Passes */
@@ -587,14 +656,24 @@ ccl_device_inline float3 path_radiance_clamp_and_sum(KernelGlobals *kg, PathRadi
 #endif
        {
                L_sum = L->emission;
+
+               /* Reject invalid value */
+               float sum = fabsf((L_sum).x) + fabsf((L_sum).y) + fabsf((L_sum).z);
+               if(!isfinite_safe(sum)) {
+                       kernel_assert(!"Non-finite final sum in path_radiance_clamp_and_sum!");
+                       L_sum = make_float3(0.0f, 0.0f, 0.0f);
+               }
        }
 
-       /* Reject invalid value */
-       float sum = fabsf((L_sum).x) + fabsf((L_sum).y) + fabsf((L_sum).z);
-       if(!isfinite_safe(sum)) {
-               kernel_assert(!"Non-finite final sum in path_radiance_clamp_and_sum!");
-               L_sum = make_float3(0.0f, 0.0f, 0.0f);
+       /* Compute alpha. */
+       *alpha = 1.0f - L->transparent;
+
+       /* Add shadow catcher contributions. */
+#ifdef __SHADOW_TRICKS__
+       if(L->has_shadow_catcher) {
+               path_radiance_sum_shadowcatcher(kg, L, &L_sum, alpha);
        }
+#endif  /* __SHADOW_TRICKS__ */
 
        return L_sum;
 }
@@ -627,14 +706,18 @@ ccl_device_inline void path_radiance_split_denoising(KernelGlobals *kg, PathRadi
        *clean = make_float3(0.0f, 0.0f, 0.0f);
 #endif
 
+#ifdef __SHADOW_TRICKS__
+       if(L->has_shadow_catcher) {
+               *noisy += L->shadow_background_color;
+       }
+#endif
+
        *noisy = ensure_finite3(*noisy);
        *clean = ensure_finite3(*clean);
 }
 
-ccl_device_inline void path_radiance_accum_sample(PathRadiance *L, PathRadiance *L_sample, int num_samples)
+ccl_device_inline void path_radiance_accum_sample(PathRadiance *L, PathRadiance *L_sample)
 {
-       float fac = 1.0f/num_samples;
-
 #ifdef __SPLIT_KERNEL__
 #  define safe_float3_add(f, v) \
        do { \
@@ -643,66 +726,35 @@ ccl_device_inline void path_radiance_accum_sample(PathRadiance *L, PathRadiance
                atomic_add_and_fetch_float(p+1, (v).y); \
                atomic_add_and_fetch_float(p+2, (v).z); \
        } while(0)
+#  define safe_float_add(f, v) \
+               atomic_add_and_fetch_float(&(f), (v))
 #else
 #  define safe_float3_add(f, v) (f) += (v)
+#  define safe_float_add(f, v) (f) += (v)
 #endif  /* __SPLIT_KERNEL__ */
 
 #ifdef __PASSES__
-       safe_float3_add(L->direct_diffuse, L_sample->direct_diffuse*fac);
-       safe_float3_add(L->direct_glossy, L_sample->direct_glossy*fac);
-       safe_float3_add(L->direct_transmission, L_sample->direct_transmission*fac);
-       safe_float3_add(L->direct_subsurface, L_sample->direct_subsurface*fac);
-       safe_float3_add(L->direct_scatter, L_sample->direct_scatter*fac);
-
-       safe_float3_add(L->indirect_diffuse, L_sample->indirect_diffuse*fac);
-       safe_float3_add(L->indirect_glossy, L_sample->indirect_glossy*fac);
-       safe_float3_add(L->indirect_transmission, L_sample->indirect_transmission*fac);
-       safe_float3_add(L->indirect_subsurface, L_sample->indirect_subsurface*fac);
-       safe_float3_add(L->indirect_scatter, L_sample->indirect_scatter*fac);
-
-       safe_float3_add(L->background, L_sample->background*fac);
-       safe_float3_add(L->ao, L_sample->ao*fac);
-       safe_float3_add(L->shadow, L_sample->shadow*fac);
-#  ifdef __SPLIT_KERNEL__
-       atomic_add_and_fetch_float(&L->mist, L_sample->mist*fac);
-#  else
-       L->mist += L_sample->mist*fac;
-#  endif  /* __SPLIT_KERNEL__ */
+       safe_float3_add(L->direct_diffuse, L_sample->direct_diffuse);
+       safe_float3_add(L->direct_glossy, L_sample->direct_glossy);
+       safe_float3_add(L->direct_transmission, L_sample->direct_transmission);
+       safe_float3_add(L->direct_subsurface, L_sample->direct_subsurface);
+       safe_float3_add(L->direct_scatter, L_sample->direct_scatter);
+
+       safe_float3_add(L->indirect_diffuse, L_sample->indirect_diffuse);
+       safe_float3_add(L->indirect_glossy, L_sample->indirect_glossy);
+       safe_float3_add(L->indirect_transmission, L_sample->indirect_transmission);
+       safe_float3_add(L->indirect_subsurface, L_sample->indirect_subsurface);
+       safe_float3_add(L->indirect_scatter, L_sample->indirect_scatter);
+
+       safe_float3_add(L->background, L_sample->background);
+       safe_float3_add(L->ao, L_sample->ao);
+       safe_float3_add(L->shadow, L_sample->shadow);
+       safe_float_add(L->mist, L_sample->mist);
 #endif  /* __PASSES__ */
-       safe_float3_add(L->emission, L_sample->emission*fac);
+       safe_float3_add(L->emission, L_sample->emission);
 
+#undef safe_float_add
 #undef safe_float3_add
 }
 
-#ifdef __SHADOW_TRICKS__
-/* Calculate current shadow of the path. */
-ccl_device_inline float path_radiance_sum_shadow(const PathRadiance *L)
-{
-       float path_total = average(L->path_total);
-       float path_total_shaded = average(L->path_total_shaded);
-       if(path_total != 0.0f) {
-               return path_total_shaded / path_total;
-       }
-       return L->shadow_transparency;
-}
-
-/* Calculate final light sum and transparency for shadow catcher object. */
-ccl_device_inline float3 path_radiance_sum_shadowcatcher(KernelGlobals *kg,
-                                                         const PathRadiance *L,
-                                                         float* alpha)
-{
-       const float shadow = path_radiance_sum_shadow(L);
-       float3 L_sum;
-       if(kernel_data.background.transparent) {
-               *alpha = 1.0f - L->shadow_throughput * shadow;
-               L_sum = L->shadow_radiance_sum;
-       }
-       else {
-               L_sum = L->shadow_background_color * L->shadow_throughput * shadow +
-                       L->shadow_radiance_sum;
-       }
-       return L_sum;
-}
-#endif
-
 CCL_NAMESPACE_END
index 8af1187..ef6f196 100644 (file)
@@ -70,7 +70,7 @@ ccl_device_inline void compute_light_pass(KernelGlobals *kg,
                /* sample emission */
                if((pass_filter & BAKE_FILTER_EMISSION) && (sd->flag & SD_EMISSION)) {
                        float3 emission = indirect_primitive_emission(kg, sd, 0.0f, state.flag, state.ray_pdf);
-                       path_radiance_accum_emission(&L_sample, throughput, emission, state.bounce);
+                       path_radiance_accum_emission(&L_sample, &state, throughput, emission);
                }
 
                bool is_sss_sample = false;
@@ -141,7 +141,7 @@ ccl_device_inline void compute_light_pass(KernelGlobals *kg,
                /* sample emission */
                if((pass_filter & BAKE_FILTER_EMISSION) && (sd->flag & SD_EMISSION)) {
                        float3 emission = indirect_primitive_emission(kg, sd, 0.0f, state.flag, state.ray_pdf);
-                       path_radiance_accum_emission(&L_sample, throughput, emission, state.bounce);
+                       path_radiance_accum_emission(&L_sample, &state, throughput, emission);
                }
 
 #ifdef __SUBSURFACE__
@@ -172,7 +172,7 @@ ccl_device_inline void compute_light_pass(KernelGlobals *kg,
 #endif
 
        /* accumulate into master L */
-       path_radiance_accum_sample(L, &L_sample, 1);
+       path_radiance_accum_sample(L, &L_sample);
 }
 
 ccl_device bool is_aa_pass(ShaderEvalType type)
@@ -368,7 +368,8 @@ ccl_device void kernel_bake_evaluate(KernelGlobals *kg, ccl_global uint4 *input,
                case SHADER_EVAL_COMBINED:
                {
                        if((pass_filter & BAKE_FILTER_COMBINED) == BAKE_FILTER_COMBINED) {
-                               out = path_radiance_clamp_and_sum(kg, &L);
+                               float alpha;
+                               out = path_radiance_clamp_and_sum(kg, &L, &alpha);
                                break;
                        }
 
index 0651044..fff7f4c 100644 (file)
@@ -365,21 +365,11 @@ ccl_device_inline void kernel_write_light_passes(KernelGlobals *kg, ccl_global f
 }
 
 ccl_device_inline void kernel_write_result(KernelGlobals *kg, ccl_global float *buffer,
-       int sample, PathRadiance *L, bool is_shadow_catcher)
+       int sample, PathRadiance *L)
 {
        if(L) {
-               float3 L_sum;
-               float alpha = 1.0f - L->transparent;
-
-#ifdef __SHADOW_TRICKS__
-               if(is_shadow_catcher) {
-                       L_sum = path_radiance_sum_shadowcatcher(kg, L, &alpha);
-               }
-               else
-#endif  /* __SHADOW_TRICKS__ */
-               {
-                       L_sum = path_radiance_clamp_and_sum(kg, L);
-               }
+               float alpha;
+               float3 L_sum = path_radiance_clamp_and_sum(kg, L, &alpha);
 
                kernel_write_pass_float4(buffer, sample, make_float4(L_sum.x, L_sum.y, L_sum.z, alpha));
 
@@ -394,16 +384,7 @@ ccl_device_inline void kernel_write_result(KernelGlobals *kg, ccl_global float *
 #  endif
                        if(kernel_data.film.pass_denoising_clean) {
                                float3 noisy, clean;
-#ifdef __SHADOW_TRICKS__
-                               if(is_shadow_catcher) {
-                                       noisy = L_sum;
-                                       clean = make_float3(0.0f, 0.0f, 0.0f);
-                               }
-                               else
-#endif  /* __SHADOW_TRICKS__ */
-                               {
-                                       path_radiance_split_denoising(kg, L, &noisy, &clean);
-                               }
+                               path_radiance_split_denoising(kg, L, &noisy, &clean);
                                kernel_write_pass_float3_variance(buffer + kernel_data.film.pass_denoising_data + DENOISING_PASS_COLOR,
                                                                  sample, noisy);
                                kernel_write_pass_float3_unaligned(buffer + kernel_data.film.pass_denoising_clean,
index afaa47c..6ad2a00 100644 (file)
@@ -122,7 +122,7 @@ ccl_device_forceinline void kernel_path_lamp_emission(
                float3 emission;
 
                if(indirect_lamp_emission(kg, emission_sd, state, &light_ray, &emission))
-                       path_radiance_accum_emission(L, throughput, emission, state->bounce);
+                       path_radiance_accum_emission(L, state, throughput, emission);
        }
 #endif  /* __LAMP_MIS__ */
 }
@@ -194,7 +194,7 @@ ccl_device_forceinline VolumeIntegrateResult kernel_path_volume(
 
                        /* emission */
                        if(volume_segment.closure_flag & SD_EMISSION)
-                               path_radiance_accum_emission(L, *throughput, volume_segment.accum_emission, state->bounce);
+                               path_radiance_accum_emission(L, state, *throughput, volume_segment.accum_emission);
 
                        /* scattering */
                        VolumeIntegrateResult result = VOLUME_PATH_ATTENUATED;
@@ -274,12 +274,12 @@ ccl_device_forceinline bool kernel_path_shader_apply(
                if(state->flag & PATH_RAY_CAMERA) {
                        state->flag |= (PATH_RAY_SHADOW_CATCHER |
                                                   PATH_RAY_STORE_SHADOW_INFO);
+
+                       float3 bg = make_float3(0.0f, 0.0f, 0.0f);
                        if(!kernel_data.background.transparent) {
-                               L->shadow_background_color =
-                                               indirect_background(kg, emission_sd, state, ray);
+                               bg = indirect_background(kg, emission_sd, state, ray);
                        }
-                       L->shadow_radiance_sum = path_radiance_clamp_and_sum(kg, L);
-                       L->shadow_throughput = average(throughput);
+                       path_radiance_accum_shadowcatcher(L, throughput, bg);
                }
        }
        else if(state->flag & PATH_RAY_SHADOW_CATCHER) {
@@ -331,7 +331,7 @@ ccl_device_forceinline bool kernel_path_shader_apply(
        /* emission */
        if(sd->flag & SD_EMISSION) {
                float3 emission = indirect_primitive_emission(kg, sd, sd->ray_length, state->flag, state->ray_pdf);
-               path_radiance_accum_emission(L, throughput, emission, state->bounce);
+               path_radiance_accum_emission(L, state, throughput, emission);
        }
 #endif  /* __EMISSION__ */
 
@@ -541,8 +541,7 @@ ccl_device_forceinline void kernel_path_integrate(
        Ray *ray,
        PathRadiance *L,
        ccl_global float *buffer,
-       ShaderData *emission_sd,
-       bool *is_shadow_catcher)
+       ShaderData *emission_sd)
 {
        /* Shader data memory used for both volumes and surfaces, saves stack space. */
        ShaderData sd;
@@ -678,10 +677,6 @@ ccl_device_forceinline void kernel_path_integrate(
                }
        }
 #endif  /* __SUBSURFACE__ */
-
-#ifdef __SHADOW_TRICKS__
-       *is_shadow_catcher = (state->flag & PATH_RAY_SHADOW_CATCHER) != 0;
-#endif  /* __SHADOW_TRICKS__ */
 }
 
 ccl_device void kernel_path_trace(KernelGlobals *kg,
@@ -702,7 +697,7 @@ ccl_device void kernel_path_trace(KernelGlobals *kg,
        kernel_path_trace_setup(kg, rng_state, sample, x, y, &rng_hash, &ray);
 
        if(ray.t == 0.0f) {
-               kernel_write_result(kg, buffer, sample, NULL, false);
+               kernel_write_result(kg, buffer, sample, NULL);
                return;
        }
 
@@ -717,17 +712,15 @@ ccl_device void kernel_path_trace(KernelGlobals *kg,
        path_state_init(kg, &emission_sd, &state, rng_hash, sample, &ray);
 
        /* Integrate. */
-       bool is_shadow_catcher;
        kernel_path_integrate(kg,
                              &state,
                              throughput,
                              &ray,
                              &L,
                              buffer,
-                             &emission_sd,
-                             &is_shadow_catcher);
+                             &emission_sd);
 
-       kernel_write_result(kg, buffer, sample, &L, is_shadow_catcher);
+       kernel_write_result(kg, buffer, sample, &L);
 }
 
 #endif  /* __SPLIT_KERNEL__ */
index daab7c8..b908cbb 100644 (file)
@@ -269,8 +269,7 @@ ccl_device void kernel_branched_path_integrate(KernelGlobals *kg,
                                                int sample,
                                                Ray ray,
                                                ccl_global float *buffer,
-                                               PathRadiance *L,
-                                               bool *is_shadow_catcher)
+                                               PathRadiance *L)
 {
        /* initialize */
        float3 throughput = make_float3(1.0f, 1.0f, 1.0f);
@@ -374,7 +373,7 @@ ccl_device void kernel_branched_path_integrate(KernelGlobals *kg,
 
                        /* emission and transmittance */
                        if(volume_segment.closure_flag & SD_EMISSION)
-                               path_radiance_accum_emission(L, throughput, volume_segment.accum_emission, state.bounce);
+                               path_radiance_accum_emission(L, &state, throughput, volume_segment.accum_emission);
                        throughput *= volume_segment.accum_transmittance;
 
                        /* free cached steps */
@@ -539,10 +538,6 @@ ccl_device void kernel_branched_path_integrate(KernelGlobals *kg,
                kernel_volume_stack_enter_exit(kg, &sd, state.volume_stack);
 #endif  /* __VOLUME__ */
        }
-
-#ifdef __SHADOW_TRICKS__
-       *is_shadow_catcher = (state.flag & PATH_RAY_SHADOW_CATCHER) != 0;
-#endif  /* __SHADOW_TRICKS__ */
 }
 
 ccl_device void kernel_branched_path_trace(KernelGlobals *kg,
@@ -564,14 +559,13 @@ ccl_device void kernel_branched_path_trace(KernelGlobals *kg,
 
        /* integrate */
        PathRadiance L;
-       bool is_shadow_catcher;
 
        if(ray.t != 0.0f) {
-               kernel_branched_path_integrate(kg, rng_hash, sample, ray, buffer, &L, &is_shadow_catcher);
-               kernel_write_result(kg, buffer, sample, &L, is_shadow_catcher);
+               kernel_branched_path_integrate(kg, rng_hash, sample, ray, buffer, &L);
+               kernel_write_result(kg, buffer, sample, &L);
        }
        else {
-               kernel_write_result(kg, buffer, sample, NULL, false);
+               kernel_write_result(kg, buffer, sample, NULL);
        }
 }
 
index 9bccc92..619d57e 100644 (file)
@@ -124,7 +124,7 @@ bool kernel_path_subsurface_scatter(
                                ss_indirect->num_rays++;
                        }
                        else {
-                               path_radiance_accum_sample(L, hit_L, 1);
+                               path_radiance_accum_sample(L, hit_L);
                        }
                }
                return true;
@@ -145,7 +145,7 @@ ccl_device void kernel_path_subsurface_accum_indirect(
 {
        if(ss_indirect->tracing) {
                path_radiance_sum_indirect(L);
-               path_radiance_accum_sample(&ss_indirect->direct_L, L, 1);
+               path_radiance_accum_sample(&ss_indirect->direct_L, L);
                if(ss_indirect->num_rays == 0) {
                        *L = ss_indirect->direct_L;
                }
index 2c7e9b8..e3d2ae1 100644 (file)
@@ -535,11 +535,13 @@ typedef ccl_addr_space struct PathRadiance {
        /* Path radiance sum and throughput at the moment when ray hits shadow
         * catcher object.
         */
-       float3 shadow_radiance_sum;
        float shadow_throughput;
 
        /* Accumulated transparency along the path after shadow catcher bounce. */
        float shadow_transparency;
+
+       /* Indicate if any shadow catcher data is set. */
+       int has_shadow_catcher;
 #endif
 
 #ifdef __DENOISING_FEATURES__
index d00714e..d8e8e19 100644 (file)
@@ -438,7 +438,7 @@ ccl_device VolumeIntegrateResult kernel_volume_integrate_homogeneous(
                float3 sigma_t = coeff.sigma_a + coeff.sigma_s;
                float3 transmittance = volume_color_transmittance(sigma_t, ray->t);
                float3 emission = kernel_volume_emission_integrate(&coeff, closure_flag, transmittance, ray->t);
-               path_radiance_accum_emission(L, *throughput, emission, state->bounce);
+               path_radiance_accum_emission(L, state, *throughput, emission);
        }
 
        /* modify throughput */
@@ -558,7 +558,7 @@ ccl_device VolumeIntegrateResult kernel_volume_integrate_heterogeneous_distance(
                        /* integrate emission attenuated by absorption */
                        if(L && (closure_flag & SD_EMISSION)) {
                                float3 emission = kernel_volume_emission_integrate(&coeff, closure_flag, transmittance, dt);
-                               path_radiance_accum_emission(L, tp, emission, state->bounce);
+                               path_radiance_accum_emission(L, state, tp, emission);
                        }
 
                        /* modify throughput */
index 3b61319..7b4d129 100644 (file)
@@ -94,8 +94,7 @@ ccl_device void kernel_buffer_update(KernelGlobals *kg,
                buffer += (kernel_split_params.offset + pixel_x + pixel_y*stride) * kernel_data.film.pass_stride;
 
                /* accumulate result in output buffer */
-               bool is_shadow_catcher = (state->flag & PATH_RAY_SHADOW_CATCHER);
-               kernel_write_result(kg, buffer, sample, L, is_shadow_catcher);
+               kernel_write_result(kg, buffer, sample, L);
 
                ASSIGN_RAY_STATE(ray_state, ray_index, RAY_TO_REGENERATE);
        }
index 08f0124..558d327 100644 (file)
@@ -63,7 +63,7 @@ ccl_device_inline void kernel_split_path_end(KernelGlobals *kg, int ray_index)
                PathRadiance *orig_ray_L = &kernel_split_state.path_radiance[orig_ray];
 
                path_radiance_sum_indirect(L);
-               path_radiance_accum_sample(orig_ray_L, L, 1);
+               path_radiance_accum_sample(orig_ray_L, L);
 
                atomic_fetch_and_dec_uint32((ccl_global uint*)&kernel_split_state.branched_state[orig_ray].shared_sample_count);