diff options
Diffstat (limited to 'source')
-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) |