summary refs log tree commit diff
path: root/res
diff options
context:
space:
mode:
authoriurii <[email protected]>2024-08-31 21:27:54 +0200
committeriurii <[email protected]>2024-08-31 21:27:54 +0200
commit1e34058ac8c5929e9dedb544b9a1c84a6c13435a (patch)
treeb7ecd2d3076f732ccafa186f7caa701d9b770def /res
parent0be81b1387f010bb00e1ea34ff66561fa67cedef (diff)
downloadfunhalla-1e34058ac8c5929e9dedb544b9a1c84a6c13435a.tar.gz
phong shader model
Diffstat (limited to 'res')
-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);
 }