From 37b929e148e5b003f68903eb9ee192d24517e683 Mon Sep 17 00:00:00 2001 From: quou Date: Mon, 10 Mar 2025 15:03:05 +1100 Subject: point light --- intermediate/surface.glsl | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'intermediate/surface.glsl') diff --git a/intermediate/surface.glsl b/intermediate/surface.glsl index 71a4307..79f5f65 100644 --- a/intermediate/surface.glsl +++ b/intermediate/surface.glsl @@ -244,8 +244,23 @@ void main() { vec3 light = 0.0.xxx; for (i = 0; i < globals.light_count; i++) { Light l = lights[i]; - vec3 light_dir = l.dir; - float cos_theta_i = max(dot(nrm, light_dir), 0.0); + vec3 light_dir; + float cos_theta_i, atten; + switch (l.type) { + case LT_SUN: + light_dir = l.pos; + cos_theta_i = max(dot(nrm, light_dir), 0.0); + atten = 1.0; + break; + case LT_POINT: { + float d; + light_dir = p - l.pos; + d = length(light_dir); + atten = max(d, 0.01); + atten = 1.0 / (atten * atten); + light_dir /= d; + } break; + } vec3 diffuse = base_diffuse * cos_theta_i; vec3 spec = spec_col * @@ -254,7 +269,7 @@ void main() { float shadow = 1.0f; if (l.caster_id >= 0) shadow = get_shadow(l, p); - light += (diffuse + spec) * l.brightness * l.colour * shadow; + light += (diffuse + spec) * atten * l.brightness * l.colour * shadow; } colour = vec4(ambient + light, 1.0); -- cgit v1.2.3-54-g00ecf