[Bf-blender-cvs] [2338f3a4906] cycles_path_guiding: Fix subtle difference in volume shadow path termination

Brecht Van Lommel noreply at git.blender.org
Wed Sep 21 21:47:17 CEST 2022


Commit: 2338f3a4906c1e487c3b874ae2eb393ac15eb99e
Author: Brecht Van Lommel
Date:   Wed Sep 21 21:30:59 2022 +0200
Branches: cycles_path_guiding
https://developer.blender.org/rB2338f3a4906c1e487c3b874ae2eb393ac15eb99e

Fix subtle difference in volume shadow path termination

Volume shadow integration should get the full throughput to make a decision
when opacity falls is above the threshold.

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

M	intern/cycles/kernel/integrator/guiding.h
M	intern/cycles/kernel/integrator/shade_shadow.h
M	intern/cycles/kernel/integrator/shade_surface.h
M	intern/cycles/kernel/integrator/shade_volume.h
M	intern/cycles/kernel/integrator/shadow_state_template.h

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

diff --git a/intern/cycles/kernel/integrator/guiding.h b/intern/cycles/kernel/integrator/guiding.h
index f0b5477c538..cff5478f427 100644
--- a/intern/cycles/kernel/integrator/guiding.h
+++ b/intern/cycles/kernel/integrator/guiding.h
@@ -372,7 +372,9 @@ ccl_device_forceinline void guiding_record_direct_light(KernelGlobals kg,
     return;
   }
   if (state->shadow_path.path_segment) {
-    const Spectrum Lo = INTEGRATOR_STATE(state, shadow_path, scattered_contribution);
+    const Spectrum Lo = safe_divide_color(INTEGRATOR_STATE(state, shadow_path, throughput),
+                                          INTEGRATOR_STATE(state, shadow_path, unlit_throughput));
+
     const float3 Lo_rgb = spectrum_to_rgb(Lo);
     openpgl::cpp::AddScatteredContribution(state->shadow_path.path_segment, guiding_vec3f(Lo_rgb));
   }
diff --git a/intern/cycles/kernel/integrator/shade_shadow.h b/intern/cycles/kernel/integrator/shade_shadow.h
index 5278e92ea60..bedb15ddf89 100644
--- a/intern/cycles/kernel/integrator/shade_shadow.h
+++ b/intern/cycles/kernel/integrator/shade_shadow.h
@@ -95,27 +95,18 @@ ccl_device_inline bool integrate_transparent_shadow(KernelGlobals kg,
 {
   /* Accumulate shadow for transparent surfaces. */
   const uint num_recorded_hits = min(num_hits, INTEGRATOR_SHADOW_ISECT_SIZE);
-#  ifdef __PATH_GUIDING__
-  const bool use_guiding = kernel_data.integrator.use_guiding;
-#  endif
+
   for (uint hit = 0; hit < num_recorded_hits + 1; hit++) {
     /* Volume shaders. */
     if (hit < num_recorded_hits || !shadow_intersections_has_remaining(num_hits)) {
 #  ifdef __VOLUME__
       if (!integrator_state_shadow_volume_stack_is_empty(kg, state)) {
         Spectrum throughput = INTEGRATOR_STATE(state, shadow_path, throughput);
-        Spectrum transmittance = one_spectrum();
-        integrate_transparent_volume_shadow(kg, state, hit, num_recorded_hits, &transmittance);
-        throughput *= transmittance;
-#    ifdef __PATH_GUIDING__
-        if (use_guiding) {
-          INTEGRATOR_STATE_WRITE(state, shadow_path, scattered_contribution) =
-              INTEGRATOR_STATE(state, shadow_path, scattered_contribution) * transmittance;
-        }
-#    endif
+        integrate_transparent_volume_shadow(kg, state, hit, num_recorded_hits, &throughput);
         if (is_zero(throughput)) {
           return true;
         }
+
         INTEGRATOR_STATE_WRITE(state, shadow_path, throughput) = throughput;
       }
 #  endif
@@ -125,12 +116,6 @@ ccl_device_inline bool integrate_transparent_shadow(KernelGlobals kg,
     if (hit < num_recorded_hits) {
       const Spectrum shadow = integrate_transparent_surface_shadow(kg, state, hit);
       const Spectrum throughput = INTEGRATOR_STATE(state, shadow_path, throughput) * shadow;
-#  ifdef __PATH_GUIDING__
-      if (use_guiding) {
-        INTEGRATOR_STATE_WRITE(state, shadow_path, scattered_contribution) =
-            INTEGRATOR_STATE(state, shadow_path, scattered_contribution) * shadow;
-      }
-#  endif
       if (is_zero(throughput)) {
         return true;
       }
diff --git a/intern/cycles/kernel/integrator/shade_surface.h b/intern/cycles/kernel/integrator/shade_surface.h
index 5426600e7f5..16e65c774bc 100644
--- a/intern/cycles/kernel/integrator/shade_surface.h
+++ b/intern/cycles/kernel/integrator/shade_surface.h
@@ -258,8 +258,8 @@ ccl_device_forceinline void integrate_surface_direct_light(KernelGlobals kg,
   /* Copy state from main path to shadow path. */
   uint32_t shadow_flag = INTEGRATOR_STATE(state, path, flag);
   shadow_flag |= (is_light) ? PATH_RAY_SHADOW_FOR_LIGHT : 0;
-  const Spectrum scattered_contribution = bsdf_eval_sum(&bsdf_eval);
-  const Spectrum throughput = INTEGRATOR_STATE(state, path, throughput) * scattered_contribution;
+  const Spectrum unlit_throughput = INTEGRATOR_STATE(state, path, throughput);
+  const Spectrum throughput = unlit_throughput * bsdf_eval_sum(&bsdf_eval);
 
   if (kernel_data.kernel_features & KERNEL_FEATURE_LIGHT_PASSES) {
     PackedSpectrum pass_diffuse_weight;
@@ -330,8 +330,7 @@ ccl_device_forceinline void integrate_surface_direct_light(KernelGlobals kg,
                                                    ls.group + 1 :
                                                    kernel_data.background.lightgroup + 1;
 #ifdef __PATH_GUIDING__
-  INTEGRATOR_STATE_WRITE(
-      shadow_state, shadow_path, scattered_contribution) = scattered_contribution;
+  INTEGRATOR_STATE_WRITE(shadow_state, shadow_path, unlit_throughput) = unlit_throughput;
   INTEGRATOR_STATE_WRITE(shadow_state, shadow_path, path_segment) = INTEGRATOR_STATE(
       state, guiding, path_segment);
 #endif
diff --git a/intern/cycles/kernel/integrator/shade_volume.h b/intern/cycles/kernel/integrator/shade_volume.h
index d10b53516e1..a8324cda2dc 100644
--- a/intern/cycles/kernel/integrator/shade_volume.h
+++ b/intern/cycles/kernel/integrator/shade_volume.h
@@ -799,8 +799,7 @@ ccl_device_forceinline void integrate_volume_direct_light(
   const uint16_t transparent_bounce = INTEGRATOR_STATE(state, path, transparent_bounce);
   uint32_t shadow_flag = INTEGRATOR_STATE(state, path, flag);
   shadow_flag |= (is_light) ? PATH_RAY_SHADOW_FOR_LIGHT : 0;
-  const Spectrum scattered_contribution = bsdf_eval_sum(&phase_eval);
-  const Spectrum throughput_phase = throughput * scattered_contribution;
+  const Spectrum throughput_phase = throughput * bsdf_eval_sum(&phase_eval);
 
   if (kernel_data.kernel_features & KERNEL_FEATURE_LIGHT_PASSES) {
     PackedSpectrum pass_diffuse_weight;
@@ -851,9 +850,8 @@ ccl_device_forceinline void integrate_volume_direct_light(
                                                    ls->group + 1 :
                                                    kernel_data.background.lightgroup + 1;
 
-#  if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 1
-  INTEGRATOR_STATE_WRITE(
-      shadow_state, shadow_path, scattered_contribution) = scattered_contribution;
+#  ifdef __PATH_GUIDING__
+  INTEGRATOR_STATE_WRITE(shadow_state, shadow_path, unlit_throughput) = throughput;
   INTEGRATOR_STATE_WRITE(shadow_state, shadow_path, path_segment) = INTEGRATOR_STATE(
       state, guiding, path_segment);
 #  endif
diff --git a/intern/cycles/kernel/integrator/shadow_state_template.h b/intern/cycles/kernel/integrator/shadow_state_template.h
index 8aa9ed9e30e..f28430d99b7 100644
--- a/intern/cycles/kernel/integrator/shadow_state_template.h
+++ b/intern/cycles/kernel/integrator/shadow_state_template.h
@@ -40,20 +40,14 @@ KERNEL_STRUCT_MEMBER(shadow_path, PackedSpectrum, pass_glossy_weight, KERNEL_FEA
 KERNEL_STRUCT_MEMBER(shadow_path, uint16_t, num_hits, KERNEL_FEATURE_PATH_TRACING)
 /* Light group. */
 KERNEL_STRUCT_MEMBER(shadow_path, uint8_t, lightgroup, KERNEL_FEATURE_PATH_TRACING)
+/* Path guiding. */
+KERNEL_STRUCT_MEMBER(shadow_path, PackedSpectrum, unlit_throughput, KERNEL_FEATURE_PATH_GUIDING)
 #ifdef __PATH_GUIDING__
-KERNEL_STRUCT_MEMBER(shadow_path,
-                     PackedSpectrum,
-                     scattered_contribution,
-                     KERNEL_FEATURE_PATH_GUIDING)
 KERNEL_STRUCT_MEMBER(shadow_path,
                      openpgl::cpp::PathSegment *,
                      path_segment,
                      KERNEL_FEATURE_PATH_GUIDING)
 #else
-KERNEL_STRUCT_MEMBER(shadow_path,
-                     PackedSpectrum,
-                     scattered_contribution,
-                     KERNEL_FEATURE_PATH_GUIDING)
 KERNEL_STRUCT_MEMBER(shadow_path, void *, path_segment, KERNEL_FEATURE_PATH_GUIDING)
 #endif
 KERNEL_STRUCT_END(shadow_path)



More information about the Bf-blender-cvs mailing list