summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-05-22 21:22:19 +0200
committerHampusM <hampus@hampusmat.com>2024-05-22 21:22:19 +0200
commitdb4017c1165b9ba02655508e615d161a4c42acf0 (patch)
tree31e93c201596ea4f9f9b588e13a07a45bb6e1535 /engine
parent944518fa4c3523bdc3e299e03e52613efaaf46b3 (diff)
refactor(engine): make shader functions not use uniforms directly
Diffstat (limited to 'engine')
-rw-r--r--engine/fragment.glsl15
-rw-r--r--engine/light.glsl15
2 files changed, 22 insertions, 8 deletions
diff --git a/engine/fragment.glsl b/engine/fragment.glsl
index a9d192b..9becd4c 100644
--- a/engine/fragment.glsl
+++ b/engine/fragment.glsl
@@ -10,19 +10,28 @@ in vec3 in_frag_pos;
in vec3 in_normal;
uniform vec3 view_pos;
-
uniform sampler2D input_texture;
+uniform Material material;
+uniform PointLight light;
void main()
{
- vec3 ambient_light = calc_ambient_light(in_texture_coords);
+ vec3 ambient_light = calc_ambient_light(material, in_texture_coords);
vec3 light_direction = normalize(light.position - in_frag_pos);
vec3 norm = normalize(in_normal);
- vec3 diffuse_light = calc_diffuse_light(light_direction, norm, in_texture_coords);
+ vec3 diffuse_light = calc_diffuse_light(
+ material,
+ light,
+ light_direction,
+ norm,
+ in_texture_coords
+ );
vec3 specular_light = calc_specular_light(
+ material,
+ light,
light_direction,
norm,
view_pos,
diff --git a/engine/light.glsl b/engine/light.glsl
index 04a42f5..e9b2a61 100644
--- a/engine/light.glsl
+++ b/engine/light.glsl
@@ -21,16 +21,19 @@ struct PointLight {
float linear;
float quadratic;
};
-
-uniform Material material;
-uniform PointLight light;
-vec3 calc_ambient_light(in vec2 texture_coords)
+vec3 calc_ambient_light(in Material material, in vec2 texture_coords)
{
return vec3(texture(material.ambient_map, texture_coords)) * material.ambient;
}
-vec3 calc_diffuse_light(in vec3 light_dir, in vec3 norm, in vec2 texture_coords)
+vec3 calc_diffuse_light(
+ in Material material,
+ in PointLight light,
+ in vec3 light_dir,
+ in vec3 norm,
+ in vec2 texture_coords
+)
{
float diff = max(dot(norm, light_dir), 0.0);
@@ -40,6 +43,8 @@ vec3 calc_diffuse_light(in vec3 light_dir, in vec3 norm, in vec2 texture_coords)
}
vec3 calc_specular_light(
+ in Material material,
+ in PointLight light,
in vec3 light_dir,
in vec3 norm,
in vec3 view_pos,