diff options
author | HampusM <hampus@hampusmat.com> | 2024-05-22 20:39:26 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-05-22 20:39:26 +0200 |
commit | d4b61dd34b06119e87c8932ab7718d432dbc6a4f (patch) | |
tree | 2240158176c11eac545a1b50bbe644700b67ab51 /engine/light.glsl | |
parent | 8398025d7927564637e1ea67234665571dc7bcc5 (diff) |
feat(engine): add point light attenuation
Diffstat (limited to 'engine/light.glsl')
-rw-r--r-- | engine/light.glsl | 16 |
1 files changed, 14 insertions, 2 deletions
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 |