summaryrefslogtreecommitdiff
path: root/intermediate/surface.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'intermediate/surface.glsl')
-rw-r--r--intermediate/surface.glsl21
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);