[Bf-blender-cvs] [e85f04c15d0] cycles_path_guiding: Simplify BSSRDF bounce recording.

Brecht Van Lommel noreply at git.blender.org
Tue Sep 20 21:00:37 CEST 2022


Commit: e85f04c15d0731c5fe64b437667c44bfa9626e57
Author: Brecht Van Lommel
Date:   Tue Sep 20 19:00:08 2022 +0200
Branches: cycles_path_guiding
https://developer.blender.org/rBe85f04c15d0731c5fe64b437667c44bfa9626e57

Simplify BSSRDF bounce recording.

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

M	intern/cycles/kernel/integrator/guiding.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/guiding.h b/intern/cycles/kernel/integrator/guiding.h
index 11c21318010..eaa73acf72d 100644
--- a/intern/cycles/kernel/integrator/guiding.h
+++ b/intern/cycles/kernel/integrator/guiding.h
@@ -141,13 +141,16 @@ ccl_device_forceinline void guiding_record_bssrdf_segment(KernelGlobals kg,
  * the surface boundary.*/
 ccl_device_forceinline void guiding_record_bssrdf_weight(KernelGlobals kg,
                                                          IntegratorState state,
-                                                         const Spectrum weight)
+                                                         const Spectrum weight,
+                                                         const Spectrum albedo)
 {
 #if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 1
   if (!kernel_data.integrator.train_guiding) {
     return;
   }
-  const float3 weight_rgb = spectrum_to_rgb(weight);
+
+  /* Note albedo left out here, will be included in guiding_record_bssrdf_bounce. */
+  const float3 weight_rgb = spectrum_to_rgb(safe_divide_color(weight, albedo));
 
   kernel_assert(state->guiding.path_segment != nullptr);
 
@@ -167,13 +170,16 @@ ccl_device_forceinline void guiding_record_bssrdf_bounce(KernelGlobals kg,
                                                          IntegratorState state,
                                                          const float pdf,
                                                          const float3 N,
-                                                         const float3 omega_in)
+                                                         const float3 omega_in,
+                                                         const Spectrum weight,
+                                                         const Spectrum albedo)
 {
 #if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 1
   if (!kernel_data.integrator.train_guiding) {
     return;
   }
   const float3 normal = clamp(N, -one_float3(), one_float3());
+  const float3 weight_rgb = spectrum_to_rgb(weight * albedo);
 
   kernel_assert(state->guiding.path_segment != nullptr);
 
@@ -181,6 +187,7 @@ ccl_device_forceinline void guiding_record_bssrdf_bounce(KernelGlobals kg,
   openpgl::cpp::SetNormal(state->guiding.path_segment, guiding_vec3f(normal));
   openpgl::cpp::SetDirectionIn(state->guiding.path_segment, guiding_vec3f(omega_in));
   openpgl::cpp::SetPDFDirectionIn(state->guiding.path_segment, pdf);
+  openpgl::cpp::SetTransmittanceWeight(state->guiding.path_segment, guiding_vec3f(weight_rgb));
 #endif
 }
 
diff --git a/intern/cycles/kernel/integrator/subsurface.h b/intern/cycles/kernel/integrator/subsurface.h
index 979c298e0a9..efd293e4141 100644
--- a/intern/cycles/kernel/integrator/subsurface.h
+++ b/intern/cycles/kernel/integrator/subsurface.h
@@ -78,9 +78,8 @@ ccl_device int subsurface_bounce(KernelGlobals kg,
   INTEGRATOR_STATE_WRITE(state, subsurface, radius) = bssrdf->radius;
   INTEGRATOR_STATE_WRITE(state, subsurface, anisotropy) = bssrdf->anisotropy;
 
-  if (kernel_data.integrator.use_guiding) {
-    guiding_record_bssrdf_weight(kg, state, safe_divide_color(weight, bssrdf->albedo));
-  }
+  /* Path guiding. */
+  guiding_record_bssrdf_weight(kg, state, weight, bssrdf->albedo);
 
   return LABEL_SUBSURFACE_SCATTER;
 }
diff --git a/intern/cycles/kernel/integrator/subsurface_disk.h b/intern/cycles/kernel/integrator/subsurface_disk.h
index 5377e7f19e0..16fb45392f4 100644
--- a/intern/cycles/kernel/integrator/subsurface_disk.h
+++ b/intern/cycles/kernel/integrator/subsurface_disk.h
@@ -40,17 +40,6 @@ ccl_device_inline bool subsurface_disk(KernelGlobals kg,
   /* Read subsurface scattering parameters. */
   const Spectrum radius = INTEGRATOR_STATE(state, subsurface, radius);
 
-#if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 1
-  const Spectrum albedo = INTEGRATOR_STATE(state, subsurface, albedo);
-  Spectrum throughput = INTEGRATOR_STATE(state, path, throughput);
-  throughput = safe_divide_color(throughput, albedo);
-  const bool use_guiding = kernel_data.integrator.use_guiding;
-  Spectrum initial_throughput = throughput;
-  if (use_guiding) {
-    guiding_record_bssrdf_bounce(kg, state, 1.f, Ng, -Ng);
-  }
-#endif
-
   /* Pick random axis in local frame and point on disk. */
   float3 disk_N, disk_T, disk_B;
   float pick_pdf_N, pick_pdf_T, pick_pdf_B;
@@ -186,7 +175,8 @@ ccl_device_inline bool subsurface_disk(KernelGlobals kg,
 
     if (r < next_sum) {
       /* Return exit point. */
-      INTEGRATOR_STATE_WRITE(state, path, throughput) *= weight * sum_weights / sample_weight;
+      const Spectrum resampled_weight = weight * sum_weights / sample_weight;
+      INTEGRATOR_STATE_WRITE(state, path, throughput) *= resampled_weight;
       ss_isect.hits[0] = ss_isect.hits[hit];
       ss_isect.Ng[0] = ss_isect.Ng[hit];
 
@@ -195,17 +185,8 @@ ccl_device_inline bool subsurface_disk(KernelGlobals kg,
       ray.tmin = 0.0f;
       ray.tmax = 1.0f;
 
-#if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 1
-      // calculate the transmittance weight for the comple SSS-random walk
-      if (use_guiding) {
-        throughput = INTEGRATOR_STATE(state, path, throughput);
-        initial_throughput = safe_divide_color(throughput, initial_throughput);
-        openpgl::cpp::SetTransmittanceWeight(state->guiding.path_segment,
-                                             openpgl::cpp::Vector3(initial_throughput.x,
-                                                                   initial_throughput.y,
-                                                                   initial_throughput.z));
-      }
-#endif
+      guiding_record_bssrdf_bounce(
+          kg, state, 1.0f, Ng, -Ng, resampled_weight, INTEGRATOR_STATE(state, subsurface, albedo));
       return true;
     }
 
diff --git a/intern/cycles/kernel/integrator/subsurface_random_walk.h b/intern/cycles/kernel/integrator/subsurface_random_walk.h
index 02bc2b8f2ca..45d4aa1b53d 100644
--- a/intern/cycles/kernel/integrator/subsurface_random_walk.h
+++ b/intern/cycles/kernel/integrator/subsurface_random_walk.h
@@ -209,14 +209,6 @@ ccl_device_inline bool subsurface_random_walk(KernelGlobals kg,
   subsurface_random_walk_coefficients(albedo, radius, anisotropy, &sigma_t, &alpha, &throughput);
   Spectrum sigma_s = sigma_t * alpha;
 
-#if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 1
-  const bool use_guiding = kernel_data.integrator.use_guiding;
-  Spectrum initial_throughput = throughput;
-  if (use_guiding) {
-    guiding_record_bssrdf_bounce(kg, state, pdf, N, D);
-  }
-#endif
-
   /* Theoretically it should be better to use the exact alpha for the channel we're sampling at
    * each bounce, but in practice there doesn't seem to be a noticeable difference in exchange
    * for making the code significantly more complex and slower (if direction sampling depends on
@@ -444,18 +436,21 @@ ccl_device_inline bool subsurface_random_walk(KernelGlobals kg,
 
   if (hit) {
     kernel_assert(isfinite_safe(throughput));
-    INTEGRATOR_STATE_WRITE(state, path, throughput) = throughput;
-  }
+
 #if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 1
-  if (use_guiding) {
-    // calculate the transmittance weight for the comple SSS-random walk
-    initial_throughput = safe_divide_color(throughput, initial_throughput);
-    openpgl::cpp::SetTransmittanceWeight(
-        state->guiding.path_segment,
-        openpgl::cpp::Vector3(initial_throughput.x, initial_throughput.y, initial_throughput.z));
-  }
+    guiding_record_bssrdf_bounce(
+        kg,
+        state,
+        pdf,
+        N,
+        D,
+        safe_divide_color(throughput, INTEGRATOR_STATE(state, path, throughput)),
+        albedo);
 #endif
 
+    INTEGRATOR_STATE_WRITE(state, path, throughput) = throughput;
+  }
+
   return hit;
 }



More information about the Bf-blender-cvs mailing list