diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2021-03-13 19:06:07 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2021-03-13 22:59:20 +0300 |
commit | 09e77d2c89315ee3b7153e53d6990469b6759fa7 (patch) | |
tree | 1fcf4f53dfbb155b54e15430484a27f78a480ffe | |
parent | 165a2da753248384787ea3509a031d8867d4587e (diff) |
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.
-rw-r--r-- | source/blender/draw/engines/eevee/shaders/effect_subsurface_frag.glsl | 4 |
1 files changed, 3 insertions, 1 deletions
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)))) { |