diff options
Diffstat (limited to 'res/shaders')
-rw-r--r-- | res/shaders/colors.fs | 15 | ||||
-rw-r--r-- | res/shaders/colors.vs | 9 |
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); } |