From: Mikko Rasa Date: Wed, 9 Mar 2022 18:31:03 +0000 (+0200) Subject: Normalize vertex normal and tangent vectors in vertex shader X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=139924448ef4753b3942da07091a2630a037c034;p=libs%2Fgl.git Normalize vertex normal and tangent vectors in vertex shader If the normal matrix has scaling, that can throw things off. --- 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); }