summary refs log tree commit diff
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
parent1a771d9a157bebffad42573d114240a4bfe7f611 (diff)
downloadfunhalla-4009a194178f1f85bf8936faeca2bf14dcff2c08.tar.gz
materials
-rw-r--r--res/shaders/colors.fs28
-rw-r--r--src/main.odin11
2 files changed, 25 insertions, 14 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);
 }
-
diff --git a/src/main.odin b/src/main.odin
index 2b8dd3e..a21a891 100644
--- a/src/main.odin
+++ b/src/main.odin
@@ -398,10 +398,17 @@ main :: proc() {
 
 
 		shader.use(lighting_shader)
-		object_color := Vec3{1.0, 0.5, 0.31}
 		light_color := Vec3{1.0, 1.0, 1.0}
-		shader.set_vec3(lighting_shader, cstring("object_color"), &object_color)
 		shader.set_vec3(lighting_shader, cstring("light_color"), &light_color)
+
+		material_ambient := Vec3{1.0, 0.5, 0.31}
+		material_diffuse := Vec3{1.0, 0.5, 0.31}
+		material_specular := Vec3{0.5, 0.5, 0.5}
+		shader.set_vec3(lighting_shader, cstring("material.ambient"), &material_ambient)
+		shader.set_vec3(lighting_shader, cstring("material.diffuse"), &material_diffuse)
+		shader.set_vec3(lighting_shader, cstring("material.specular"), &material_specular)
+		shader.set_f32(lighting_shader, cstring("material.shininess"), 32.0)
+
 		shader.set_vec3(lighting_shader, cstring("light_position"), &light_pos)
 		shader.set_vec3(lighting_shader, cstring("view_position"), &camera.position)