]> git.lizzy.rs Git - dragonblocks_alpha.git/blobdiff - shaders/3d/entity/vertex.glsl
Add items
[dragonblocks_alpha.git] / shaders / 3d / entity / vertex.glsl
index ca8684a22e34671ebd93e5c1e22f20b38cd30fef..a53f950549202299b36aa88050621e5e644ef104 100755 (executable)
@@ -2,7 +2,6 @@ layout(location = 0) in vec3 vertexPosition;
 layout(location = 1) in vec3 vertexNormal;
 
 out vec3 fragmentPosition;
-out vec3 fragmentNormal;
 out vec3 fragmentTextureCoordinates;
 out float fragmentLight;
 
@@ -18,9 +17,9 @@ void main()
        gl_Position = VP * worldSpace;
 
        fragmentPosition = worldSpace.xyz;
-       fragmentNormal = vertexNormal;
        fragmentTextureCoordinates = vertexPosition;
 
-       float diffuseLight = 0.3 * daylight * clamp(dot(normalize(fragmentNormal), normalize(lightDir)), 0.0, 1.0);
-       fragmentLight = ambientLight + diffuseLight;
+       mat3 normalMatrix = transpose(inverse(mat3(model)));
+       vec3 normal = normalize(normalMatrix * vertexNormal);
+       fragmentLight = ambientLight + 0.3 * daylight * clamp(dot(normal, normalize(lightDir)), 0.0, 1.0);
 }