summaryrefslogtreecommitdiff
path: root/engine/light.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/light.glsl
parent67023d6a095f457a2579367d59d13c6c804e7108 (diff)
feat(engine): add basic flat lighting
Diffstat (limited to 'engine/light.glsl')
-rw-r--r--engine/light.glsl34
1 files changed, 34 insertions, 0 deletions
diff --git a/engine/light.glsl b/engine/light.glsl
new file mode 100644
index 0000000..3f1c601
--- /dev/null
+++ b/engine/light.glsl
@@ -0,0 +1,34 @@
+#version 330 core
+
+uniform vec3 light_color;
+uniform vec3 light_pos;
+
+uniform float ambient_light_strength;
+uniform float specular_light_strength;
+
+uniform uint specular_shininess;
+
+vec3 calc_diffuse_light(in vec3 light_dir, in vec3 norm)
+{
+ float diff = max(dot(norm, light_dir), 0.0);
+
+ return diff * light_color;
+}
+
+vec3 calc_specular_light(
+ in vec3 light_dir,
+ in vec3 norm,
+ in vec3 view_pos,
+ in vec3 frag_pos
+)
+{
+ vec3 view_direction = normalize(view_pos - frag_pos);
+
+ vec3 reflect_direction = reflect(-light_dir, norm);
+
+ float spec =
+ pow(max(dot(view_direction, reflect_direction), 0.0), specular_shininess);
+
+ return specular_light_strength * spec * light_color;
+}
+