summary refs log tree commit diff
path: root/res/shaders
diff options
context:
space:
mode:
authoriurii <[email protected]>2024-09-05 20:21:40 +0200
committeriurii <[email protected]>2024-09-05 20:21:40 +0200
commit4009a194178f1f85bf8936faeca2bf14dcff2c08 (patch)
tree77008e8d5f538b9058678a4b3e3abd4dfd989867 /res/shaders
parent1a771d9a157bebffad42573d114240a4bfe7f611 (diff)
downloadfunhalla-4009a194178f1f85bf8936faeca2bf14dcff2c08.tar.gz
materials
Diffstat (limited to '')
-rw-r--r--res/shaders/colors.fs28
1 files changed, 16 insertions, 12 deletions
diff --git a/res/shaders/colors.fs b/res/shaders/colors.fs
index 83733cf..8d51645 100644
--- a/res/shaders/colors.fs
+++ b/res/shaders/colors.fs
@@ -1,34 +1,38 @@
 #version 330 core
+struct Material {
+  vec3 ambient;
+  vec3 diffuse;
+  vec3 specula;
+  float shininess;
+};
 
 out vec4 FragColor;
 
 in vec3 Normal;
 in vec3 FragPos;
 
-uniform vec3 object_color;
 uniform vec3 light_color;
 uniform vec3 light_position;
 uniform vec3 view_position;
 
+uniform Material material;
+
 void main() {
   // ambient
-  float ambient_stength = 0.1;
-  vec3 ambient = ambient_stength * light_color;
-
+  vec3 ambient = light_color * material.ambient;
+  
   // 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;
-
+  vec3 diffuse = light_color * (diff * material.diffuse);
+  
   // 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 + specular) * object_color;
+  float spec = pow(max(dot(view_dir, reflect_dir), 0.0), material.shininess);
+  vec3 specular = light_color * (spec * material.specular);
+  
+  vec3 result = ambient + diffuse + specular;
   FragColor = vec4(result, 1.0);
 }
-