summaryrefslogtreecommitdiff
path: root/engine/light.glsl
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-04-24 20:43:18 +0200
committerHampusM <hampus@hampusmat.com>2024-04-24 20:43:18 +0200
commit33f7772ddddf2a1c2bfefc50ef39f123df8af3e4 (patch)
treec142293d3ebdcbbaf36220fb073873c95575de9d /engine/light.glsl
parentd06be3fdaf66eb38e6c54fe2b7407d25692f8edc (diff)
feat(engine): add colors to materials
Diffstat (limited to 'engine/light.glsl')
-rw-r--r--engine/light.glsl21
1 files changed, 15 insertions, 6 deletions
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