From aa2e978bd8b47dbc06826698b07d850cdd499568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Fri, 18 Sep 2020 23:42:43 +0200 Subject: Fix T79557 EEVEE: Normalize in vector math node is not null vector safe This add basic null safe handling for this operation. --- .../gpu/shaders/material/gpu_shader_material_vector_math.glsl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'source/blender/gpu') 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) -- cgit v1.2.3