Remove sorting light probes by subsector

This commit is contained in:
Magnus Norddahl 2021-10-15 04:22:04 +02:00
parent 539bd9fd1d
commit c76bf98834
2 changed files with 6 additions and 36 deletions

View file

@ -648,10 +648,6 @@ void LightmapBuilder::CreateLightProbes()
float halfGridSize = GridSize * 0.5f; float halfGridSize = GridSize * 0.5f;
float doubleGridSize = GridSize * 2.0f; float doubleGridSize = GridSize * 2.0f;
std::vector<std::vector<LightProbeSample>> probes; // order probes by subsector
probes.resize(map->NumGLSubsectors);
size_t totalProbes = 0;
for (float y = minY; y < maxY; y += GridSize) for (float y = minY; y < maxY; y += GridSize)
{ {
for (float x = minX; x < maxX; x += GridSize) for (float x = minX; x < maxX; x += GridSize)
@ -672,9 +668,7 @@ void LightmapBuilder::CreateLightProbes()
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
size_t index = (ptrdiff_t)(ssec - map->GLSubsectors); lightProbes.push_back(p[i]);
probes[index].push_back(p[i]);
totalProbes++;
} }
} }
else if (delta > 0.0f) else if (delta > 0.0f)
@ -683,10 +677,7 @@ void LightmapBuilder::CreateLightProbes()
probe.Position.x = x; probe.Position.x = x;
probe.Position.y = y; probe.Position.y = y;
probe.Position.z = z0 + (z1 - z0) * 0.5f; probe.Position.z = z0 + (z1 - z0) * 0.5f;
lightProbes.push_back(probe);
size_t index = (ptrdiff_t)(ssec - map->GLSubsectors);
probes[index].push_back(probe);
totalProbes++;
} }
} }
} }
@ -694,24 +685,9 @@ void LightmapBuilder::CreateLightProbes()
for (unsigned int i = 0; i < map->ThingLightProbes.Size(); i++) for (unsigned int i = 0; i < map->ThingLightProbes.Size(); i++)
{ {
Vec3 pos = map->GetLightProbePosition(i); LightProbeSample probe;
MapSubsectorEx* ssec = map->PointInSubSector((int)pos.x, (int)pos.y); probe.Position = map->GetLightProbePosition(i);
if (ssec) lightProbes.push_back(probe);
{
LightProbeSample probe;
probe.Position = pos;
size_t index = (ptrdiff_t)(ssec - map->GLSubsectors);
probes[index].push_back(probe);
totalProbes++;
}
}
lightProbes.reserve(totalProbes);
for (const std::vector<LightProbeSample>& ssprobes : probes)
{
lightProbes.insert(lightProbes.end(), ssprobes.begin(), ssprobes.cend());
lightProbeSubsectorCounts.push_back((int)ssprobes.size());
} }
} }
@ -808,7 +784,7 @@ void LightmapBuilder::AddLightmapLump(FWadWriter &wadFile)
lumpFile.Write32(numSurfaces); lumpFile.Write32(numSurfaces);
lumpFile.Write32(numTexCoords); lumpFile.Write32(numTexCoords);
lumpFile.Write32(lightProbes.size()); lumpFile.Write32(lightProbes.size());
lumpFile.Write32(lightProbeSubsectorCounts.size()); lumpFile.Write32(map->NumGLSubsectors);
// Write light probes // Write light probes
for (const LightProbeSample& probe : lightProbes) for (const LightProbeSample& probe : lightProbes)
@ -821,11 +797,6 @@ void LightmapBuilder::AddLightmapLump(FWadWriter &wadFile)
lumpFile.WriteFloat(probe.Color.z); lumpFile.WriteFloat(probe.Color.z);
} }
for (int count : lightProbeSubsectorCounts)
{
lumpFile.Write32(count);
}
// Write surfaces // Write surfaces
int coordOffsets = 0; int coordOffsets = 0;
for (size_t i = 0; i < surfaces.size(); i++) for (size_t i = 0; i < surfaces.size(); i++)

View file

@ -116,7 +116,6 @@ private:
std::vector<std::unique_ptr<LightmapTexture>> textures; std::vector<std::unique_ptr<LightmapTexture>> textures;
std::vector<TraceTask> traceTasks; std::vector<TraceTask> traceTasks;
std::vector<LightProbeSample> lightProbes; std::vector<LightProbeSample> lightProbes;
std::vector<int> lightProbeSubsectorCounts;
int tracedTexels = 0; int tracedTexels = 0;
std::mutex mutex; std::mutex mutex;