summaryrefslogtreecommitdiff
path: root/ray.c
diff options
context:
space:
mode:
Diffstat (limited to 'ray.c')
-rw-r--r--ray.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/ray.c b/ray.c
index 6304b36..1125d19 100644
--- a/ray.c
+++ b/ray.c
@@ -59,9 +59,12 @@ trace(float s[3], const float d[3], float pixel[3], int n) {
for(i = 0; i < 3; ++i)
l[i] = lights[m].position[i] - y[i];
- normalize(l);
- for(k = 0; k < 3; ++k)
- pixel[k] += lights[m].diffuse[k] * objects[j].diffuse[k] * (MAX(dot(l, r), 0)) / (1 << n);
+ float lr_dot = dot(l, r);
+ if (lr_dot > 0) {
+ float scale = lr_dot / sqrtf(dot(l, l)) / (1 << n);
+ for(k = 0; k < 3; ++k)
+ pixel[k] += lights[m].diffuse[k] * objects[j].diffuse[k] * scale;
+ }
trace(y, r, pixel, n + 1);
}