Fix diffuse lighting

This commit is contained in:
Dane Johnson 2021-01-21 15:35:21 -06:00
parent 8fb29d389a
commit 96f1e23a54
2 changed files with 7 additions and 3 deletions

View File

@ -39,7 +39,11 @@ void main() {
if (!material.unshaded) {
vec3 ambient = directionalLight.ambient * directionalLight.color;
vec3 diffuse = directionalLight.diffuse * reflect(directionalLight.direction, NORMAL) * directionalLight.color;
FragColor *= vec4(ambient, 1.0);
ambient = max(ambient, 0.0);
vec3 diffuse = directionalLight.diffuse * dot(directionalLight.direction, NORMAL) * directionalLight.color;
diffuse = max(diffuse, 0.0);
FragColor *= vec4(ambient + diffuse, 1.0);
}
}

View File

@ -15,5 +15,5 @@ void main() {
vec4 vertex = PROJECTION * VIEW * MODEL * vec4(pos, 1.0);
gl_Position = vertex;
UV = vec3(uv * vertex.z, vertex.z);
NORMAL = normal;
NORMAL = (PROJECTION * VIEW * MODEL * vec4(normal, 0.0)).xyz;
}