Commit: 0665f58a57b54c874f9d944cb0fbf3422cb214b0
Author: Clément Foucault
Date:   Thu Aug 10 23:08:33 2017 +0200
Branches: blender2.8
https://developer.blender.org/rB0665f58a57b54c874f9d944cb0fbf3422cb214b0

Eevee: Fix NaN

This was surely cause by float overflow. Limit roughness in this case to limit 
the brdf intensity.
Also compute VH faster.

Add a sanitizer to the SSR pass for investigating where NANs come from. Play 
with the roughness until you see where the black pixel is / comes from.

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

M       source/blender/draw/engines/eevee/shaders/bsdf_direct_lib.glsl
M       source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl

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

diff --git a/source/blender/draw/engines/eevee/shaders/bsdf_direct_lib.glsl 
b/source/blender/draw/engines/eevee/shaders/bsdf_direct_lib.glsl
index 352cd60de3c..d0a365f5a3e 100644
--- a/source/blender/draw/engines/eevee/shaders/bsdf_direct_lib.glsl
+++ b/source/blender/draw/engines/eevee/shaders/bsdf_direct_lib.glsl
@@ -85,6 +85,7 @@ float direct_diffuse_unit_disc(vec3 N, vec3 L)
 /* ----------- GGx ------------ */
 vec3 direct_ggx_point(vec3 N, vec3 V, vec4 l_vector, float roughness, vec3 f0)
 {
+       roughness = max(1e-3, roughness);
        float dist = l_vector.w;
        vec3 L = l_vector.xyz / dist;
        float bsdf = bsdf_ggx(N, L, V, roughness);
@@ -97,8 +98,9 @@ vec3 direct_ggx_point(vec3 N, vec3 V, vec4 l_vector, float 
roughness, vec3 f0)
 
 vec3 direct_ggx_sun(LightData ld, vec3 N, vec3 V, float roughness, vec3 f0)
 {
+       roughness = max(1e-3, roughness);
        float bsdf = bsdf_ggx(N, -ld.l_forward, V, roughness);
-       float VH = max(dot(V, normalize(V - ld.l_forward)), 0.0);
+       float VH = dot(V, -ld.l_forward) * 0.5 + 0.5;
        return F_schlick(f0, VH) * bsdf;
 }
 
diff --git a/source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl 
b/source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl
index 68bcf8c06e4..267c52f0508 100644
--- a/source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl
+++ b/source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl
@@ -270,7 +270,7 @@ vec4 get_ssr_sample(
        mask = min(mask, screen_border_mask(ref_uvs));
        mask *= float(has_hit);
 
-       float hit_dist = length(hit_vec);
+       float hit_dist = max(1e-8, length(hit_vec));
        vec3 L = hit_vec / hit_dist;
 
        float cone_footprint = hit_dist * cone_tan;
@@ -306,6 +306,10 @@ vec4 get_ssr_sample(
        /* Do not add light if ray has failed. */
        sample *= float(has_hit);
 
+#if 0 /* Enable to see where NANs come from. */
+       sample = (any(isnan(sample))) ? vec3(0.0) : sample;
+#endif
+
        return vec4(sample, mask) * weight;
 }

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to