[Bf-blender-cvs] [54a6ae709ff] cycles_path_guiding: Refactor functions to record paths for path guiding:

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


Commit: 54a6ae709ff03309eed5996253e92270d5ae6a13
Author: Brecht Van Lommel
Date:   Thu Aug 25 17:28:13 2022 +0200
Branches: cycles_path_guiding
https://developer.blender.org/rB54a6ae709ff03309eed5996253e92270d5ae6a13

Refactor functions to record paths for path guiding:

* Use guiding_record_ prefix for all, and rename to better match Cycles
  terminology.
* Move #ifdefs into guiding.h where possible to simplify code calling these.
* Fix missing call to guiding_new_virtual_light_segment with volumes in front
  of lights, by moving this into the shade_light kernel.
* Fix missing call to guiding_add_background for distant lights.

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

M	intern/cycles/kernel/integrator/guiding.h
M	intern/cycles/kernel/integrator/intersect_closest.h
M	intern/cycles/kernel/integrator/path_state.h
M	intern/cycles/kernel/integrator/shade_background.h
M	intern/cycles/kernel/integrator/shade_light.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/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 f9a7f3e8f69..dfeec9b3471 100644
--- a/intern/cycles/kernel/integrator/guiding.h
+++ b/intern/cycles/kernel/integrator/guiding.h
@@ -11,11 +11,16 @@
 
 CCL_NAMESPACE_BEGIN
 
-#if defined(__PATH_GUIDING__)
-#  if PATH_GUIDING_LEVEL >= 1
-ccl_device_forceinline void guiding_new_virtual_light_segment(
-    IntegratorState state, ccl_private const Intersection *ccl_restrict isect)
+/* Path recording for guiding. */
+
+ccl_device_forceinline void guiding_record_light_surface_segment(
+    KernelGlobals kg, IntegratorState state, ccl_private const Intersection *ccl_restrict isect)
 {
+#if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 1
+  if (!kernel_data.integrator.use_guiding) {
+    return;
+  }
+
   const pgl_vec3f pglZero = openpgl::cpp::Vector3(0.f, 0.f, 0.f);
   const pgl_vec3f pglOne = openpgl::cpp::Vector3(1.f, 1.f, 1.f);
   float3 ray_P = INTEGRATOR_STATE(state, ray, P);
@@ -37,11 +42,18 @@ ccl_device_forceinline void guiding_new_virtual_light_segment(
   openpgl::cpp::SetTransmittanceWeight(state->guiding.path_segment, pglOne);
   openpgl::cpp::SetScatteringWeight(state->guiding.path_segment, pglOne);
   openpgl::cpp::SetEta(state->guiding.path_segment, 1.0f);
+#endif
 }
 
-ccl_device_forceinline void guiding_new_surface_segment(IntegratorState state,
-                                                        const ShaderData *sd)
+ccl_device_forceinline void guiding_record_surface_segment(KernelGlobals kg,
+                                                           IntegratorState state,
+                                                           ccl_private const ShaderData *sd)
 {
+#if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 1
+  if (!kernel_data.integrator.use_guiding) {
+    return;
+  }
+
   const pgl_vec3f pglZero = openpgl::cpp::Vector3(0.f, 0.f, 0.f);
   const pgl_vec3f pglOne = openpgl::cpp::Vector3(1.f, 1.f, 1.f);
   pgl_point3f pglP = openpgl::cpp::Point3(sd->P.x, sd->P.y, sd->P.z);
@@ -55,22 +67,30 @@ ccl_device_forceinline void guiding_new_surface_segment(IntegratorState state,
   openpgl::cpp::SetDirectContribution(state->guiding.path_segment, pglZero);
   openpgl::cpp::SetTransmittanceWeight(state->guiding.path_segment, pglOne);
   openpgl::cpp::SetEta(state->guiding.path_segment, 1.0);
+#endif
 }
 
-ccl_device_forceinline void guiding_add_bsdf_data(IntegratorState state,
-                                                  const ShaderData *sd,
-                                                  const Spectrum bsdf_weight,
-                                                  const float bsdf_pdf,
-                                                  const float3 bsdf_shading_normal,
-                                                  const float3 bsdf_omega_in,
-                                                  const float2 bsdf_roughness,
-                                                  const float bsdf_eta,
-                                                  const bool bsdf_is_delta)
+ccl_device_forceinline void guiding_record_surface_bounce(KernelGlobals kg,
+                                                          IntegratorState state,
+                                                          ccl_private const ShaderData *sd,
+                                                          const Spectrum bsdf_weight,
+                                                          const float bsdf_pdf,
+                                                          const float3 bsdf_shading_normal,
+                                                          const float3 bsdf_omega_in,
+                                                          const float2 bsdf_roughness,
+                                                          const float bsdf_eta)
 {
+#if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 4
+  if (!kernel_data.integrator.use_guiding) {
+    return;
+  }
+
   float roughness = fminf(bsdf_roughness.x, bsdf_roughness.y);
-  if (roughness > 0.0f)
+  if (roughness > 0.0f) {
     roughness = sqrt(roughness);
+  }
 
+  const bool bsdf_is_delta = roughness > 0.f ? false : true;
   const float3 bsdf_weight_rgb = spectrum_to_rgb(bsdf_weight);
 
   pgl_vec3f pglWo = openpgl::cpp::Vector3(bsdf_omega_in[0], bsdf_omega_in[1], bsdf_omega_in[2]);
@@ -92,12 +112,19 @@ ccl_device_forceinline void guiding_add_bsdf_data(IntegratorState state,
   openpgl::cpp::SetIsDelta(state->guiding.path_segment, bsdf_is_delta);
   openpgl::cpp::SetEta(state->guiding.path_segment, bsdf_eta);
   openpgl::cpp::SetRoughness(state->guiding.path_segment, roughness);
+#endif
 }
 
-ccl_device_forceinline void guiding_new_bssrdf_segment(IntegratorState state,
-                                                       const float3 &P,
-                                                       const float3 &I)
+ccl_device_forceinline void guiding_record_bssrdf_segment(KernelGlobals kg,
+                                                          IntegratorState state,
+                                                          const float3 &P,
+                                                          const float3 &I)
 {
+#if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 1
+  if (!kernel_data.integrator.use_guiding) {
+    return;
+  }
+
   const pgl_vec3f pglZero = openpgl::cpp::Vector3(0.f, 0.f, 0.f);
   const pgl_vec3f pglOne = openpgl::cpp::Vector3(1.f, 1.f, 1.f);
   pgl_point3f pglP = openpgl::cpp::Point3(P.x, P.y, P.z);
@@ -111,14 +138,21 @@ ccl_device_forceinline void guiding_new_bssrdf_segment(IntegratorState state,
   openpgl::cpp::SetDirectContribution(state->guiding.path_segment, pglZero);
   openpgl::cpp::SetTransmittanceWeight(state->guiding.path_segment, pglOne);
   openpgl::cpp::SetEta(state->guiding.path_segment, 1.0);
+#endif
 }
 
-ccl_device_forceinline void guiding_add_bssrdf_data(IntegratorState state,
-                                                    const Spectrum bssrdf_weight,
-                                                    const float bssrdf_pdf,
-                                                    const float3 bssrdf_shading_normal,
-                                                    const float3 bssrdf_omega_in)
+ccl_device_forceinline void guiding_record_bssrdf_bounce(KernelGlobals kg,
+                                                         IntegratorState state,
+                                                         const Spectrum bssrdf_weight,
+                                                         const float bssrdf_pdf,
+                                                         const float3 bssrdf_shading_normal,
+                                                         const float3 bssrdf_omega_in)
 {
+#if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 1
+  if (!kernel_data.integrator.use_guiding) {
+    return;
+  }
+
   const float3 bssrdf_weight_rgb = spectrum_to_rgb(bssrdf_weight);
 
   pgl_vec3f pglWo = openpgl::cpp::Vector3(
@@ -141,12 +175,19 @@ ccl_device_forceinline void guiding_add_bssrdf_data(IntegratorState state,
   openpgl::cpp::SetIsDelta(state->guiding.path_segment, false);
   openpgl::cpp::SetEta(state->guiding.path_segment, 1.0f);
   openpgl::cpp::SetRoughness(state->guiding.path_segment, 1.0f);
+#endif
 }
 
-ccl_device_forceinline void guiding_new_volume_segment(IntegratorState state,
-                                                       const float3 &P,
-                                                       const float3 &I)
+ccl_device_forceinline void guiding_record_volume_segment(KernelGlobals kg,
+                                                          IntegratorState state,
+                                                          const float3 &P,
+                                                          const float3 &I)
 {
+#if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 1
+  if (!kernel_data.integrator.use_guiding) {
+    return;
+  }
+
   const pgl_vec3f pglZero = openpgl::cpp::Vector3(0.f, 0.f, 0.f);
   const pgl_vec3f pglOne = openpgl::cpp::Vector3(1.f, 1.f, 1.f);
   pgl_point3f pglP = openpgl::cpp::Point3(P.x, P.y, P.z);
@@ -161,15 +202,22 @@ ccl_device_forceinline void guiding_new_volume_segment(IntegratorState state,
   openpgl::cpp::SetDirectContribution(state->guiding.path_segment, pglZero);
   openpgl::cpp::SetTransmittanceWeight(state->guiding.path_segment, pglOne);
   openpgl::cpp::SetEta(state->guiding.path_segment, 1.0);
+#endif
 }
 
-ccl_device_forceinline void guiding_add_phase_data(IntegratorState state,
-                                                   const ShaderData *sd,
-                                                   const Spectrum phase_weight,
-                                                   const float phase_pdf,
-                                                   const float3 phase_omega_in,
-                                                   const float phase_roughness)
+ccl_device_forceinline void guiding_record_volume_bounce(KernelGlobals kg,
+                                                         IntegratorState state,
+                                                         ccl_private const ShaderData *sd,
+                                                         const Spectrum phase_weight,
+                                                         const float phase_pdf,
+                                                         const float3 phase_omega_in,
+                                                         const float phase_roughness)
 {
+#if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 4
+  if (!kernel_data.integrator.use_guiding) {
+    return;
+  }
+
   const float3 phase_weight_rgb = spectrum_to_rgb(phase_weight);
 
   pgl_vec3f pglWo = openpgl::cpp::Vector3(phase_omega_in[0], phase_omega_in[1], phase_omega_in[2]);
@@ -189,12 +237,19 @@ ccl_device_forceinline void guiding_add_phase_data(IntegratorState state,
   openpgl::cpp::SetIsDelta(state->guiding.path_segment, false);
   openpgl::cpp::SetEta(state->guiding.path_segment, 1.f);
   openpgl::cpp::SetRoughness(state->guiding.path_segment, phase_roughness);
+#endif
 }
 
-ccl_device_forceinline void guiding_add_background(IntegratorState state,
-          

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list