diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2020-09-19 00:42:43 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2020-09-19 00:42:51 +0300 |
commit | aa2e978bd8b47dbc06826698b07d850cdd499568 (patch) | |
tree | 870f9da5edf33ee093eccb91af3017f0e6932b0b /source/blender/gpu/shaders/material | |
parent | a0a536bbffaa866a504f5faa42d8605bf557729a (diff) |
Fix T79557 EEVEE: Normalize in vector math node is not null vector safe
This add basic null safe handling for this operation.
Diffstat (limited to 'source/blender/gpu/shaders/material')
-rw-r--r-- | source/blender/gpu/shaders/material/gpu_shader_material_vector_math.glsl | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_vector_math.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_vector_math.glsl index 256fdcafe3c..0b65fdb229a 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_vector_math.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_vector_math.glsl @@ -64,7 +64,12 @@ void vector_math_scale(vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, void vector_math_normalize( vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue) { - outVector = normalize(a); + outVector = a; + /* Safe version of normalize(a). */ + float lenSquared = dot(a, a); + if (lenSquared > 0.0) { + outVector *= inversesqrt(lenSquared); + } } void vector_math_snap(vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue) |