From 8d821588cd4f51d4ae9c4ef52d45c0af0e1ce9e5 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 12 Nov 2023 22:38:52 +0100 Subject: feat(engine): add basic flat lighting --- engine/fragment-color.glsl | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'engine/fragment-color.glsl') diff --git a/engine/fragment-color.glsl b/engine/fragment-color.glsl index 8b209c4..fcf8d28 100644 --- a/engine/fragment-color.glsl +++ b/engine/fragment-color.glsl @@ -1,9 +1,28 @@ #version 330 core + +#preinclude "light.glsl" + out vec4 FragColor; in vec3 in_frag_color; +in vec3 in_frag_pos; +in vec3 in_normal; + +uniform vec3 view_pos; void main() { - FragColor = vec4(in_frag_color, 1.0); + vec3 ambient_light = ambient_light_strength * light_color; + + vec3 light_direction = normalize(light_pos - in_frag_pos); + vec3 norm = normalize(in_normal); + + vec3 diffuse_light = calc_diffuse_light(light_direction, norm); + + vec3 specular_light = + calc_specular_light(light_direction, norm, view_pos, in_frag_pos); + + FragColor = + vec4((ambient_light + diffuse_light + specular_light) * in_frag_color, 1.0); } + -- cgit v1.2.3-18-g5258