[Bf-blender-cvs] [88fd99e3647] cycles-x: Fix new shadow catcher not handling emissive meshes correctly

Brecht Van Lommel noreply at git.blender.org
Sat May 8 18:42:26 CEST 2021


Commit: 88fd99e3647e241d1e38b37412ffc068b7c73e63
Author: Brecht Van Lommel
Date:   Sat May 8 17:24:34 2021 +0200
Branches: cycles-x
https://developer.blender.org/rB88fd99e3647e241d1e38b37412ffc068b7c73e63

Fix new shadow catcher not handling emissive meshes correctly

These must also be excluded from direct light sampling for the shadow
catcher pass.

===================================================================

M	intern/cycles/kernel/integrator/integrator_shade_surface.h
M	intern/cycles/kernel/kernel_light.h

===================================================================

diff --git a/intern/cycles/kernel/integrator/integrator_shade_surface.h b/intern/cycles/kernel/integrator/integrator_shade_surface.h
index 8264b1476b9..4f69b031237 100644
--- a/intern/cycles/kernel/integrator/integrator_shade_surface.h
+++ b/intern/cycles/kernel/integrator/integrator_shade_surface.h
@@ -110,11 +110,12 @@ ccl_device_inline void integrate_surface_direct_light(INTEGRATOR_STATE_ARGS,
   /* Sample position on a light. */
   LightSample ls ccl_optional_struct_init;
   {
+    const int path_flag = INTEGRATOR_STATE(path, flag);
     const uint bounce = INTEGRATOR_STATE(path, bounce);
     float light_u, light_v;
     path_state_rng_2D(kg, rng_state, PRNG_LIGHT_U, &light_u, &light_v);
 
-    if (!light_sample(kg, -1, light_u, light_v, sd->time, sd->P, bounce, &ls)) {
+    if (!light_sample(kg, light_u, light_v, sd->time, sd->P, bounce, path_flag, &ls)) {
       return;
     }
   }
diff --git a/intern/cycles/kernel/kernel_light.h b/intern/cycles/kernel/kernel_light.h
index f71301271f3..9ce9fe51a8a 100644
--- a/intern/cycles/kernel/kernel_light.h
+++ b/intern/cycles/kernel/kernel_light.h
@@ -751,35 +751,38 @@ ccl_device_inline bool light_select_reached_max_bounces(const KernelGlobals *kg,
 }
 
 ccl_device_noinline bool light_sample(const KernelGlobals *kg,
-                                      int lamp,
                                       float randu,
-                                      float randv,
-                                      float time,
-                                      float3 P,
-                                      int bounce,
+                                      const float randv,
+                                      const float time,
+                                      const float3 P,
+                                      const int bounce,
+                                      const int path_flag,
                                       LightSample *ls)
 {
-  if (lamp < 0) {
-    /* sample index */
-    int index = light_distribution_sample(kg, &randu);
-
-    /* fetch light data */
-    const ccl_global KernelLightDistribution *kdistribution = &kernel_tex_fetch(
-        __light_distribution, index);
-    int prim = kdistribution->prim;
-
-    if (prim >= 0) {
-      int object = kdistribution->mesh_light.object_id;
-      int shader_flag = kdistribution->mesh_light.shader_flag;
-
-      triangle_light_sample(kg, prim, object, randu, randv, time, ls, P);
-      ls->shader |= shader_flag;
-      return (ls->pdf > 0.0f);
+  /* Sample light index from distribution. */
+  const int index = light_distribution_sample(kg, &randu);
+  const ccl_global KernelLightDistribution *kdistribution = &kernel_tex_fetch(__light_distribution,
+                                                                              index);
+  const int prim = kdistribution->prim;
+
+  if (prim >= 0) {
+    /* Mesh light. */
+    const int object = kdistribution->mesh_light.object_id;
+
+    /* Exclude synthetic meshes from shadow catcher pass. */
+    if ((path_flag & PATH_RAY_SHADOW_CATCHER_PASS) &&
+        !(kernel_tex_fetch(__object_flag, object) & SD_OBJECT_SHADOW_CATCHER)) {
+      return false;
     }
 
-    lamp = -prim - 1;
+    const int shader_flag = kdistribution->mesh_light.shader_flag;
+    triangle_light_sample(kg, prim, object, randu, randv, time, ls, P);
+    ls->shader |= shader_flag;
+    return (ls->pdf > 0.0f);
   }
 
+  const int lamp = -prim - 1;
+
   if (UNLIKELY(light_select_reached_max_bounces(kg, lamp, bounce))) {
     return false;
   }



More information about the Bf-blender-cvs mailing list