Minor refactor and fix 3d floors not being detected for lightmap updates

This commit is contained in:
RaveYard 2023-09-09 15:22:40 +02:00 committed by Christoph Oelckers
parent 934ba83503
commit 2bdb495498
4 changed files with 32 additions and 9 deletions

View file

@ -735,7 +735,7 @@ public:
inline void PushVisibleSurface(int surfaceIndex, LevelMeshSurface* surface)
{
if(surface->needsUpdate && mActiveLightmapSurfaces.Size() < lm_max_updates && mActiveLightmapSurfaces.Find(surfaceIndex) >= mActiveLightmapSurfaces.Size()) // yikes, how awful
if(surface->needsUpdate && mActiveLightmapSurfaces.Size() < unsigned(lm_max_updates) && mActiveLightmapSurfaces.Find(surfaceIndex) >= mActiveLightmapSurfaces.Size()) // yikes, how awful
mActiveLightmapSurfaces.Push(surfaceIndex);
}

View file

@ -98,6 +98,15 @@ DoomLevelMesh::DoomLevelMesh(FLevelLocals &doomMap)
BindLightmapSurfacesToGeometry(doomMap);
Collision = std::make_unique<TriangleMeshShape>(MeshVertices.Data(), MeshVertices.Size(), MeshElements.Data(), MeshElements.Size());
// Runtime stuff
for (auto& surface : Surfaces)
{
if ((surface.Type == ST_FLOOR || surface.Type == ST_CEILING) && surface.ControlSector)
{
XFloorToSurface[surface.ControlSector].Push(&surface);
}
}
}
void DoomLevelMesh::CreatePortals()

View file

@ -27,6 +27,9 @@ class DoomLevelMesh : public LevelMesh
{
public:
DoomLevelMesh(FLevelLocals &doomMap);
void CreatePortals();
void DumpMesh(const FString& objFilename, const FString& mtlFilename) const;
bool TraceSky(const FVector3& start, FVector3 direction, float dist)
{
@ -40,17 +43,15 @@ public:
LevelMeshSurface* GetSurface(int index) override { return &Surfaces[index]; }
int GetSurfaceCount() override { return Surfaces.Size(); }
TArray<DoomLevelMeshSurface> Surfaces;
std::vector<std::unique_ptr<LevelMeshLight>> Lights;
TArray<FVector2> LightmapUvs;
static_assert(alignof(FVector2) == alignof(float[2]) && sizeof(FVector2) == sizeof(float) * 2);
void DumpMesh(const FString& objFilename, const FString& mtlFilename) const;
// runtime utility variables
TMap<sector_t*, TArray<DoomLevelMeshSurface*>> XFloorToSurface;
void SetupLightmapUvs();
void CreatePortals();
private:
void CreateSubsectorSurfaces(FLevelLocals &doomMap);
void CreateCeilingSurface(FLevelLocals &doomMap, subsector_t *sub, sector_t *sector, int typeIndex, bool is3DFloor);
@ -61,6 +62,7 @@ private:
void SetSubsectorLightmap(DoomLevelMeshSurface* surface);
void SetSideLightmap(DoomLevelMeshSurface* surface);
void SetupLightmapUvs();
void PropagateLight(const LevelMeshLight* light, std::set<LevelMeshPortal, RecursivePortalComparator>& touchedPortals, int lightPropagationRecursiveDepth);
void CreateLightList();

View file

@ -192,12 +192,24 @@ void HWFlat::DrawSubsectors(HWDrawInfo *di, FRenderState &state)
}
state.SetLightIndex(dynlightindex);
const auto* lm = &sector->Level->levelMesh->Surfaces[0]; // temporay hack on top of a temporary hack
for (auto& subsector : section->subsectors)
{
auto lightmap = subsector->lightmap[ceiling ? 1 : 0][0];
if (lightmap)
if (auto lightmap = subsector->lightmap[ceiling ? 1 : 0][0])
{
state.PushVisibleSurface(lightmap - &subsector->sector->Level->levelMesh->Surfaces[0], lightmap);
state.PushVisibleSurface(lightmap - lm, lightmap);
}
}
if (auto subsectors = sector->Level->levelMesh->XFloorToSurface.CheckKey(sector))
{
for (auto* surface : *subsectors)
{
if (surface)
{
state.PushVisibleSurface(surface - lm, surface);
}
}
}