Fix T52021: Shadow catcher renders wrong when catcher object is behind transparent...
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 18 Jul 2017 07:25:58 +0000 (09:25 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 18 Jul 2017 07:46:21 +0000 (09:46 +0200)
Tweaked the path radiance summing and alpha to accommodate for possible contribution of
light by transparent surface bounces happening prior to shadow catcher intersection.

This commit will change the way how shadow catcher results looks when was behind semi
transparent object, but the old result seemed to be fully wrong: there were big artifacts
when alpha-overing the result on some actual footage.

intern/cycles/kernel/kernel_accumulate.h
intern/cycles/kernel/kernel_path.h
intern/cycles/kernel/kernel_path_branched.h
intern/cycles/kernel/kernel_types.h
intern/cycles/kernel/split/kernel_holdout_emission_blurring_pathtermination_ao.h

index 175bd6b..9ed16ac 100644 (file)
@@ -220,7 +220,9 @@ ccl_device_inline void path_radiance_init(PathRadiance *L, int use_light_pass)
 #ifdef __SHADOW_TRICKS__
        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_color = 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;
 #endif
 
 #ifdef __DENOISING_FEATURES__
@@ -680,11 +682,12 @@ ccl_device_inline float3 path_radiance_sum_shadowcatcher(KernelGlobals *kg,
        const float shadow = path_radiance_sum_shadow(L);
        float3 L_sum;
        if(kernel_data.background.transparent) {
-               *alpha = 1.0f-shadow;
-               L_sum = make_float3(0.0f, 0.0f, 0.0f);
+               *alpha = 1.0f - L->shadow_throughput * shadow;
+               L_sum = L->shadow_radiance_sum;
        }
        else {
-               L_sum = L->shadow_color * shadow;
+               L_sum = L->shadow_background_color * L->shadow_throughput * shadow +
+                       L->shadow_radiance_sum;
        }
        return L_sum;
 }
index fc093ad..c340b3b 100644 (file)
@@ -643,11 +643,16 @@ ccl_device_inline float kernel_path_integrate(KernelGlobals *kg,
 #ifdef __SHADOW_TRICKS__
                if((sd.object_flag & SD_OBJECT_SHADOW_CATCHER)) {
                        if(state.flag & PATH_RAY_CAMERA) {
-                               state.flag |= (PATH_RAY_SHADOW_CATCHER | PATH_RAY_SHADOW_CATCHER_ONLY | PATH_RAY_STORE_SHADOW_INFO);
+                               state.flag |= (PATH_RAY_SHADOW_CATCHER |
+                                              PATH_RAY_SHADOW_CATCHER_ONLY |
+                                              PATH_RAY_STORE_SHADOW_INFO);
                                state.catcher_object = sd.object;
                                if(!kernel_data.background.transparent) {
-                                       L->shadow_color = indirect_background(kg, &emission_sd, &state, &ray);
+                                       L->shadow_background_color =
+                                               indirect_background(kg, &emission_sd, &state, &ray);
                                }
+                               L->shadow_radiance_sum = path_radiance_clamp_and_sum(kg, L);
+                               L->shadow_throughput = average(throughput);
                        }
                }
                else {
index 5f7f1a2..77d4f1d 100644 (file)
@@ -499,11 +499,16 @@ ccl_device float kernel_branched_path_integrate(KernelGlobals *kg,
 
 #ifdef __SHADOW_TRICKS__
                if((sd.object_flag & SD_OBJECT_SHADOW_CATCHER)) {
-                       state.flag |= (PATH_RAY_SHADOW_CATCHER | PATH_RAY_SHADOW_CATCHER_ONLY | PATH_RAY_STORE_SHADOW_INFO);
+                       state.flag |= (PATH_RAY_SHADOW_CATCHER |
+                                      PATH_RAY_SHADOW_CATCHER_ONLY |
+                                      PATH_RAY_STORE_SHADOW_INFO);
                        state.catcher_object = sd.object;
                        if(!kernel_data.background.transparent) {
-                               L->shadow_color = indirect_background(kg, &emission_sd, &state, &ray);
+                               L->shadow_background_color =
+                                       indirect_background(kg, &emission_sd, &state, &ray);
                        }
+                       L->shadow_radiance_sum = path_radiance_clamp_and_sum(kg, L);
+                       L->shadow_throughput = average(throughput);
                }
                else {
                        state.flag &= ~PATH_RAY_SHADOW_CATCHER_ONLY;
index 34affab..37af98b 100644 (file)
@@ -515,7 +515,13 @@ typedef ccl_addr_space struct PathRadiance {
        float3 path_total_shaded;
 
        /* Color of the background on which shadow is alpha-overed. */
-       float3 shadow_color;
+       float3 shadow_background_color;
+
+       /* Path radiance sum and throughput at the moment when ray hits shadow
+        * catcher object.
+        */
+       float3 shadow_radiance_sum;
+       float shadow_throughput;
 #endif
 
 #ifdef __DENOISING_FEATURES__
index 670a557..fec671b 100644 (file)
@@ -125,13 +125,21 @@ ccl_device void kernel_holdout_emission_blurring_pathtermination_ao(
 #ifdef __SHADOW_TRICKS__
                if((sd->object_flag & SD_OBJECT_SHADOW_CATCHER)) {
                        if(state->flag & PATH_RAY_CAMERA) {
-                               state->flag |= (PATH_RAY_SHADOW_CATCHER | PATH_RAY_SHADOW_CATCHER_ONLY | PATH_RAY_STORE_SHADOW_INFO);
+                               PathRadiance *L = &kernel_split_state.path_radiance[ray_index];
+                               state->flag |= (PATH_RAY_SHADOW_CATCHER |
+                                               PATH_RAY_SHADOW_CATCHER_ONLY |
+                                               PATH_RAY_STORE_SHADOW_INFO);
                                state->catcher_object = sd->object;
                                if(!kernel_data.background.transparent) {
-                                       PathRadiance *L = &kernel_split_state.path_radiance[ray_index];
                                        ccl_global Ray *ray = &kernel_split_state.ray[ray_index];
-                                       L->shadow_color = indirect_background(kg, &kernel_split_state.sd_DL_shadow[ray_index], state, ray);
+                                       L->shadow_background_color = indirect_background(
+                                               kg,
+                                               &kernel_split_state.sd_DL_shadow[ray_index],
+                                               state,
+                                               ray);
                                }
+                               L->shadow_radiance_sum = path_radiance_clamp_and_sum(kg, L);
+                               L->shadow_throughput = average(throughput);
                        }
                }
                else {