[Bf-blender-cvs] [5a230fccc58] principled-v2: Fix NaNs with thin film on glass

Lukas Stockner noreply at git.blender.org
Sun Oct 30 16:35:30 CET 2022


Commit: 5a230fccc588be922246b6920d8b4aaea1de0e19
Author: Lukas Stockner
Date:   Sun Oct 30 14:50:00 2022 +0100
Branches: principled-v2
https://developer.blender.org/rB5a230fccc588be922246b6920d8b4aaea1de0e19

Fix NaNs with thin film on glass

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

M	intern/cycles/kernel/closure/bsdf_microfacet_glass.h
M	intern/cycles/kernel/closure/bsdf_microfacet_util.h

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

diff --git a/intern/cycles/kernel/closure/bsdf_microfacet_glass.h b/intern/cycles/kernel/closure/bsdf_microfacet_glass.h
index 68688ffa922..c6ab2e385e0 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet_glass.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet_glass.h
@@ -138,6 +138,14 @@ ccl_device Spectrum bsdf_microfacet_ggx_glass_eval_transmit(ccl_private const Mi
   float cosMO = dot(m, I);
   float cosMI = dot(m, omega_in);
 
+  kernel_assert(dot(m, N) >= 0.0f);  // TODO: Is this assert to aggressive?
+  /* Avoid backfacing microfacets.
+   * TODO: Also check this in sample? */
+  if (cosMO < 0.0f || cosMI > 0.0f) {
+    *pdf = 0.0f;
+    return zero_spectrum();
+  }
+
   float reflect_pdf;
   Spectrum F = glass_fresnel(bsdf, cosMO, &reflect_pdf);
 
diff --git a/intern/cycles/kernel/closure/bsdf_microfacet_util.h b/intern/cycles/kernel/closure/bsdf_microfacet_util.h
index 733084a3228..4a41155b3f7 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet_util.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet_util.h
@@ -231,12 +231,14 @@ ccl_device_inline float3 fresnel_dielectric_thin_film(float cosThetaOuter,
     I += Cm.x * SmSh + Cm.y * SmPh;
   }
 
+  kernel_assert(isfinite_safe(I));
+
   /* CIE XYZ -> sRGB incl. whitepoint adaption E -> D65
    * TODO: Somehow properly handle color management here?
    * Does OCIO have anything for handling reflectances? */
-  return make_float3(3.17482107f, -0.98993255f, 0.06047909f) * I.x +
-         make_float3(-1.69745555f, 1.94998695f, -0.20891802f) * I.y +
-         make_float3(-0.47752224f, 0.04004475f, 1.14851336f) * I.z;
+  return saturate(make_float3(3.17482107f, -0.98993255f, 0.06047909f) * I.x +
+                  make_float3(-1.69745555f, 1.94998695f, -0.20891802f) * I.y +
+                  make_float3(-0.47752224f, 0.04004475f, 1.14851336f) * I.z);
 }
 
 CCL_NAMESPACE_END



More information about the Bf-blender-cvs mailing list