[Bf-blender-cvs] [6362f2d8d1f] cycles_path_guiding: Replace rr_throughput with factor to multiply with throughput

Brecht Van Lommel noreply at git.blender.org
Thu Aug 25 21:57:39 CEST 2022


Commit: 6362f2d8d1fdd71bc3c5eea908950283c1e19fc6
Author: Brecht Van Lommel
Date:   Thu Aug 25 18:45:11 2022 +0200
Branches: cycles_path_guiding
https://developer.blender.org/rB6362f2d8d1fdd71bc3c5eea908950283c1e19fc6

Replace rr_throughput with factor to multiply with throughput

This seems simpler and more efficient overall.

It also removes a division by albedo of rr_throughput in random walk SSS,
which seems wrong.

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

M	intern/cycles/kernel/integrator/path_state.h
M	intern/cycles/kernel/integrator/shade_surface.h
M	intern/cycles/kernel/integrator/shade_volume.h
M	intern/cycles/kernel/integrator/state_template.h
M	intern/cycles/kernel/integrator/subsurface.h
M	intern/cycles/kernel/integrator/subsurface_disk.h
M	intern/cycles/kernel/integrator/subsurface_random_walk.h

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

diff --git a/intern/cycles/kernel/integrator/path_state.h b/intern/cycles/kernel/integrator/path_state.h
index 550ee8e71c7..51a139a219d 100644
--- a/intern/cycles/kernel/integrator/path_state.h
+++ b/intern/cycles/kernel/integrator/path_state.h
@@ -57,7 +57,7 @@ ccl_device_inline void path_state_init_integrator(KernelGlobals kg,
   INTEGRATOR_STATE_WRITE(state, path, throughput) = one_spectrum();
 
 #ifdef __PATH_GUIDING__
-  INTEGRATOR_STATE_WRITE(state, path, rr_throughput) = one_spectrum();
+  INTEGRATOR_STATE_WRITE(state, path, guiding_throughput) = 1.0f;
 #endif
 
 #ifdef __MNEE__
@@ -253,11 +253,11 @@ ccl_device_inline float path_state_continuation_probability(KernelGlobals kg,
 
   /* Probabilistic termination: use sqrt() to roughly match typical view
    * transform and do path termination a bit later on average. */
-#ifdef __PATH_GUIDING__
-  return min(sqrtf(reduce_max(fabs(INTEGRATOR_STATE(state, path, rr_throughput)))), 1.0f);
-#else
-  return min(sqrtf(reduce_max(fabs(INTEGRATOR_STATE(state, path, throughput)))), 1.0f);
+  Spectrum throughput = INTEGRATOR_STATE(state, path, throughput);
+#if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 4
+  throughput *= INTEGRATOR_STATE(state, path, guiding_throughput);
 #endif
+  return min(sqrtf(reduce_max(fabs(throughput))), 1.0f);
 }
 
 ccl_device_inline bool path_state_ao_bounce(KernelGlobals kg, ConstIntegratorState state)
diff --git a/intern/cycles/kernel/integrator/shade_surface.h b/intern/cycles/kernel/integrator/shade_surface.h
index 9bf8da1bf4c..f8b79d7919b 100644
--- a/intern/cycles/kernel/integrator/shade_surface.h
+++ b/intern/cycles/kernel/integrator/shade_surface.h
@@ -352,7 +352,8 @@ ccl_device_forceinline void integrate_surface_direct_light(KernelGlobals kg,
 #  ifdef __PATH_GUIDING__
   INTEGRATOR_STATE_WRITE(
       shadow_state, shadow_path, scattered_contribution) = scattered_contribution;
-  INTEGRATOR_STATE_WRITE(shadow_state, shadow_path, path_segment) = state->guiding.path_segment;
+  INTEGRATOR_STATE_WRITE(shadow_state, shadow_path, path_segment) = INTEGRATOR_STATE(
+      state, guiding, path_segment);
 #  endif
 }
 #endif
@@ -381,7 +382,7 @@ ccl_device_forceinline int integrate_surface_bsdf_bssrdf_bounce(
 #endif
 
   /* BSDF closure, sample direction. */
-  float bsdf_pdf;
+  float bsdf_pdf = 0.0f, guided_bsdf_pdf = 0.0f;
   BsdfEval bsdf_eval ccl_optional_struct_init;
   float3 bsdf_omega_in ccl_optional_struct_init;
   int label;
@@ -390,7 +391,6 @@ ccl_device_forceinline int integrate_surface_bsdf_bssrdf_bounce(
   float bsdf_eta = 1.0f;
 
 #if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 4
-  float guided_bsdf_pdf;
   if (kernel_data.integrator.use_guiding) {
     label = shader_guided_bsdf_sample_closure(kg,
                                               state,
@@ -404,8 +404,16 @@ ccl_device_forceinline int integrate_surface_bsdf_bssrdf_bounce(
                                               &bsdf_pdf,
                                               &bsdf_sampled_roughness,
                                               &bsdf_eta);
+
+    if (guided_bsdf_pdf == 0.0f || bsdf_eval_is_zero(&bsdf_eval)) {
+      return LABEL_NONE;
+    }
+
+    INTEGRATOR_STATE_WRITE(state, path, guiding_throughput) *= guided_bsdf_pdf / bsdf_pdf;
   }
-  else {
+  else
+#endif
+  {
     label = shader_bsdf_sample_closure(kg,
                                        sd,
                                        sc,
@@ -416,27 +424,13 @@ ccl_device_forceinline int integrate_surface_bsdf_bssrdf_bounce(
                                        &bsdf_pdf,
                                        &bsdf_sampled_roughness,
                                        &bsdf_eta);
+
+    if (bsdf_pdf == 0.0f || bsdf_eval_is_zero(&bsdf_eval)) {
+      return LABEL_NONE;
+    }
+
     guided_bsdf_pdf = bsdf_pdf;
   }
-  if (guided_bsdf_pdf == 0.0f || bsdf_eval_is_zero(&bsdf_eval)) {
-    return LABEL_NONE;
-  }
-#else
-  label = shader_bsdf_sample_closure(kg,
-                                     sd,
-                                     sc,
-                                     bsdf_u,
-                                     bsdf_v,
-                                     &bsdf_eval,
-                                     &bsdf_omega_in,
-                                     &bsdf_pdf,
-                                     &bsdf_sampled_roughness,
-                                     &bsdf_eta);
-
-  if (bsdf_pdf == 0.0f || bsdf_eval_is_zero(&bsdf_eval)) {
-    return LABEL_NONE;
-  }
-#endif
 
   if (label & LABEL_TRANSPARENT) {
     /* Only need to modify start distance for transparent. */
@@ -455,18 +449,8 @@ ccl_device_forceinline int integrate_surface_bsdf_bssrdf_bounce(
   }
 
   /* Update throughput. */
-  Spectrum throughput = INTEGRATOR_STATE(state, path, throughput);
-#if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 4
   const Spectrum bsdf_weight = bsdf_eval_sum(&bsdf_eval) / guided_bsdf_pdf;
-#else
-  const Spectrum bsdf_weight = bsdf_eval_sum(&bsdf_eval) / bsdf_pdf;
-#endif
-  throughput *= bsdf_weight;
-  INTEGRATOR_STATE_WRITE(state, path, throughput) = throughput;
-#if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 4
-  const Spectrum rr_bsdf_weight = bsdf_eval_sum(&bsdf_eval) / bsdf_pdf;
-  INTEGRATOR_STATE_WRITE(state, path, rr_throughput) *= rr_bsdf_weight;
-#endif
+  INTEGRATOR_STATE_WRITE(state, path, throughput) *= bsdf_weight;
 
   if (kernel_data.kernel_features & KERNEL_FEATURE_LIGHT_PASSES) {
     if (INTEGRATOR_STATE(state, path, bounce) == 0) {
@@ -479,21 +463,13 @@ ccl_device_forceinline int integrate_surface_bsdf_bssrdf_bounce(
 
   /* Update path state */
   if (!(label & LABEL_TRANSPARENT)) {
-#if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 4
     INTEGRATOR_STATE_WRITE(state, path, mis_ray_pdf) = guided_bsdf_pdf;
-#else
-    INTEGRATOR_STATE_WRITE(state, path, mis_ray_pdf) = bsdf_pdf;
-#endif
     INTEGRATOR_STATE_WRITE(state, path, min_ray_pdf) = fminf(
         bsdf_pdf, INTEGRATOR_STATE(state, path, min_ray_pdf));
   }
 
   path_state_next(kg, state, label);
 
-#if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 1
-#  if PATH_GUIDING_LEVEL < 4
-  float guided_bsdf_pdf = bsdf_pdf;
-#  endif
   guiding_record_surface_bounce(kg,
                                 state,
                                 sd,
@@ -503,7 +479,6 @@ ccl_device_forceinline int integrate_surface_bsdf_bssrdf_bounce(
                                 normalize(bsdf_omega_in),
                                 bsdf_sampled_roughness,
                                 bsdf_eta);
-#endif
 
   return label;
 }
@@ -535,9 +510,6 @@ ccl_device_forceinline bool integrate_surface_terminate(IntegratorState state,
   }
   else if (continuation_probability != 1.0f) {
     INTEGRATOR_STATE_WRITE(state, path, throughput) /= continuation_probability;
-#if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 4
-    INTEGRATOR_STATE_WRITE(state, path, rr_throughput) /= continuation_probability;
-#endif
   }
 
   return false;
diff --git a/intern/cycles/kernel/integrator/shade_volume.h b/intern/cycles/kernel/integrator/shade_volume.h
index b7d5c9b342c..450619f1b98 100644
--- a/intern/cycles/kernel/integrator/shade_volume.h
+++ b/intern/cycles/kernel/integrator/shade_volume.h
@@ -916,7 +916,8 @@ ccl_device_forceinline void integrate_volume_direct_light(
 #    if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 1
   INTEGRATOR_STATE_WRITE(
       shadow_state, shadow_path, scattered_contribution) = scattered_contribution;
-  INTEGRATOR_STATE_WRITE(shadow_state, shadow_path, path_segment) = state->guiding.path_segment;
+  INTEGRATOR_STATE_WRITE(shadow_state, shadow_path, path_segment) = INTEGRATOR_STATE(
+      state, guiding, path_segment);
 #    endif
 
   integrator_state_copy_volume_stack_to_shadow(kg, shadow_state, state);
@@ -944,14 +945,13 @@ ccl_device_forceinline bool integrate_volume_phase_scatter(
 #  endif
 
   /* Phase closure, sample direction. */
-  float phase_pdf;
+  float phase_pdf = 0.0f, guided_phase_pdf = 0.0f;
   BsdfEval phase_eval ccl_optional_struct_init;
   float3 phase_omega_in ccl_optional_struct_init;
-
   float sampled_roughness = 1.0f;
-#  if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 4
-  float guided_phase_pdf;
   int label;
+
+#  if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 4
   if (kernel_data.integrator.use_guiding) {
     label = shader_guided_volume_phase_sample(kg,
                                               state,
@@ -964,8 +964,16 @@ ccl_device_forceinline bool integrate_volume_phase_scatter(
                                               &guided_phase_pdf,
                                               &phase_pdf,
                                               &sampled_roughness);
+
+    if (guided_phase_pdf == 0.0f || bsdf_eval_is_zero(&phase_eval)) {
+      return false;
+    }
+
+    INTEGRATOR_STATE_WRITE(state, path, guiding_throughput) *= guided_phase_pdf / phase_pdf;
   }
-  else {
+  else
+#  endif
+  {
     label = shader_volume_phase_sample(kg,
                                        sd,
                                        phases,
@@ -975,23 +983,12 @@ ccl_device_forceinline bool integrate_volume_phase_scatter(
                                        &phase_omega_in,
                                        &phase_pdf,
                                        &sampled_roughness);
-    guided_phase_pdf = phase_pdf;
-  }
-#  else
-  const int label = shader_volume_phase_sample(kg,
-                                               sd,
-                                               phases,
-                                               phase_u,
-                                               phase_v,
-                                               &phase_eval,
-                                               &phase_omega_in,
-                                               &phase_pdf,
-                                               &sampled_roughness);
-  const float guided_phase_pdf = phase_pdf;
-#  endif
 
-  if (phase_pdf == 0.0f || bsdf_eval_is_zero(&phase_eval)) {
-    return false;
+    if (phase_pdf == 0.0f || bsdf_eval_is_zero(&phase_eval)) {
+      return false;
+    }
+
+    guided_phase_pdf = phase_pdf;
   }
 
   /* Setu

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list