summaryrefslogtreecommitdiff
path: root/engine/fragment.glsl
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-05-22 22:42:43 +0200
committerHampusM <hampus@hampusmat.com>2024-05-22 22:42:43 +0200
commite9504a3b90ef081dcd622381694f6c51e2844c2d (patch)
tree479f1e21c892c3cfc964c139015d60840862df89 /engine/fragment.glsl
parentdb4017c1165b9ba02655508e615d161a4c42acf0 (diff)
feat(engine): add support for multiple point lights
Diffstat (limited to 'engine/fragment.glsl')
-rw-r--r--engine/fragment.glsl46
1 files changed, 18 insertions, 28 deletions
diff --git a/engine/fragment.glsl b/engine/fragment.glsl
index 9becd4c..6e852f3 100644
--- a/engine/fragment.glsl
+++ b/engine/fragment.glsl
@@ -2,6 +2,8 @@
#preinclude "light.glsl"
+#define MAX_POINT_LIGHT_CNT 64
+
out vec4 FragColor;
in vec2 in_texture_coords;
@@ -12,37 +14,25 @@ in vec3 in_normal;
uniform vec3 view_pos;
uniform sampler2D input_texture;
uniform Material material;
-uniform PointLight light;
+uniform PointLight point_lights[MAX_POINT_LIGHT_CNT];
+uniform int point_light_cnt;
void main()
{
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(
- material,
- light,
- light_direction,
- norm,
- in_texture_coords
- );
-
- vec3 specular_light = calc_specular_light(
- material,
- light,
- light_direction,
- norm,
- view_pos,
- in_frag_pos,
- in_texture_coords
- );
-
- float attenuation = calc_attenuation(light, in_frag_pos);
-
- diffuse_light *= attenuation;
- specular_light *= attenuation;
-
- FragColor = vec4((ambient_light + diffuse_light + specular_light), 1.0);
+ vec3 point_light_sum = vec3(0.0, 0.0, 0.0);
+
+ for (int pl_index= 0; pl_index < point_light_cnt; pl_index++) {
+ point_light_sum += calc_point_light(
+ point_lights[pl_index],
+ in_frag_pos,
+ in_normal,
+ in_texture_coords,
+ view_pos,
+ material
+ );
+ }
+
+ FragColor = vec4((ambient_light + point_light_sum), 1.0);
}