From 888494f0c17f0cc771b77b09b3497ff50375e8e0 Mon Sep 17 00:00:00 2001 From: Kevin Shanahan Date: Sun, 3 Mar 2013 12:56:10 +1030 Subject: [PATCH] light: test spotlight cone before ray tracing Signed-off-by: Kevin Shanahan --- light/ltface.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/light/ltface.c b/light/ltface.c index f0722e52..e206b01b 100644 --- a/light/ltface.c +++ b/light/ltface.c @@ -501,7 +501,6 @@ SingleLightFace(const entity_t *light, lightinfo_t * l, const vec3_t faceoffset, const vec3_t colors) { vec_t dist; - vec3_t incoming; vec_t angle; vec_t add; const vec_t *surf; @@ -553,19 +552,21 @@ SingleLightFace(const entity_t *light, lightinfo_t * l, surf = l->surfpt[0]; for (c = 0; c < l->numsurfpt; c++, surf += 3) { - dist = scaledDistance(CastRay(light->origin, surf), light); - if (dist < 0) - continue; + vec3_t ray; - VectorSubtract(light->origin, surf, incoming); - VectorNormalize(incoming); - angle = DotProduct(incoming, l->facenormal); + VectorSubtract(light->origin, surf, ray); + VectorNormalize(ray); + angle = DotProduct(ray, l->facenormal); if (light->spotlight) { - vec_t falloff = DotProduct(light->spotvec, incoming); + vec_t falloff = DotProduct(light->spotvec, ray); if (falloff > light->spotfalloff) continue; } + dist = scaledDistance(CastRay(light->origin, surf), light); + if (dist < 0) + continue; + angle = (1.0 - scalecos) + scalecos * angle; add = scaledLight(CastRay(light->origin, surf), light); add *= angle;