summary refs log tree commit diff
path: root/res
diff options
context:
space:
mode:
authoriurii plugatarov <[email protected]>2024-08-18 20:54:42 +0200
committeriurii plugatarov <[email protected]>2024-08-18 20:54:42 +0200
commit30c8a4d7c2160c174392aa2dccf60178f9cd02c2 (patch)
treeafea3e1e310dfac2afd51abc0f974b2c74a76ca4 /res
parent05aa5178f7b0cf0962d4125a6a0af76a972150f2 (diff)
downloadfunhalla-30c8a4d7c2160c174392aa2dccf60178f9cd02c2.tar.gz
diffuse
Diffstat (limited to '')
-rw-r--r--res/shaders/colors.fs15
-rw-r--r--res/shaders/colors.vs9
2 files changed, 22 insertions, 2 deletions
diff --git a/res/shaders/colors.fs b/res/shaders/colors.fs
index a2b8ff4..d434370 100644
--- a/res/shaders/colors.fs
+++ b/res/shaders/colors.fs
@@ -2,10 +2,23 @@
 
 out vec4 FragColor;
 
+in vec3 Normal;
+in vec3 FragPos;
+
 uniform vec3 object_color;
 uniform vec3 light_color;
+uniform vec3 light_position;
 
 void main() {
-  FragColor = vec4(light_color * object_color, 1.0);
+  float ambient_stength = 0.1;
+  vec3 ambient = ambient_stength * light_color;
+
+  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 result = (ambient + diffuse) * object_color;
+  FragColor = vec4(result, 1.0);
 }
 
diff --git a/res/shaders/colors.vs b/res/shaders/colors.vs
index 63a9758..323b2ad 100644
--- a/res/shaders/colors.vs
+++ b/res/shaders/colors.vs
@@ -1,11 +1,18 @@
 #version 330 core
 
 layout (location = 0) in vec3 a_pos;
+layout (location = 1) in vec3 a_normal;
 
 uniform mat4 model;
 uniform mat4 view;
 uniform mat4 projection;
 
+out vec3 Normal;
+out vec3 FragPos;
+
 void main() {
-  gl_Position = projection * view * model * vec4(a_pos, 1.0);
+  FragPos = vec3(model * vec4(a_pos, 1.0));
+  Normal = a_normal;  
+
+  gl_Position = projection * view  * vec4(FragPos, 1.0);
 }