From deec629ef4b6d13f2f1cb72fc702682b8db33ad5 Mon Sep 17 00:00:00 2001 From: Dane Johnson Date: Fri, 22 Jan 2021 14:40:45 -0600 Subject: [PATCH] Vertex exports all lights independently --- shaders/flat.frag | 7 +++++-- shaders/flat.vert | 13 +++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/shaders/flat.frag b/shaders/flat.frag index 8aed153..ef55898 100644 --- a/shaders/flat.frag +++ b/shaders/flat.frag @@ -2,7 +2,10 @@ noperspective in vec2 UV; in vec3 NORMAL; -flat in vec3 LIGHT; + +flat in vec3 AMBIENT; +flat in vec3 DIFFUSE; +flat in vec3 SPECULAR; out vec4 FragColor; @@ -30,6 +33,6 @@ void main() { } if (!material.unshaded) { - FragColor *= vec4(LIGHT, 1.0); + FragColor *= vec4(AMBIENT + DIFFUSE + SPECULAR, 1.0); } } diff --git a/shaders/flat.vert b/shaders/flat.vert index 8e1176f..45112e7 100644 --- a/shaders/flat.vert +++ b/shaders/flat.vert @@ -10,7 +10,10 @@ uniform mat4 PROJECTION; noperspective out vec2 UV; // PSX use affine texture mapping out vec3 NORMAL; -flat out vec3 LIGHT; + +flat out vec3 AMBIENT; +flat out vec3 DIFFUSE; +flat out vec3 SPECULAR; struct DirectionalLight { vec3 direction; @@ -31,19 +34,17 @@ void main() { NORMAL = (VIEW * MODEL * vec4(normal, 0.0)).xyz; // Flat shading, we compute light per vertex - vec3 ambient = directionalLight.ambient * directionalLight.color; + AMBIENT = directionalLight.ambient * directionalLight.color; vec3 direction = -(VIEW * vec4(directionalLight.direction, 0.0)).xyz; float diff = dot(normalize(direction), normalize(NORMAL)); diff = max(diff, 0.0); - vec3 diffuse = directionalLight.diffuse * diff * directionalLight.color; + DIFFUSE = directionalLight.diffuse * diff * directionalLight.color; vec3 viewDir = (VIEW * MODEL * vec4(pos, 1.0)).xyz; vec3 reflectionDir = reflect(normalize(direction), normalize(NORMAL)); float spec = dot(viewDir, reflectionDir); spec = max(spec, 0.0); spec = pow(spec, 2); - vec3 specular = directionalLight.specular * spec * directionalLight.color; - - LIGHT = ambient + diffuse + specular; + SPECULAR = directionalLight.specular * spec * directionalLight.color; }