From 1dca69e545ab815850230a377bc346bb5dc33839 Mon Sep 17 00:00:00 2001 From: Morten Hustveit Date: Tue, 2 Dec 2014 15:18:32 -0500 Subject: ray.c: Skip normalizing if light has negative contribution This saves about 3ms/frame on yelena. --- ray.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'ray.c') 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); } -- cgit v1.2.3