[Bf-blender-cvs] [51012a109aa] principled-v2: Replace lerp with mix to make it compile for GPU

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


Commit: 51012a109aa8a40510c7c457d903004b43e98b1c
Author: Lukas Stockner
Date:   Mon Jul 4 23:31:48 2022 +0200
Branches: principled-v2
https://developer.blender.org/rB51012a109aa8a40510c7c457d903004b43e98b1c

Replace lerp with mix to make it compile for GPU

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

M	intern/cycles/app/cycles_precompute.cpp
M	intern/cycles/kernel/closure/bsdf_microfacet.h
M	intern/cycles/kernel/closure/bsdf_microfacet_util.h
M	intern/cycles/kernel/closure/bsdf_principled_sheen.h
M	intern/cycles/kernel/closure/bsdf_util.h
M	intern/cycles/kernel/svm/closure_principled.h

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

diff --git a/intern/cycles/app/cycles_precompute.cpp b/intern/cycles/app/cycles_precompute.cpp
index 6c744d952e0..c0f3d732c22 100644
--- a/intern/cycles/app/cycles_precompute.cpp
+++ b/intern/cycles/app/cycles_precompute.cpp
@@ -217,7 +217,7 @@ static float precompute_ggx_dielectric_E(float rough, float mu, float eta, float
      */
     float F0 = fresnel_dielectric_cos(1.0f, eta);
     auto get_remap = [eta, F0](float x) {
-      return lerp(x, inverse_lerp(1.0f, F0, fresnel_dielectric_cos(x, eta)), 0.5f);
+      return mix(x, inverse_lerp(1.0f, F0, fresnel_dielectric_cos(x, eta)), 0.5f);
     };
 
     float remap_target = mu;
diff --git a/intern/cycles/kernel/closure/bsdf_microfacet.h b/intern/cycles/kernel/closure/bsdf_microfacet.h
index 6168eab8f98..e31b0d6ea89 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet.h
@@ -67,7 +67,7 @@ ccl_device_forceinline float3 reflection_color(ccl_private const MicrofacetBsdf
      * as well as falloff control. F90=white and falloff=0.2 gives classic Schlick Fresnel.
      * Metallic factor and albedo scaling is baked into the F0 and F90 parameters. */
     float metallicBlend = powf(1.0f - cosHL, extra->metal_falloff);
-    float3 metallic = lerp(extra->metal_base, extra->metal_edge, metallicBlend);
+    float3 metallic = mix(extra->metal_base, extra->metal_edge, metallicBlend);
     /* Dielectric Fresnel, just basic IOR control. */
     float dielectric = extra->dielectric * fresnel_dielectric_cos(cosHL, bsdf->ior);
 
diff --git a/intern/cycles/kernel/closure/bsdf_microfacet_util.h b/intern/cycles/kernel/closure/bsdf_microfacet_util.h
index 3ae68e09f24..55503772c2d 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet_util.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet_util.h
@@ -86,7 +86,7 @@ ccl_device_forceinline float microfacet_table_1D(const float *table, float x, in
   x = saturatef(x - (0.5f / size)) * size;
   int i = min(size - 1, (int)x);
   int i1 = min(size - 1, i + 1);
-  return lerp(table[i], table[i1], x - i);
+  return mix(table[i], table[i1], x - i);
 }
 
 ccl_device_forceinline float microfacet_table_2D(
@@ -95,9 +95,9 @@ ccl_device_forceinline float microfacet_table_2D(
   y = saturatef(y - (0.5f / ysize)) * ysize;
   int i = min(ysize - 1, (int)y);
   int i1 = min(ysize - 1, i + 1);
-  return lerp(microfacet_table_1D(table + xsize * i, x, xsize),
-              microfacet_table_1D(table + xsize * i1, x, xsize),
-              y - i);
+  return mix(microfacet_table_1D(table + xsize * i, x, xsize),
+             microfacet_table_1D(table + xsize * i1, x, xsize),
+             y - i);
 }
 
 ccl_device_forceinline float microfacet_table_3D(
@@ -106,9 +106,9 @@ ccl_device_forceinline float microfacet_table_3D(
   z = saturatef(z - (0.5f / zsize)) * zsize;
   int i = min(zsize - 1, (int)z);
   int i1 = min(zsize - 1, i + 1);
-  return lerp(microfacet_table_2D(table + xsize * ysize * i, x, y, xsize, ysize),
-              microfacet_table_2D(table + xsize * ysize * i1, x, y, xsize, ysize),
-              z - i);
+  return mix(microfacet_table_2D(table + xsize * ysize * i, x, y, xsize, ysize),
+             microfacet_table_2D(table + xsize * ysize * i1, x, y, xsize, ysize),
+             z - i);
 }
 
 ccl_device_forceinline float microfacet_ggx_glass_E(float mu, float rough, float ior)
@@ -133,7 +133,7 @@ ccl_device_forceinline float microfacet_ggx_dielectric_E(float mu, float rough,
 
   float macro_fresnel = fresnel_dielectric_cos(mu, ior);
   float F0 = fresnel_dielectric_cos(1.0f, ior);
-  float x = lerp(mu, inverse_lerp(1.0f, F0, macro_fresnel), 0.5f);
+  float x = mix(mu, inverse_lerp(1.0f, F0, macro_fresnel), 0.5f);
   float y = 1 - rough;
   float z = sqrtf(0.5f * (ior - 1.0f));
 
@@ -158,8 +158,8 @@ ccl_device_forceinline float clearcoat_E(float mu, float rough)
 
 ccl_device_inline float3 metallic_Fss(float3 F0, float3 F90, float falloff)
 {
-  /* Fss for lerp(F0, F90, (1-cosNI)^falloff) */
-  return lerp(F0, F90, 2.0f / (sqr(falloff) + 3 * falloff + 2));
+  /* Fss for mix(F0, F90, (1-cosNI)^falloff) */
+  return mix(F0, F90, 2.0f / (sqr(falloff) + 3 * falloff + 2));
 }
 
 ccl_device_inline float3 schlick_fresnel_Fss(float3 F0)
diff --git a/intern/cycles/kernel/closure/bsdf_principled_sheen.h b/intern/cycles/kernel/closure/bsdf_principled_sheen.h
index 250f591f650..1d2cbb5f16a 100644
--- a/intern/cycles/kernel/closure/bsdf_principled_sheen.h
+++ b/intern/cycles/kernel/closure/bsdf_principled_sheen.h
@@ -56,11 +56,11 @@ calculate_principled_sheen_brdf(float3 N, float3 V, float3 L, float3 H, ccl_priv
  */
 ccl_device_inline float sheen_v2_lambda(float mu, float w)
 {
-  float a = lerp(11.9095f, 13.7000f, w);
-  float b = lerp(4.68753f, 2.92754f, w);
-  float c = lerp(0.33467f, 0.28670f, w);
-  float d = lerp(-2.22664f, -0.81757f, w);
-  float e = lerp(-1.76591f, -1.22466f, w);
+  float a = mix(11.9095f, 13.7000f, w);
+  float b = mix(4.68753f, 2.92754f, w);
+  float c = mix(0.33467f, 0.28670f, w);
+  float d = mix(-2.22664f, -0.81757f, w);
+  float e = mix(-1.76591f, -1.22466f, w);
 
   float exponent;
   if (mu < 0.5f) {
@@ -116,9 +116,9 @@ ccl_device_forceinline float sheen_v2_E(float mu, float rough)
   rough -= rough_i;
   mu -= mu_i;
 
-  float a = lerp(table_sheen_E[rough_i][mu_i], table_sheen_E[rough_i][mu_i1], mu);
-  float b = lerp(table_sheen_E[rough_i1][mu_i], table_sheen_E[rough_i1][mu_i1], mu);
-  return saturatef(lerp(a, b, rough));
+  float a = mix(table_sheen_E[rough_i][mu_i], table_sheen_E[rough_i][mu_i1], mu);
+  float b = mix(table_sheen_E[rough_i1][mu_i], table_sheen_E[rough_i1][mu_i1], mu);
+  return saturatef(mix(a, b, rough));
 }
 
 ccl_device int bsdf_principled_sheen_setup(ccl_private const ShaderData *sd,
diff --git a/intern/cycles/kernel/closure/bsdf_util.h b/intern/cycles/kernel/closure/bsdf_util.h
index a1541a01cd5..6468f5cd78c 100644
--- a/intern/cycles/kernel/closure/bsdf_util.h
+++ b/intern/cycles/kernel/closure/bsdf_util.h
@@ -114,12 +114,12 @@ ccl_device_forceinline float3
 interpolate_fresnel_color(float3 L, float3 H, float ior, float3 F0)
 {
   /* Compute the real Fresnel term and remap it from real_F0...1 to F0...1.
-   * We could also just use actual Schlick fresnel (lerp(F0, 1, (1-cosI)^5)) here. */
+   * We could also just use actual Schlick fresnel (mix(F0, 1, (1-cosI)^5)) here. */
   float real_F0 = fresnel_dielectric_cos(1.0f, ior);
   float F0_norm = 1.0f / (1.0f - real_F0);
   float FH = (fresnel_dielectric_cos(dot(L, H), ior) - real_F0) * F0_norm;
 
-  return lerp(F0, one_float3(), FH);
+  return mix(F0, one_float3(), FH);
 }
 
 ccl_device float3 ensure_valid_reflection(float3 Ng, float3 I, float3 N)
diff --git a/intern/cycles/kernel/svm/closure_principled.h b/intern/cycles/kernel/svm/closure_principled.h
index b84003af383..2d5dbaac22f 100644
--- a/intern/cycles/kernel/svm/closure_principled.h
+++ b/intern/cycles/kernel/svm/closure_principled.h
@@ -55,7 +55,7 @@ ccl_device_inline void principled_v1_diffuse_sss(ccl_private ShaderData *sd,
   float3 subsurface_color = stack_load_float3(stack, color_offset);
   float3 subsurface_radius = stack_load_float3(stack, radius_offset);
 
-  float3 mixed_ss_base_color = lerp(base_color, subsurface_color, subsurface);
+  float3 mixed_ss_base_color = mix(base_color, subsurface_color, subsurface);
 
   /* disable in case of diffuse ancestor, can't see it well then and
    * adds considerably noise due to probabilities of continuing path
@@ -157,9 +157,9 @@ ccl_device_inline void principled_v1_specular(KernelGlobals kg,
   // normalize lum. to isolate hue+sat
   float m_cdlum = linear_rgb_to_gray(kg, base_color);
   float3 m_ctint = m_cdlum > 0.0f ? base_color / m_cdlum : one_float3();
-  float3 specular_color = lerp(one_float3(), m_ctint, specular_tint);
+  float3 specular_color = mix(one_float3(), m_ctint, specular_tint);
 
-  bsdf->extra->cspec0 = lerp(specular * 0.08f * specular_color, base_color, metallic);
+  bsdf->extra->cspec0 = mix(specular * 0.08f * specular_color, base_color, metallic);
   bsdf->extra->color = base_color;
 
   /* setup bsdf */
@@ -203,7 +203,7 @@ ccl_device_inline void principled_v1_glass_refl(ccl_private ShaderData *sd,
   bsdf->ior = ior;
 
   bsdf->extra->color = base_color;
-  bsdf->extra->cspec0 = lerp(one_float3(), base_color, specular_tint);
+  bsdf->extra->cspec0 = mix(one_float3(), base_color, specular_tint);
 
   /* setup bsdf */
   sd->flag |= bsdf_microfacet_ggx_fresnel_setup(bsdf, sd);
@@ -338,7 +338,7 @@ ccl_device_inline void principled_v1_glass_multi(KernelGlobals kg,
   bsdf->ior = (sd->flag & SD_BACKFACING) ? 1.0f / eta : eta;
 
   bsdf->extra->color = base_color;
-  bsdf->extra->cspec0 = lerp(one_float3(), base_color, specular_tint);
+  bsdf->extra->cspec0 = mix(one_float3(), base_color, specular_tint);
 
   /* setup bsdf */
   sd->flag |= bsdf_microfacet_multi_ggx_glass_fresnel_setup(bsdf, sd);
@@ -368,7 +368,7 @@ ccl_device_inline void principled_v1_sheen(KernelGlobals kg,
 
   /* color of the sheen component */
   float sheen_tint = stack_load_float(stack, sheen_tint_offset);
-  float3 sheen_color = lerp(one_float3(), m_ctint, sheen_tint);
+  float3 sheen_color = mix(one_float3(), m_ctint, sheen_tint);
 
   ccl_private PrincipledSheenBsdf *bsdf = (ccl_private PrincipledSheenBsdf *)bsdf_alloc(
       sd, sizeof(PrincipledSheenBsdf), sheen_weight * sheen_color * weight);
@@ -532,7 +532,7 @@ ccl_device_inline float3 principled_v2_clearcoat(KernelGlobals kg,
      * the cosNI of the exit bounce will be much higher on average, so the tint would be
      * less extreme.
      * TODO: Maybe account for this by setting
-     * OD := 0.5*OD + 0.5*lerp(1.59, OD, metallic * (1 - roughness)),
+     * OD := 0.5*OD + 0.5*mix(1.59, OD, metallic * (1 - roughness)),
      * where 1.59 is the closest numerical fit for average optical depth on lambertian reflectors.
      * That way, mirrors preserve their look, but diffuse-ish objects have a more natural behavior.
      */



More information about the Bf-blender-cvs mailing list