From d4b61dd34b06119e87c8932ab7718d432dbc6a4f Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 22 May 2024 20:39:26 +0200 Subject: feat(engine): add point light attenuation --- engine/light.glsl | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'engine/light.glsl') diff --git a/engine/light.glsl b/engine/light.glsl index 49026ec..04a42f5 100644 --- a/engine/light.glsl +++ b/engine/light.glsl @@ -13,14 +13,17 @@ struct Material { float shininess; }; -struct Light { +struct PointLight { vec3 position; vec3 diffuse; vec3 specular; + float constant; + float linear; + float quadratic; }; uniform Material material; -uniform Light light; +uniform PointLight light; vec3 calc_ambient_light(in vec2 texture_coords) { @@ -56,4 +59,13 @@ vec3 calc_specular_light( ); } +float calc_attenuation(in PointLight point_light, in vec3 position) +{ + float light_distance = length(point_light.position - position); + + return 1.0 / (point_light.constant + point_light.linear + * light_distance + point_light.quadratic + * pow(light_distance, 2)); +} + #endif -- cgit v1.2.3-18-g5258