Use a faster way to find the closest light probe
Fix light probe not being applied to psprite
This commit is contained in:
parent
b59bd46b79
commit
764a08752f
8 changed files with 103 additions and 28 deletions
|
|
@ -45,6 +45,50 @@ T smoothstep(const T edge0, const T edge1, const T x)
|
|||
return t * t * (3.0 - 2.0 * t);
|
||||
}
|
||||
|
||||
LightProbe* FindLightProbe(FLevelLocals* level, float x, float y, float z)
|
||||
{
|
||||
LightProbe* foundprobe = nullptr;
|
||||
if (level->LightProbes.Size() > 0)
|
||||
{
|
||||
#if 1
|
||||
float radiusSquared = 32.0f * 32.0f;
|
||||
float lastdist = 0.0f;
|
||||
BSPWalkCircle(level, x, y, radiusSquared, [&](subsector_t* subsector) // Iterate through all subsectors potentially touched by actor
|
||||
{
|
||||
for (uint32_t i = 0; i < subsector->numprobes; i++)
|
||||
{
|
||||
LightProbe* probe = subsector->firstprobe + i;
|
||||
float dx = probe->X - x;
|
||||
float dy = probe->Y - y;
|
||||
float dz = probe->Z - z;
|
||||
float dist = dx * dx + dy * dy + dz * dz;
|
||||
if (!foundprobe || dist < lastdist)
|
||||
{
|
||||
foundprobe = probe;
|
||||
lastdist = dist;
|
||||
}
|
||||
}
|
||||
});
|
||||
#else
|
||||
float lastdist = 0.0f;
|
||||
for (unsigned int i = 0; i < level->LightProbes.Size(); i++)
|
||||
{
|
||||
LightProbe *probe = &level->LightProbes[i];
|
||||
float dx = probe->X - x;
|
||||
float dy = probe->Y - y;
|
||||
float dz = probe->Z - z;
|
||||
float dist = dx * dx + dy * dy + dz * dz;
|
||||
if (i == 0 || dist < lastdist)
|
||||
{
|
||||
foundprobe = probe;
|
||||
lastdist = dist;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return foundprobe;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Sets a single light value from all dynamic lights affecting the specified location
|
||||
|
|
@ -57,7 +101,15 @@ void HWDrawInfo::GetDynSpriteLight(AActor *self, float x, float y, float z, FLig
|
|||
float frac, lr, lg, lb;
|
||||
float radius;
|
||||
|
||||
Level->GetLightProbeLight(x, y, z, out);
|
||||
out[0] = out[1] = out[2] = 0.f;
|
||||
|
||||
LightProbe* probe = FindLightProbe(Level, x, y, z);
|
||||
if (probe)
|
||||
{
|
||||
out[0] = probe->Red;
|
||||
out[1] = probe->Green;
|
||||
out[2] = probe->Blue;
|
||||
}
|
||||
|
||||
// Go through both light lists
|
||||
while (node)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue