- don't waste time ray tracing surfaces out of range

This commit is contained in:
Magnus Norddahl 2018-11-05 12:52:19 +01:00
parent ce518820ff
commit 440b4d0b3c

View file

@ -249,6 +249,7 @@ float kexLightSurface::TraceSurface(FLevel *map, const surface_t *surf, const ke
float total = 0.0f;
float closestDistance = distance * gzdoomRadiusScale;
float maxDistanceSqr = closestDistance * closestDistance;
for (size_t i = 0; i < origins.size(); ++i)
{
kexVec3 center = origins[i];
@ -261,7 +262,15 @@ float kexLightSurface::TraceSurface(FLevel *map, const surface_t *surf, const ke
continue;
}
kexVec3 dir = (origin - center).Normalize();
float dsqr = origin.DistanceSq(center);
if (dsqr > maxDistanceSqr)
continue; // out of range
float d = std::sqrt(dsqr);
float id = 1.0f / d;
kexVec3 dir = (origin - center) * id;
float attenuation = dir.Dot(lnormal);
if (attenuation <= 0.0f)
@ -288,7 +297,6 @@ float kexLightSurface::TraceSurface(FLevel *map, const surface_t *surf, const ke
continue;
}
float d = origin.Distance(center);
if (d < closestDistance)
closestDistance = d;
total += attenuation;