diff options
author | HampusM <hampus@hampusmat.com> | 2024-05-22 22:42:43 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-05-22 22:42:43 +0200 |
commit | e9504a3b90ef081dcd622381694f6c51e2844c2d (patch) | |
tree | 479f1e21c892c3cfc964c139015d60840862df89 /engine/light.glsl | |
parent | db4017c1165b9ba02655508e615d161a4c42acf0 (diff) |
feat(engine): add support for multiple point lights
Diffstat (limited to 'engine/light.glsl')
-rw-r--r-- | engine/light.glsl | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/engine/light.glsl b/engine/light.glsl index e9b2a61..7516a58 100644 --- a/engine/light.glsl +++ b/engine/light.glsl @@ -73,4 +73,43 @@ float calc_attenuation(in PointLight point_light, in vec3 position) * pow(light_distance, 2)); } +vec3 calc_point_light( + in PointLight light, + in vec3 frag_pos, + in vec3 normal, + in vec2 texture_coords, + in vec3 view_pos, + in Material material +) +{ + vec3 light_direction = normalize(light.position - frag_pos); + vec3 norm = normalize(normal); + + vec3 diffuse_light = calc_diffuse_light( + material, + light, + light_direction, + norm, + texture_coords + ); + + vec3 specular_light = calc_specular_light( + material, + light, + light_direction, + norm, + view_pos, + frag_pos, + texture_coords + ); + + float attenuation = calc_attenuation(light, frag_pos); + + diffuse_light *= attenuation; + specular_light *= attenuation; + + return diffuse_light + specular_light; +} + + #endif |