diff options
author | quou <quou@disroot.org> | 2025-03-10 15:03:05 +1100 |
---|---|---|
committer | quou <quou@disroot.org> | 2025-03-10 15:03:05 +1100 |
commit | 37b929e148e5b003f68903eb9ee192d24517e683 (patch) | |
tree | 79c39617fa73ddc95f30f0ff2c86b5b81c6de0bc /intermediate/surface.glsl | |
parent | 075e530b9964d1eb000dded329d2e8d80ee277c3 (diff) |
point light
Diffstat (limited to 'intermediate/surface.glsl')
-rw-r--r-- | intermediate/surface.glsl | 21 |
1 files changed, 18 insertions, 3 deletions
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); |