- make the closest sample still decide the distance

This commit is contained in:
Magnus Norddahl 2018-11-03 00:25:42 +01:00
parent 664be1eca5
commit a034992280

View file

@ -269,7 +269,10 @@ float kexLightSurface::TraceSurface(FLevel *doomMap, kexTrace &trace, const surf
normal = kexVec3::vecUp; normal = kexVec3::vecUp;
} }
float gzdoomRadiusScale = 2.0f; // 2.0 because gzdoom's dynlights do this and we want them to match
float total = 0.0f; float total = 0.0f;
float closestDistance = distance * gzdoomRadiusScale;
for (unsigned int i = 0; i < origins.Length(); ++i) for (unsigned int i = 0; i < origins.Length(); ++i)
{ {
kexVec3 center = origins[i]; kexVec3 center = origins[i];
@ -310,10 +313,11 @@ float kexLightSurface::TraceSurface(FLevel *doomMap, kexTrace &trace, const surf
} }
float d = origin.Distance(center); float d = origin.Distance(center);
attenuation *= 1.0f - d / (distance * 2.0f); // 2.0 because gzdoom's dynlights do this and we want them to match if (d < closestDistance)
if (attenuation > 0.0f) closestDistance = d;
total += attenuation; total += attenuation;
} }
return total / origins.Length(); float attenuation = 1.0f - closestDistance / (distance * gzdoomRadiusScale);
return attenuation * total / origins.Length();
} }