]> git.tdb.fi Git - libs/gl.git/commitdiff
Normalize vertex normal and tangent vectors in vertex shader
authorMikko Rasa <tdb@tdb.fi>
Wed, 9 Mar 2022 18:31:03 +0000 (20:31 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 9 Mar 2022 18:31:03 +0000 (20:31 +0200)
If the normal matrix has scaling, that can throw things off.

shaderlib/common.glsl

index 35d5a87eafb8bf8c83e8fe877cdf5e90b0a3d724..7a57b0671eebf1a3b4850cb451785c66a52498ff 100644 (file)
@@ -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);
        }