From 09e77d2c89315ee3b7153e53d6990469b6759fa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Sat, 13 Mar 2021 17:06:07 +0100 Subject: Fix T86476 EEVEE: SSS material with variable radius can produce NaNs Simple divide by 0 error. The input radius was assumed to be safe but is not when the user can scale it arbitrarly. This also move the division out of the loop. --- source/blender/draw/engines/eevee/shaders/effect_subsurface_frag.glsl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source/blender/draw') diff --git a/source/blender/draw/engines/eevee/shaders/effect_subsurface_frag.glsl b/source/blender/draw/engines/eevee/shaders/effect_subsurface_frag.glsl index 1964adf3059..b79cd17c567 100644 --- a/source/blender/draw/engines/eevee/shaders/effect_subsurface_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/effect_subsurface_frag.glsl @@ -45,6 +45,8 @@ void main(void) vec2 scale = vec2(ProjectionMatrix[0][0], ProjectionMatrix[1][1]) * sss_radius / homcoord; vec2 finalStep = scale * 0.5; /* samples range -1..1 */ + float sss_radius_inv = 1.0 / max(1e-8, sss_radius); + /* Center sample */ vec3 accum = sss_irradiance * kernel[0].rgb; @@ -58,7 +60,7 @@ void main(void) * by Jimenez, eqs. 2 and 9, and D9740. * Coefficient -2 follows from gaussian_profile() from gpu_material.c and * from the definition of finalStep. */ - float depth_delta = (depth_view - sample_depth) / sss_radius; + float depth_delta = (depth_view - sample_depth) * sss_radius_inv; float s = exp(-2.0 * sqr(depth_delta)); /* Out of view samples. */ if (any(lessThan(sample_uv, vec2(0.0))) || any(greaterThan(sample_uv, vec2(1.0)))) { -- cgit v1.2.3