[Bf-blender-cvs] [978af0f2b9a] principled-v2: Move Principled BSDF SVM code to separate file

Lukas Stockner noreply at git.blender.org
Mon Jul 4 23:56:13 CEST 2022


Commit: 978af0f2b9a0d69f7c3e7caa229cdfae8f5c9cf2
Author: Lukas Stockner
Date:   Mon Jul 4 23:31:47 2022 +0200
Branches: principled-v2
https://developer.blender.org/rB978af0f2b9a0d69f7c3e7caa229cdfae8f5c9cf2

Move Principled BSDF SVM code to separate file

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

M	intern/cycles/kernel/CMakeLists.txt
M	intern/cycles/kernel/svm/closure.h
M	intern/cycles/kernel/svm/closure_principled.h

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

diff --git a/intern/cycles/kernel/CMakeLists.txt b/intern/cycles/kernel/CMakeLists.txt
index 1e2158ba2ee..4eaae9fdb00 100644
--- a/intern/cycles/kernel/CMakeLists.txt
+++ b/intern/cycles/kernel/CMakeLists.txt
@@ -131,6 +131,7 @@ set(SRC_KERNEL_SVM_HEADERS
   svm/camera.h
   svm/clamp.h
   svm/closure.h
+  svm/closure_principled.h
   svm/convert.h
   svm/checker.h
   svm/color_util.h
diff --git a/intern/cycles/kernel/svm/closure.h b/intern/cycles/kernel/svm/closure.h
index 102b95c7972..fe39f5d6d34 100644
--- a/intern/cycles/kernel/svm/closure.h
+++ b/intern/cycles/kernel/svm/closure.h
@@ -3,6 +3,10 @@
 
 #pragma once
 
+#ifdef __PRINCIPLED__
+#  include "kernel/svm/closure_principled.h"
+#endif
+
 CCL_NAMESPACE_BEGIN
 
 /* Closure Nodes */
@@ -106,382 +110,8 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
   switch (type) {
 #ifdef __PRINCIPLED__
     case CLOSURE_BSDF_PRINCIPLED_ID: {
-      uint specular_offset, roughness_offset, specular_tint_offset, anisotropic_offset,
-          sheen_offset, sheen_tint_offset, clearcoat_offset, clearcoat_roughness_offset,
-          eta_offset, transmission_offset, anisotropic_rotation_offset,
-          transmission_roughness_offset;
-      uint4 data_node2 = read_node(kg, &offset);
-
-      float3 T = stack_load_float3(stack, data_node.y);
-      svm_unpack_node_uchar4(data_node.z,
-                             &specular_offset,
-                             &roughness_offset,
-                             &specular_tint_offset,
-                             &anisotropic_offset);
-      svm_unpack_node_uchar4(data_node.w,
-                             &sheen_offset,
-                             &sheen_tint_offset,
-                             &clearcoat_offset,
-                             &clearcoat_roughness_offset);
-      svm_unpack_node_uchar4(data_node2.x,
-                             &eta_offset,
-                             &transmission_offset,
-                             &anisotropic_rotation_offset,
-                             &transmission_roughness_offset);
-
-      // get Disney principled parameters
-      float metallic = param1;
-      float subsurface = param2;
-      float specular = stack_load_float(stack, specular_offset);
-      float roughness = stack_load_float(stack, roughness_offset);
-      float specular_tint = stack_load_float(stack, specular_tint_offset);
-      float anisotropic = stack_load_float(stack, anisotropic_offset);
-      float sheen = stack_load_float(stack, sheen_offset);
-      float sheen_tint = stack_load_float(stack, sheen_tint_offset);
-      float clearcoat = stack_load_float(stack, clearcoat_offset);
-      float clearcoat_roughness = stack_load_float(stack, clearcoat_roughness_offset);
-      float transmission = stack_load_float(stack, transmission_offset);
-      float anisotropic_rotation = stack_load_float(stack, anisotropic_rotation_offset);
-      float transmission_roughness = stack_load_float(stack, transmission_roughness_offset);
-      float eta = fmaxf(stack_load_float(stack, eta_offset), 1e-5f);
-
-      ClosureType distribution = (ClosureType)data_node2.y;
-      ClosureType subsurface_method = (ClosureType)data_node2.z;
-
-      /* rotate tangent */
-      if (anisotropic_rotation != 0.0f)
-        T = rotate_around_axis(T, N, anisotropic_rotation * M_2PI_F);
-
-      /* calculate ior */
-      float ior = (sd->flag & SD_BACKFACING) ? 1.0f / eta : eta;
-
-      // calculate fresnel for refraction
-      float cosNO = dot(N, sd->I);
-      float fresnel = fresnel_dielectric_cos(cosNO, ior);
-
-      // calculate weights of the diffuse and specular part
-      float diffuse_weight = (1.0f - saturatef(metallic)) * (1.0f - saturatef(transmission));
-
-      float final_transmission = saturatef(transmission) * (1.0f - saturatef(metallic));
-      float specular_weight = (1.0f - final_transmission);
-
-      // get the base color
-      uint4 data_base_color = read_node(kg, &offset);
-      float3 base_color = stack_valid(data_base_color.x) ?
-                              stack_load_float3(stack, data_base_color.x) :
-                              make_float3(__uint_as_float(data_base_color.y),
-                                          __uint_as_float(data_base_color.z),
-                                          __uint_as_float(data_base_color.w));
-
-      // get the additional clearcoat normal and subsurface scattering radius
-      uint4 data_cn_ssr = read_node(kg, &offset);
-      float3 clearcoat_normal = stack_valid(data_cn_ssr.x) ?
-                                    stack_load_float3(stack, data_cn_ssr.x) :
-                                    sd->N;
-      if (!(sd->type & PRIMITIVE_CURVE)) {
-        clearcoat_normal = ensure_valid_reflection(sd->Ng, sd->I, clearcoat_normal);
-      }
-      float3 subsurface_radius = stack_valid(data_cn_ssr.y) ?
-                                     stack_load_float3(stack, data_cn_ssr.y) :
-                                     make_float3(1.0f, 1.0f, 1.0f);
-      float subsurface_ior = stack_valid(data_cn_ssr.z) ? stack_load_float(stack, data_cn_ssr.z) :
-                                                          1.4f;
-      float subsurface_anisotropy = stack_valid(data_cn_ssr.w) ?
-                                        stack_load_float(stack, data_cn_ssr.w) :
-                                        0.0f;
-
-      // get the subsurface color
-      uint4 data_subsurface_color = read_node(kg, &offset);
-      float3 subsurface_color = stack_valid(data_subsurface_color.x) ?
-                                    stack_load_float3(stack, data_subsurface_color.x) :
-                                    make_float3(__uint_as_float(data_subsurface_color.y),
-                                                __uint_as_float(data_subsurface_color.z),
-                                                __uint_as_float(data_subsurface_color.w));
-
-      float3 weight = sd->svm_closure_weight * mix_weight;
-
-#  ifdef __SUBSURFACE__
-      float3 mixed_ss_base_color = subsurface_color * subsurface +
-                                   base_color * (1.0f - subsurface);
-      float3 subsurf_weight = weight * mixed_ss_base_color * diffuse_weight;
-
-      /* disable in case of diffuse ancestor, can't see it well then and
-       * adds considerably noise due to probabilities of continuing path
-       * getting lower and lower */
-      if (path_flag & PATH_RAY_DIFFUSE_ANCESTOR) {
-        subsurface = 0.0f;
-
-        /* need to set the base color in this case such that the
-         * rays get the correctly mixed color after transmitting
-         * the object */
-        base_color = mixed_ss_base_color;
-      }
-
-      /* diffuse */
-      if (fabsf(average(mixed_ss_base_color)) > CLOSURE_WEIGHT_CUTOFF) {
-        if (subsurface <= CLOSURE_WEIGHT_CUTOFF && diffuse_weight > CLOSURE_WEIGHT_CUTOFF) {
-          float3 diff_weight = weight * base_color * diffuse_weight;
-
-          ccl_private PrincipledDiffuseBsdf *bsdf = (ccl_private PrincipledDiffuseBsdf *)
-              bsdf_alloc(sd, sizeof(PrincipledDiffuseBsdf), diff_weight);
-
-          if (bsdf) {
-            bsdf->N = N;
-            bsdf->roughness = roughness;
-
-            /* setup bsdf */
-            sd->flag |= bsdf_principled_diffuse_setup(bsdf, PRINCIPLED_DIFFUSE_FULL);
-          }
-        }
-        else if (subsurface > CLOSURE_WEIGHT_CUTOFF) {
-          ccl_private Bssrdf *bssrdf = bssrdf_alloc(sd, subsurf_weight);
-
-          if (bssrdf) {
-            bssrdf->radius = subsurface_radius * subsurface;
-            bssrdf->albedo = mixed_ss_base_color;
-            bssrdf->N = N;
-            bssrdf->roughness = roughness;
-
-            /* Clamps protecting against bad/extreme and non physical values. */
-            subsurface_ior = clamp(subsurface_ior, 1.01f, 3.8f);
-            bssrdf->anisotropy = clamp(subsurface_anisotropy, 0.0f, 0.9f);
-
-            /* setup bsdf */
-            sd->flag |= bssrdf_setup(sd, bssrdf, subsurface_method, subsurface_ior);
-          }
-        }
-      }
-#  else
-      /* diffuse */
-      if (diffuse_weight > CLOSURE_WEIGHT_CUTOFF) {
-        float3 diff_weight = weight * base_color * diffuse_weight;
-
-        ccl_private PrincipledDiffuseBsdf *bsdf = (ccl_private PrincipledDiffuseBsdf *)bsdf_alloc(
-            sd, sizeof(PrincipledDiffuseBsdf), diff_weight);
-
-        if (bsdf) {
-          bsdf->N = N;
-          bsdf->roughness = roughness;
-
-          /* setup bsdf */
-          sd->flag |= bsdf_principled_diffuse_setup(bsdf, PRINCIPLED_DIFFUSE_FULL);
-        }
-      }
-#  endif
-
-      /* sheen */
-      if (diffuse_weight > CLOSURE_WEIGHT_CUTOFF && sheen > CLOSURE_WEIGHT_CUTOFF) {
-        float m_cdlum = linear_rgb_to_gray(kg, base_color);
-        float3 m_ctint = m_cdlum > 0.0f ?
-                             base_color / m_cdlum :
-                             make_float3(1.0f, 1.0f, 1.0f);  // normalize lum. to isolate hue+sat
-
-        /* color of the sheen component */
-        float3 sheen_color = make_float3(1.0f, 1.0f, 1.0f) * (1.0f - sheen_tint) +
-                             m_ctint * sheen_tint;
-
-        float3 sheen_weight = weight * sheen * sheen_color * diffuse_weight;
-
-        ccl_private PrincipledSheenBsdf *bsdf = (ccl_private PrincipledSheenBsdf *)bsdf_alloc(
-            sd, sizeof(PrincipledSheenBsdf), sheen_weight);
-
-        if (bsdf) {
-          bsdf->N = N;
-
-          /* setup bsdf */
-          sd->flag |= bsdf_principled_sheen_setup(sd, bsdf);
-        }
-      }
-
-      /* specular reflection */
-#  ifdef __CAUSTICS_TRICKS__
-      if (kernel_data.integrator.caustics_reflective || (path_flag & PATH_RAY_DIFFUSE) == 0) {
-#  endif
-        if (specular_weight > CLOSURE_WEIGHT_CUTOFF &&
-            (specular > CLOSURE_WEIGHT_CUTOFF || metallic > CLOSURE_WEIGHT_CUTOFF)) {
-          float3 spec_weight = weight * specular_weight;
-
-          ccl_private MicrofacetBsdf *bsdf = (ccl_private MicrofacetBsdf *)bsdf_alloc(
-              sd, sizeof(MicrofacetBsdf), spec_weight);
-          ccl_private MicrofacetExtra *extra =
-              (bsdf != NULL) ?
-                  (ccl_private MicrofacetExtra *)closure_alloc_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list