From 139924448ef4753b3942da07091a2630a037c034 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 9 Mar 2022 20:31:03 +0200 Subject: [PATCH] Normalize vertex normal and tangent vectors in vertex shader If the normal matrix has scaling, that can throw things off. --- shaderlib/common.glsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shaderlib/common.glsl b/shaderlib/common.glsl index 35d5a87e..7a57b067 100644 --- a/shaderlib/common.glsl +++ b/shaderlib/common.glsl @@ -42,11 +42,11 @@ void standard_transform() vec4 eye_vertex = eye_world_matrix*world_vertex; gl_Position = clip_eye_matrix*eye_vertex; - out vec3 world_normal = normal_tf*get_vertex_normal(); + out vec3 world_normal = normalize(normal_tf*get_vertex_normal()); if(use_normal_map) { - vec3 world_tangent = normal_tf*tangent; - vec3 world_binormal = cross(world_normal, world_tangent); + vec3 world_tangent = normalize(normal_tf*tangent); + vec3 world_binormal = normalize(cross(world_normal, world_tangent)); out mat3 world_tbn_matrix = mat3(world_tangent, world_binormal, world_normal); } -- 2.45.2