mirror of
https://github.com/ZDoom/ZDRay.git
synced 2025-02-09 07:41:03 +00:00
- don't waste time ray tracing surfaces out of range
This commit is contained in:
parent
ce518820ff
commit
440b4d0b3c
1 changed files with 10 additions and 2 deletions
|
@ -249,6 +249,7 @@ float kexLightSurface::TraceSurface(FLevel *map, const surface_t *surf, const ke
|
||||||
|
|
||||||
float total = 0.0f;
|
float total = 0.0f;
|
||||||
float closestDistance = distance * gzdoomRadiusScale;
|
float closestDistance = distance * gzdoomRadiusScale;
|
||||||
|
float maxDistanceSqr = closestDistance * closestDistance;
|
||||||
for (size_t i = 0; i < origins.size(); ++i)
|
for (size_t i = 0; i < origins.size(); ++i)
|
||||||
{
|
{
|
||||||
kexVec3 center = origins[i];
|
kexVec3 center = origins[i];
|
||||||
|
@ -261,7 +262,15 @@ float kexLightSurface::TraceSurface(FLevel *map, const surface_t *surf, const ke
|
||||||
continue;
|
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);
|
float attenuation = dir.Dot(lnormal);
|
||||||
|
|
||||||
if (attenuation <= 0.0f)
|
if (attenuation <= 0.0f)
|
||||||
|
@ -288,7 +297,6 @@ float kexLightSurface::TraceSurface(FLevel *map, const surface_t *surf, const ke
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
float d = origin.Distance(center);
|
|
||||||
if (d < closestDistance)
|
if (d < closestDistance)
|
||||||
closestDistance = d;
|
closestDistance = d;
|
||||||
total += attenuation;
|
total += attenuation;
|
||||||
|
|
Loading…
Reference in a new issue