[Bf-blender-cvs] [935f500501d] microfacet_hair: Reuse albedo functions in principled hair BSDF

Weizhen Huang noreply at git.blender.org
Mon Jan 16 16:50:19 CET 2023


Commit: 935f500501dbf004e89f5c86e1bbbf7a7927bf54
Author: Weizhen Huang
Date:   Mon Jan 16 16:49:52 2023 +0100
Branches: microfacet_hair
https://developer.blender.org/rB935f500501dbf004e89f5c86e1bbbf7a7927bf54

Reuse albedo functions in principled hair BSDF

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

M	intern/cycles/kernel/closure/bsdf_hair_microfacet.h
M	intern/cycles/kernel/closure/bsdf_hair_principled.h
M	intern/cycles/kernel/svm/closure.h

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

diff --git a/intern/cycles/kernel/closure/bsdf_hair_microfacet.h b/intern/cycles/kernel/closure/bsdf_hair_microfacet.h
index be3d7d7e105..25a0e3ca537 100644
--- a/intern/cycles/kernel/closure/bsdf_hair_microfacet.h
+++ b/intern/cycles/kernel/closure/bsdf_hair_microfacet.h
@@ -1397,32 +1397,10 @@ ccl_device void bsdf_microfacet_hair_blur(ccl_private ShaderClosure *sc, float r
 
 /* Hair Albedo */
 
-ccl_device_inline float bsdf_microfacet_hair_albedo_roughness_scale(
-    const float azimuthal_roughness)
-{
-  const float x = azimuthal_roughness;
-  return (((((0.245f * x) + 5.574f) * x - 10.73f) * x + 2.532f) * x - 0.215f) * x + 5.969f;
-}
-
 ccl_device float3 bsdf_microfacet_hair_albedo(ccl_private const ShaderClosure *sc)
 {
   ccl_private MicrofacetHairBSDF *bsdf = (ccl_private MicrofacetHairBSDF *)sc;
-  return exp(-sqrt(bsdf->sigma) * bsdf_microfacet_hair_albedo_roughness_scale(bsdf->roughness));
-}
-
-ccl_device_inline float3
-bsdf_microfacet_hair_sigma_from_reflectance(const float3 color, const float azimuthal_roughness)
-{
-  const float3 sigma = log(color) /
-                       bsdf_microfacet_hair_albedo_roughness_scale(azimuthal_roughness);
-  return sigma * sigma;
-}
-
-ccl_device_inline float3 bsdf_microfacet_hair_sigma_from_concentration(const float eumelanin,
-                                                                       const float pheomelanin)
-{
-  return eumelanin * make_float3(0.506f, 0.841f, 1.653f) +
-         pheomelanin * make_float3(0.343f, 0.733f, 1.924f);
+  return exp(-sqrt(bsdf->sigma) * bsdf_hair_albedo_roughness_scale(bsdf->roughness));
 }
 
 CCL_NAMESPACE_END
diff --git a/intern/cycles/kernel/closure/bsdf_hair_principled.h b/intern/cycles/kernel/closure/bsdf_hair_principled.h
index 5a6465c7af6..fbdf05a2790 100644
--- a/intern/cycles/kernel/closure/bsdf_hair_principled.h
+++ b/intern/cycles/kernel/closure/bsdf_hair_principled.h
@@ -473,10 +473,9 @@ ccl_device void bsdf_principled_hair_blur(ccl_private ShaderClosure *sc, float r
   bsdf->m0_roughness = fmaxf(roughness, bsdf->m0_roughness);
 }
 
-/* Hair Albedo */
+/* Hair Albedo. Also used by `bsdf_hair_microfacet.h` */
 
-ccl_device_inline float bsdf_principled_hair_albedo_roughness_scale(
-    const float azimuthal_roughness)
+ccl_device_inline float bsdf_hair_albedo_roughness_scale(const float azimuthal_roughness)
 {
   const float x = azimuthal_roughness;
   return (((((0.245f * x) + 5.574f) * x - 10.73f) * x + 2.532f) * x - 0.215f) * x + 5.969f;
@@ -485,19 +484,18 @@ ccl_device_inline float bsdf_principled_hair_albedo_roughness_scale(
 ccl_device Spectrum bsdf_principled_hair_albedo(ccl_private const ShaderClosure *sc)
 {
   ccl_private PrincipledHairBSDF *bsdf = (ccl_private PrincipledHairBSDF *)sc;
-  return exp(-sqrt(bsdf->sigma) * bsdf_principled_hair_albedo_roughness_scale(bsdf->v));
+  return exp(-sqrt(bsdf->sigma) * bsdf_hair_albedo_roughness_scale(bsdf->v));
 }
 
-ccl_device_inline Spectrum
-bsdf_principled_hair_sigma_from_reflectance(const Spectrum color, const float azimuthal_roughness)
+ccl_device_inline Spectrum bsdf_hair_sigma_from_reflectance(const Spectrum color,
+                                                            const float azimuthal_roughness)
 {
-  const Spectrum sigma = log(color) /
-                         bsdf_principled_hair_albedo_roughness_scale(azimuthal_roughness);
+  const Spectrum sigma = log(color) / bsdf_hair_albedo_roughness_scale(azimuthal_roughness);
   return sigma * sigma;
 }
 
-ccl_device_inline Spectrum bsdf_principled_hair_sigma_from_concentration(const float eumelanin,
-                                                                         const float pheomelanin)
+ccl_device_inline Spectrum bsdf_hair_sigma_from_concentration(const float eumelanin,
+                                                              const float pheomelanin)
 {
   const float3 eumelanin_color = make_float3(0.506f, 0.841f, 1.653f);
   const float3 pheomelanin_color = make_float3(0.343f, 0.733f, 1.924f);
diff --git a/intern/cycles/kernel/svm/closure.h b/intern/cycles/kernel/svm/closure.h
index 42abbbdd3a3..582f1595cba 100644
--- a/intern/cycles/kernel/svm/closure.h
+++ b/intern/cycles/kernel/svm/closure.h
@@ -850,27 +850,26 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
             /* Benedikt Bitterli's melanin ratio remapping. */
             float eumelanin = melanin * (1.0f - melanin_redness);
             float pheomelanin = melanin * melanin_redness;
-            Spectrum melanin_sigma = bsdf_principled_hair_sigma_from_concentration(eumelanin,
-                                                                                   pheomelanin);
+            Spectrum melanin_sigma = bsdf_hair_sigma_from_concentration(eumelanin, pheomelanin);
 
             /* Optional tint. */
             float3 tint = stack_load_float3(stack, tint_ofs);
-            Spectrum tint_sigma = bsdf_principled_hair_sigma_from_reflectance(
-                rgb_to_spectrum(tint), radial_roughness);
+            Spectrum tint_sigma = bsdf_hair_sigma_from_reflectance(rgb_to_spectrum(tint),
+                                                                   radial_roughness);
 
             bsdf->sigma = melanin_sigma + tint_sigma;
             break;
           }
           case NODE_PRINCIPLED_HAIR_REFLECTANCE: {
             float3 color = stack_load_float3(stack, color_ofs);
-            bsdf->sigma = bsdf_principled_hair_sigma_from_reflectance(rgb_to_spectrum(color),
-                                                                      radial_roughness);
+            bsdf->sigma = bsdf_hair_sigma_from_reflectance(rgb_to_spectrum(color),
+                                                           radial_roughness);
             break;
           }
           default: {
             /* Fallback to brownish hair, same as defaults for melanin. */
             kernel_assert(!"Invalid Principled Hair parametrization!");
-            bsdf->sigma = bsdf_principled_hair_sigma_from_concentration(0.0f, 0.8054375f);
+            bsdf->sigma = bsdf_hair_sigma_from_concentration(0.0f, 0.8054375f);
             break;
           }
         }
@@ -968,27 +967,25 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
             /* Benedikt Bitterli's melanin ratio remapping. */
             float eumelanin = melanin * (1.0f - melanin_redness);
             float pheomelanin = melanin * melanin_redness;
-            Spectrum melanin_sigma = bsdf_microfacet_hair_sigma_from_concentration(eumelanin,
-                                                                                   pheomelanin);
+            Spectrum melanin_sigma = bsdf_hair_sigma_from_concentration(eumelanin, pheomelanin);
 
             /* Optional tint. */
             float3 tint = stack_load_float3(stack, tint_ofs);
-            Spectrum tint_sigma = bsdf_microfacet_hair_sigma_from_reflectance(
-                rgb_to_spectrum(tint), roughness);
+            Spectrum tint_sigma = bsdf_hair_sigma_from_reflectance(rgb_to_spectrum(tint),
+                                                                   roughness);
 
             bsdf->sigma = melanin_sigma + tint_sigma;
             break;
           }
           case NODE_MICROFACET_HAIR_REFLECTANCE: {
             float3 color = stack_load_float3(stack, color_ofs);
-            bsdf->sigma = bsdf_microfacet_hair_sigma_from_reflectance(rgb_to_spectrum(color),
-                                                                      roughness);
+            bsdf->sigma = bsdf_hair_sigma_from_reflectance(rgb_to_spectrum(color), roughness);
             break;
           }
           default: {
             /* Fallback to brownish hair, same as defaults for melanin. */
             kernel_assert(!"Invalid Microfacet Hair parametrization!");
-            bsdf->sigma = bsdf_microfacet_hair_sigma_from_concentration(0.0f, 0.8054375f);
+            bsdf->sigma = bsdf_hair_sigma_from_concentration(0.0f, 0.8054375f);
             break;
           }
         }



More information about the Bf-blender-cvs mailing list