From 33f7772ddddf2a1c2bfefc50ef39f123df8af3e4 Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 24 Apr 2024 20:43:18 +0200 Subject: feat(engine): add colors to materials --- engine/light.glsl | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'engine/light.glsl') diff --git a/engine/light.glsl b/engine/light.glsl index 3ba5ba0..46105e9 100644 --- a/engine/light.glsl +++ b/engine/light.glsl @@ -4,9 +4,12 @@ #define LIGHT_GLSL struct Material { - sampler2D ambient; - sampler2D diffuse; - sampler2D specular; + vec3 ambient; + vec3 diffuse; + vec3 specular; + sampler2D ambient_map; + sampler2D diffuse_map; + sampler2D specular_map; float shininess; }; @@ -23,14 +26,18 @@ uniform Light light; vec3 calc_ambient_light(in vec2 texture_coords) { - return light.ambient * vec3(texture(material.ambient, texture_coords)); + return light.ambient * ( + vec3(texture(material.ambient_map, texture_coords)) * material.ambient + ); } vec3 calc_diffuse_light(in vec3 light_dir, in vec3 norm, in vec2 texture_coords) { float diff = max(dot(norm, light_dir), 0.0); - return light.diffuse * (diff * vec3(texture(material.diffuse, texture_coords))); + return light.diffuse * ( + diff * (vec3(texture(material.diffuse_map, texture_coords)) * material.diffuse) + ); } vec3 calc_specular_light( @@ -48,7 +55,9 @@ vec3 calc_specular_light( float spec = pow(max(dot(view_direction, reflect_direction), 0.0), material.shininess); - return light.specular * (spec * vec3(texture(material.specular, texture_coords))); + return light.specular * ( + spec * (vec3(texture(material.specular_map, texture_coords)) * material.specular) + ); } #endif -- cgit v1.2.3-18-g5258