Fix light probe Z coordinate

This commit is contained in:
Magnus Norddahl 2021-09-25 19:55:17 +02:00
parent ba36819da9
commit ef7caddb2c
3 changed files with 28 additions and 16 deletions

View file

@ -346,6 +346,8 @@ struct FLevel
MapSubsectorEx *PointInSubSector(const int x, const int y); MapSubsectorEx *PointInSubSector(const int x, const int y);
FloatVertex GetSegVertex(int index); FloatVertex GetSegVertex(int index);
Vec3 GetLightProbePosition(int index);
private: private:
void CheckSkySectors(); void CheckSkySectors();
void CreateLights(); void CreateLights();

View file

@ -402,3 +402,24 @@ void FLevel::CreateLights()
printf("Surface lights: %i\n", (int)SurfaceLights.Size()); printf("Surface lights: %i\n", (int)SurfaceLights.Size());
} }
Vec3 FLevel::GetLightProbePosition(int index)
{
int thingIndex = ThingLightProbes[index];
const IntThing& thing = Things[thingIndex];
float x = (float)(thing.x >> FRACBITS);
float y = (float)(thing.y >> FRACBITS);
float z = 0.0f;
MapSubsectorEx* ssect = PointInSubSector(x, y);
if (ssect)
{
IntSector* sector = GetSectorFromSubSector(ssect);
if (sector)
{
z = sector->floorplane.zAt(x, y) + thing.height;
}
}
return Vec3(x, y, z);
}

View file

@ -692,13 +692,7 @@ void LightmapBuilder::CreateSurfaceLights()
void LightmapBuilder::LightProbe(int id) void LightmapBuilder::LightProbe(int id)
{ {
int thingIndex = map->ThingLightProbes[id]; lightProbes[id] = LightTexelSample(map->GetLightProbePosition(id), nullptr);
const IntThing& thing = map->Things[thingIndex];
float x = (float)(thing.x >> FRACBITS);
float y = (float)(thing.y >> FRACBITS);
float z = (float)thing.z /* + thing.height * 0.5f*/;
lightProbes[id] = LightTexelSample({ x, y, z }, nullptr);
} }
void LightmapBuilder::AddLightmapLump(FWadWriter &wadFile) void LightmapBuilder::AddLightmapLump(FWadWriter &wadFile)
@ -741,15 +735,10 @@ void LightmapBuilder::AddLightmapLump(FWadWriter &wadFile)
// Write light probes // Write light probes
for (size_t i = 0; i < lightProbes.size(); i++) for (size_t i = 0; i < lightProbes.size(); i++)
{ {
int thingIndex = map->ThingLightProbes[i]; Vec3 pos = map->GetLightProbePosition(i);
const IntThing& thing = map->Things[thingIndex]; lumpFile.WriteFloat(pos.x);
float x = (float)(thing.x >> FRACBITS); lumpFile.WriteFloat(pos.y);
float y = (float)(thing.y >> FRACBITS); lumpFile.WriteFloat(pos.z);
float z = (float)thing.z /* + thing.height * 0.5f*/;
lumpFile.WriteFloat(x);
lumpFile.WriteFloat(y);
lumpFile.WriteFloat(z);
lumpFile.WriteFloat(lightProbes[i].x); lumpFile.WriteFloat(lightProbes[i].x);
lumpFile.WriteFloat(lightProbes[i].y); lumpFile.WriteFloat(lightProbes[i].y);
lumpFile.WriteFloat(lightProbes[i].z); lumpFile.WriteFloat(lightProbes[i].z);