summary refs log tree commit diff
path: root/res
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--res/shaders/colors.fs12
-rw-r--r--res/shaders/colors.vs2
2 files changed, 12 insertions, 2 deletions
diff --git a/res/shaders/colors.fs b/res/shaders/colors.fs
index d434370..2184d03 100644
--- a/res/shaders/colors.fs
+++ b/res/shaders/colors.fs
@@ -8,17 +8,27 @@ in vec3 FragPos;
 uniform vec3 object_color;
 uniform vec3 light_color;
 uniform vec3 light_position;
+uniform vec3 view_position;
 
 void main() {
+  // ambient
   float ambient_stength = 0.1;
   vec3 ambient = ambient_stength * light_color;
 
+  // diffuse
   vec3 norm = normalize(Normal);
   vec3 light_dir = normalize(light_position - FragPos);
   float diff = max(dot(norm, light_dir), 0.0);
   vec3 diffuse = diff * light_color;
+
+  // specular
+  float specular_strength = 0.5;
+  vec3 view_dir = normalize(view_position - FragPos);
+  vec3 reflect_dir = reflect(-light_dir, norm);
+  float spec = pow(max(dot(view_dir, reflect_dir), 0.0), 32);
+  vec3 specular = specular_strength * spec * light_color;
   
-  vec3 result = (ambient + diffuse) * object_color;
+  vec3 result = (ambient + diffuse + specular) * object_color;
   FragColor = vec4(result, 1.0);
 }
 
diff --git a/res/shaders/colors.vs b/res/shaders/colors.vs
index 323b2ad..15cc265 100644
--- a/res/shaders/colors.vs
+++ b/res/shaders/colors.vs
@@ -12,7 +12,7 @@ out vec3 FragPos;
 
 void main() {
   FragPos = vec3(model * vec4(a_pos, 1.0));
-  Normal = a_normal;  
+  Normal = mat3(transpose(inverse(model))) * a_normal;
 
   gl_Position = projection * view  * vec4(FragPos, 1.0);
 }