[Bf-blender-cvs] [ab69f9a7587] cycles_path_guiding: Cleanup: move guiding utilities from state_util.h to new guiding.h

Brecht Van Lommel noreply at git.blender.org
Thu Aug 11 14:12:50 CEST 2022


Commit: ab69f9a758713e6e0c214bbe75a9129d1527098f
Author: Brecht Van Lommel
Date:   Thu Aug 11 13:58:01 2022 +0200
Branches: cycles_path_guiding
https://developer.blender.org/rBab69f9a758713e6e0c214bbe75a9129d1527098f

Cleanup: move guiding utilities from state_util.h to new guiding.h

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

M	intern/cycles/kernel/CMakeLists.txt
A	intern/cycles/kernel/integrator/guiding.h
M	intern/cycles/kernel/integrator/intersect_closest.h
M	intern/cycles/kernel/integrator/intersect_volume_stack.h
M	intern/cycles/kernel/integrator/shade_background.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/shader_eval.h
M	intern/cycles/kernel/integrator/state_util.h
M	intern/cycles/kernel/integrator/subsurface_disk.h
M	intern/cycles/kernel/integrator/subsurface_random_walk.h

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

diff --git a/intern/cycles/kernel/CMakeLists.txt b/intern/cycles/kernel/CMakeLists.txt
index fbc30234dac..82ae18e9e73 100644
--- a/intern/cycles/kernel/CMakeLists.txt
+++ b/intern/cycles/kernel/CMakeLists.txt
@@ -240,6 +240,7 @@ set(SRC_KERNEL_INTEGRATOR_HEADERS
   integrator/intersect_shadow.h
   integrator/intersect_subsurface.h
   integrator/intersect_volume_stack.h
+  integrator/guiding.h
   integrator/megakernel.h
   integrator/mnee.h
   integrator/path_state.h
diff --git a/intern/cycles/kernel/integrator/guiding.h b/intern/cycles/kernel/integrator/guiding.h
new file mode 100644
index 00000000000..540d784e467
--- /dev/null
+++ b/intern/cycles/kernel/integrator/guiding.h
@@ -0,0 +1,302 @@
+/* SPDX-License-Identifier: Apache-2.0
+ * Copyright 2011-2022 Blender Foundation */
+
+#pragma once
+
+#if defined(PATH_GUIDING_DEBUG_PASS)
+#  include "kernel/closure/alloc.h"
+#  include "kernel/closure/bsdf.h"
+#  include "kernel/film/write_passes.h"
+#endif
+
+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)
+{
+  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);
+  float3 ray_D = INTEGRATOR_STATE(state, ray, D);
+  float3 p = ray_P + isect->t * ray_D;
+  pgl_point3f pglP = openpgl::cpp::Point3(p[0], p[1], p[2]);
+  pgl_vec3f pglWi = openpgl::cpp::Vector3(-ray_D[0], -ray_D[1], -ray_D[2]);
+  pgl_vec3f pglWo = openpgl::cpp::Vector3(ray_D[0], ray_D[1], ray_D[2]);
+
+  state->guiding.path_segment = state->guiding.path_segment_storage->NextSegment();
+  openpgl::cpp::SetPosition(state->guiding.path_segment, pglP);
+  openpgl::cpp::SetDirectionOut(state->guiding.path_segment, pglWi);
+  openpgl::cpp::SetNormal(state->guiding.path_segment, pglWi);
+  openpgl::cpp::SetDirectionIn(state->guiding.path_segment, pglWo);
+  openpgl::cpp::SetPDFDirectionIn(state->guiding.path_segment, 1.0f);
+  openpgl::cpp::SetVolumeScatter(state->guiding.path_segment, false);
+  openpgl::cpp::SetScatteredContribution(state->guiding.path_segment, pglZero);
+  openpgl::cpp::SetDirectContribution(state->guiding.path_segment, pglZero);
+  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);
+}
+
+ccl_device_forceinline void guiding_new_surface_segment(IntegratorState state,
+                                                        const ShaderData *sd)
+{
+  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);
+  pgl_vec3f pglWi = openpgl::cpp::Vector3(sd->I.x, sd->I.y, sd->I.z);
+
+  state->guiding.path_segment = state->guiding.path_segment_storage->NextSegment();
+  openpgl::cpp::SetPosition(state->guiding.path_segment, pglP);
+  openpgl::cpp::SetDirectionOut(state->guiding.path_segment, pglWi);
+  openpgl::cpp::SetVolumeScatter(state->guiding.path_segment, false);
+  openpgl::cpp::SetScatteredContribution(state->guiding.path_segment, pglZero);
+  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);
+}
+
+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)
+{
+  float roughness = fminf(bsdf_roughness.x, bsdf_roughness.y);
+  if (roughness > 0.0f)
+    roughness = sqrt(roughness);
+
+  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]);
+  pgl_vec3f pglBSDFWeight = openpgl::cpp::Vector3(
+      bsdf_weight_rgb[0], bsdf_weight_rgb[1], bsdf_weight_rgb[2]);
+  pgl_vec3f pglNormal = openpgl::cpp::Vector3(clamp(bsdf_shading_normal[0], -1.f, 1.f),
+                                              clamp(bsdf_shading_normal[1], -1.f, 1.f),
+                                              clamp(bsdf_shading_normal[2], -1.f, 1.f));
+
+  assert(state->guiding.path_segment != nullptr);
+
+  openpgl::cpp::SetTransmittanceWeight(state->guiding.path_segment,
+                                       openpgl::cpp::Vector3(1.0f, 1.0f, 1.0f));
+  openpgl::cpp::SetVolumeScatter(state->guiding.path_segment, false);
+  openpgl::cpp::SetNormal(state->guiding.path_segment, pglNormal);
+  openpgl::cpp::SetDirectionIn(state->guiding.path_segment, pglWo);
+  openpgl::cpp::SetPDFDirectionIn(state->guiding.path_segment, bsdf_pdf);
+  openpgl::cpp::SetScatteringWeight(state->guiding.path_segment, pglBSDFWeight);
+  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);
+}
+
+ccl_device_forceinline void guiding_new_bssrdf_segment(IntegratorState state,
+                                                       const float3 &P,
+                                                       const float3 &I)
+{
+  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);
+  pgl_vec3f pglWi = openpgl::cpp::Vector3(I.x, I.y, I.z);
+
+  state->guiding.path_segment = state->guiding.path_segment_storage->NextSegment();
+  openpgl::cpp::SetPosition(state->guiding.path_segment, pglP);
+  openpgl::cpp::SetDirectionOut(state->guiding.path_segment, pglWi);
+  openpgl::cpp::SetVolumeScatter(state->guiding.path_segment, true);
+  openpgl::cpp::SetScatteredContribution(state->guiding.path_segment, pglZero);
+  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);
+}
+
+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)
+{
+  const float3 bssrdf_weight_rgb = spectrum_to_rgb(bssrdf_weight);
+
+  pgl_vec3f pglWo = openpgl::cpp::Vector3(
+      bssrdf_omega_in[0], bssrdf_omega_in[1], bssrdf_omega_in[2]);
+  pgl_vec3f pglBSSRDFWeight = openpgl::cpp::Vector3(
+      bssrdf_weight_rgb[0], bssrdf_weight_rgb[1], bssrdf_weight_rgb[2]);
+  pgl_vec3f pglNormal = openpgl::cpp::Vector3(clamp(bssrdf_shading_normal[0], -1.f, 1.f),
+                                              clamp(bssrdf_shading_normal[1], -1.f, 1.f),
+                                              clamp(bssrdf_shading_normal[2], -1.f, 1.f));
+
+  assert(state->guiding.path_segment != nullptr);
+
+  openpgl::cpp::SetTransmittanceWeight(state->guiding.path_segment,
+                                       openpgl::cpp::Vector3(1.0f, 1.0f, 1.0f));
+  openpgl::cpp::SetVolumeScatter(state->guiding.path_segment, false);
+  openpgl::cpp::SetNormal(state->guiding.path_segment, pglNormal);
+  openpgl::cpp::SetDirectionIn(state->guiding.path_segment, pglWo);
+  openpgl::cpp::SetPDFDirectionIn(state->guiding.path_segment, bssrdf_pdf);
+  openpgl::cpp::SetScatteringWeight(state->guiding.path_segment, pglBSSRDFWeight);
+  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);
+}
+
+ccl_device_forceinline void guiding_new_volume_segment(IntegratorState state,
+                                                       const float3 &P,
+                                                       const float3 &I)
+{
+  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);
+  pgl_vec3f pglWi = openpgl::cpp::Vector3(I.x, I.y, I.z);
+
+  state->guiding.path_segment = state->guiding.path_segment_storage->NextSegment();
+
+  openpgl::cpp::SetPosition(state->guiding.path_segment, pglP);
+  openpgl::cpp::SetDirectionOut(state->guiding.path_segment, pglWi);
+  openpgl::cpp::SetVolumeScatter(state->guiding.path_segment, true);
+  openpgl::cpp::SetScatteredContribution(state->guiding.path_segment, pglZero);
+  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);
+}
+
+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)
+{
+  const float3 phase_weight_rgb = spectrum_to_rgb(phase_weight);
+
+  pgl_vec3f pglWo = openpgl::cpp::Vecto

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list