layout(location = 1) in vec3 vertexNormal;
out vec3 fragmentPosition;
-out vec3 fragmentNormal;
out vec3 fragmentTextureCoordinates;
out float fragmentLight;
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);
}