From 4d1d2ed477d2b2178a3718202afb17618ba6c5c0 Mon Sep 17 00:00:00 2001 From: Cat Flynn Date: Sun, 29 Sep 2024 00:11:12 +0100 Subject: [PATCH] feat: move light dir independently from camera --- frag_lit.glsl | 3 ++- vert.glsl | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/frag_lit.glsl b/frag_lit.glsl index 728ea2c..87e5157 100644 --- a/frag_lit.glsl +++ b/frag_lit.glsl @@ -2,6 +2,7 @@ in vec3 Normal; in vec3 FragPos; +in mat4x4 ModelViewProjection; out vec4 FragColor; @@ -17,7 +18,7 @@ void main() // Directional lighting vec3 directionalLightColor = vec3(1.0, 1.0, 1.0); - vec3 lightPos = vec3(10.0, 7.0, -8.0); + vec3 lightPos = (ModelViewProjection * vec4(6.0, -7.0, 8.0, 1.0)).xyz; vec3 normal = normalize(Normal); vec3 lightDir = normalize(lightPos - FragPos); float diff = max(dot(normal, lightDir), 0.0); diff --git a/vert.glsl b/vert.glsl index 95c6193..1007044 100644 --- a/vert.glsl +++ b/vert.glsl @@ -9,11 +9,13 @@ uniform mat4x4 _Projection; out vec3 Normal; out vec3 FragPos; +out mat4x4 ModelViewProjection; void main() { vec4 pos = vec4(aPos, 1.0); mat4x4 mvp = _Projection * _View * _Model; + ModelViewProjection = mvp; gl_Position = mvp * pos; FragPos = vec3(_Model * pos);