[Bf-blender-cvs] [b4c5db0a1a5] principled-v2: Add special handling for specular case in Glass closure

Lukas Stockner noreply at git.blender.org
Tue Jul 5 22:17:38 CEST 2022


Commit: b4c5db0a1a55ead78ec4188f5e496c6b0f8590e4
Author: Lukas Stockner
Date:   Tue Jul 5 22:09:24 2022 +0200
Branches: principled-v2
https://developer.blender.org/rBb4c5db0a1a55ead78ec4188f5e496c6b0f8590e4

Add special handling for specular case in Glass closure

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

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

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

diff --git a/intern/cycles/kernel/closure/bsdf_microfacet_glass.h b/intern/cycles/kernel/closure/bsdf_microfacet_glass.h
index 942812aaa71..121b9a2dd50 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet_glass.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet_glass.h
@@ -74,7 +74,13 @@ ccl_device float3 bsdf_microfacet_ggx_glass_eval_reflect(ccl_private const Shade
   ccl_private const MicrofacetBsdf *bsdf = (ccl_private const MicrofacetBsdf *)sc;
   float alpha_x = bsdf->alpha_x;
   float alpha_y = bsdf->alpha_y;
-  kernel_assert(alpha_x * alpha_y > 1e-7f);
+  float alpha2 = alpha_x * alpha_y;
+
+  if (alpha2 <= 1e-7f) {
+    *pdf = 0.0f;
+    return zero_float3();
+  }
+
   float3 N = bsdf->N;
 
   float cosNO = dot(N, I);
@@ -85,7 +91,6 @@ ccl_device float3 bsdf_microfacet_ggx_glass_eval_reflect(ccl_private const Shade
   }
 
   float3 m = normalize(omega_in + I);
-  float alpha2 = alpha_x * alpha_y;
   float D = microfacet_ggx_D(dot(N, m), alpha2);
   float lambdaO = microfacet_ggx_lambda(cosNO, alpha2);
   float lambdaI = microfacet_ggx_lambda(cosNI, alpha2);
@@ -111,10 +116,15 @@ ccl_device float3 bsdf_microfacet_ggx_glass_eval_transmit(ccl_private const Shad
   ccl_private const MicrofacetBsdf *bsdf = (ccl_private const MicrofacetBsdf *)sc;
   float alpha_x = bsdf->alpha_x;
   float alpha_y = bsdf->alpha_y;
-  kernel_assert(alpha_x * alpha_y > 1e-7f);
+  float alpha2 = alpha_x * alpha_y;
   float eta = bsdf->ior;
   float3 N = bsdf->N;
 
+  if (alpha2 <= 1e-7f) {
+    *pdf = 0.0f;
+    return zero_float3();
+  }
+
   float cosNO = dot(N, I);
   float cosNI = dot(N, omega_in);
   if (cosNO <= 0 || cosNI >= 0) {
@@ -134,7 +144,6 @@ ccl_device float3 bsdf_microfacet_ggx_glass_eval_transmit(ccl_private const Shad
     return zero_float3();
   }
 
-  float alpha2 = alpha_x * alpha_y;
   float D = microfacet_ggx_D(dot(N, m), alpha2);
   float lambdaO = microfacet_ggx_lambda(cosNO, alpha2);
   float lambdaI = microfacet_ggx_lambda(cosNI, alpha2);
@@ -168,7 +177,6 @@ ccl_device int bsdf_microfacet_ggx_glass_sample(ccl_private const ShaderClosure
   ccl_private const MicrofacetBsdf *bsdf = (ccl_private const MicrofacetBsdf *)sc;
   float alpha_x = bsdf->alpha_x;
   float alpha_y = bsdf->alpha_y;
-  kernel_assert(alpha_x * alpha_y > 1e-7f);
   float eta = bsdf->ior;
   float3 N = bsdf->N;
   int label;
@@ -220,8 +228,26 @@ ccl_device int bsdf_microfacet_ggx_glass_sample(ccl_private const ShaderClosure
   float randw = hash_float2_to_float(make_float2(randu, randv));
   bool do_reflect = randw < fresnel;
 
-  /* Common microfacet model terms. */
   float alpha2 = alpha_x * alpha_y;
+  if (alpha2 <= 1e-7f) {
+    /* Specular case, just return some high number for MIS */
+    *pdf = 1e6f;
+    *eval = make_float3(1e6f, 1e6f, 1e6f);
+
+    *omega_in = do_reflect ? R : T;
+#ifdef __RAY_DIFFERENTIALS__
+    *domega_in_dx = do_reflect ? dRdx : dTdx;
+    *domega_in_dy = do_reflect ? dRdy : dTdy;
+#endif
+
+    if (bsdf->type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID) {
+      *eval *= do_reflect ? reflection_color(bsdf, *omega_in, m) : bsdf->extra->color;
+    }
+
+    return LABEL_SINGULAR | (do_reflect ? LABEL_REFLECT : LABEL_TRANSMIT);
+  }
+
+  /* Common microfacet model terms. */
   float D = microfacet_ggx_D(cosThetaM, alpha2);
   float lambdaO = microfacet_ggx_lambda(cosNO, alpha2);
 
@@ -269,7 +295,7 @@ ccl_device int bsdf_microfacet_ggx_glass_sample(ccl_private const ShaderClosure
   *eval = make_float3(out, out, out);
 
   if (bsdf->type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID) {
-    *eval *= (label & LABEL_REFLECT) ? reflection_color(bsdf, *omega_in, m) : bsdf->extra->color;
+    *eval *= do_reflect ? reflection_color(bsdf, *omega_in, m) : bsdf->extra->color;
   }
   return label;
 }



More information about the Bf-blender-cvs mailing list