From c78784795449732a4d7edb72af28506ab16d0117 Mon Sep 17 00:00:00 2001 From: iurii Date: Fri, 6 Sep 2024 00:42:07 +0300 Subject: colored cubes`` --- res/shaders/colors.fs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'res') diff --git a/res/shaders/colors.fs b/res/shaders/colors.fs index df02754..053e1c4 100644 --- a/res/shaders/colors.fs +++ b/res/shaders/colors.fs @@ -6,32 +6,39 @@ struct Material { float shininess; }; +struct Light { + vec3 position; + vec3 ambient; + vec3 diffuse; + vec3 specular; +}; + out vec4 FragColor; in vec3 Normal; in vec3 FragPos; -uniform vec3 light_color; uniform vec3 light_position; uniform vec3 view_position; uniform Material material; +uniform Light light; void main() { // ambient - vec3 ambient = light_color * material.ambient; + vec3 ambient = light.ambient * 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 = light_color * (diff * material.diffuse); + vec3 diffuse = light.diffuse * (diff * material.diffuse); // specular 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), material.shininess); - vec3 specular = light_color * (spec * material.specular); + vec3 specular = light.specular * (spec * material.specular); vec3 result = ambient + diffuse + specular; FragColor = vec4(result, 1.0); -- cgit 1.4.1-2-gfad0