summaryrefslogtreecommitdiff
path: root/resources/shader.frag
diff options
context:
space:
mode:
author0undefined <oscar@nelin.dk>2025-11-10 23:17:37 +0000
committer0undefined <oscar@nelin.dk>2025-11-10 23:17:37 +0000
commitb92c9d17efff6340dad64bd920900a130166ae11 (patch)
treeaa1642d1e7def80d09fb8c525ab9f4f0bc7fbaf2 /resources/shader.frag
parent84c4c6466aaf15f16e0cb9f0470c93720805c355 (diff)
Add some lighting
Ambient & Diffuse, shadowmapping et. al. TBD
Diffstat (limited to 'resources/shader.frag')
-rw-r--r--resources/shader.frag17
1 files changed, 16 insertions, 1 deletions
diff --git a/resources/shader.frag b/resources/shader.frag
index f81277d..0b81464 100644
--- a/resources/shader.frag
+++ b/resources/shader.frag
@@ -2,10 +2,25 @@
// Ouput data
in vec2 UV;
+in vec3 FragmentPos;
+in vec3 Normal;
out vec3 color;
uniform sampler2D textureSampler;
void main() {
- color = texture(textureSampler, UV).rgb;
+ vec3 light_color_ambient = vec3(0.4, 0.6, 0.9);
+ vec3 light_color_diffuse = vec3(0.8, 1.0, 1.0);
+
+ vec3 lightpos = vec3(16, 26, 32);
+
+ float ambient_strength = 0.3;
+ vec3 ambient = ambient_strength * light_color_ambient;
+
+ vec3 norm = normalize(Normal);
+ vec3 light_dir = normalize(lightpos - FragmentPos);
+
+ float diff = max(dot(norm, light_dir), 0.0);
+ vec3 diffuse = diff * light_color_diffuse;
+ color = (ambient + diffuse) * texture(textureSampler, UV).rgb;
}