summaryrefslogtreecommitdiff
path: root/engine/fragment-texture.glsl
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-11-12 22:38:52 +0100
committerHampusM <hampus@hampusmat.com>2023-11-12 22:57:19 +0100
commit8d821588cd4f51d4ae9c4ef52d45c0af0e1ce9e5 (patch)
treeed1b0dd30e801b9a70537b9806a445e4212978b3 /engine/fragment-texture.glsl
parent67023d6a095f457a2579367d59d13c6c804e7108 (diff)
feat(engine): add basic flat lighting
Diffstat (limited to 'engine/fragment-texture.glsl')
-rw-r--r--engine/fragment-texture.glsl22
1 files changed, 21 insertions, 1 deletions
diff --git a/engine/fragment-texture.glsl b/engine/fragment-texture.glsl
index a4d378b..2948a2e 100644
--- a/engine/fragment-texture.glsl
+++ b/engine/fragment-texture.glsl
@@ -1,11 +1,31 @@
#version 330 core
+
+#preinclude "light.glsl"
+
out vec4 FragColor;
in vec2 in_texture_coords;
+in vec3 in_frag_pos;
+in vec3 in_normal;
+
+uniform vec3 view_pos;
+
uniform sampler2D input_texture;
void main()
{
- FragColor = texture(input_texture, in_texture_coords);
+ vec3 ambient_light = ambient_light_strength * light_color;
+
+ vec3 light_direction = normalize(light_pos - in_frag_pos);
+ vec3 norm = normalize(in_normal);
+
+ vec3 diffuse_light = calc_diffuse_light(light_direction, norm);
+
+ vec3 specular_light =
+ calc_specular_light(light_direction, norm, view_pos, in_frag_pos);
+
+ vec4 light = vec4((ambient_light + diffuse_light + specular_light), 1.0);
+
+ FragColor = light * texture(input_texture, in_texture_coords);
}