Sector portals sunlight only

This commit is contained in:
RaveYard 2023-09-05 15:47:48 +02:00 committed by Christoph Oelckers
parent cd6dd34f72
commit efeab91a75
5 changed files with 69 additions and 2 deletions

View file

@ -55,7 +55,9 @@ struct LevelMeshSurface
//
// Required for internal lightmapper:
//
// int portalDestinationIndex = -1; // line or sector index
int portalIndex = 0;
int sectorGroup = 0;
BBox bounds;
@ -146,6 +148,25 @@ struct LevelMeshPortal
}
};
// for use with std::set to recursively go through portals and skip returning portals
struct RecursivePortalComparator
{
bool operator()(const LevelMeshPortal& a, const LevelMeshPortal& b) const
{
return !a.IsInversePortal(b) && std::memcmp(&a.transformation, &b.transformation, sizeof(VSMatrix)) < 0;
}
};
// for use with std::map to reject portals which have the same effect for light rays
struct IdenticalPortalComparator
{
bool operator()(const LevelMeshPortal& a, const LevelMeshPortal& b) const
{
return !a.IsEqualPortal(b) && std::memcmp(&a.transformation, &b.transformation, sizeof(VSMatrix)) < 0;
}
};
class LevelMesh
{
public:

View file

@ -121,7 +121,7 @@ void VkRaytrace::CreateBuffers()
SurfaceInfo info;
info.Normal = surface->plane.XYZ();
info.PortalIndex = 0;
info.PortalIndex = surface->portalIndex;
info.SamplingDistance = (float)surface->sampleDimension;
info.Sky = surface->bSky;
surfaceInfo.Push(info);

View file

@ -3294,5 +3294,7 @@ void MapLoader::LoadLevel(MapData *map, const char *lumpname, int position)
if (!Level->IsReentering())
Level->FinalizePortals(); // finalize line portals after polyobjects have been initialized. This info is needed for properly flagging them.
Level->levelMesh->CreatePortals(); // [RaveYard]: needs portal data, but at the same time intializing the level mesh here breaks floor/ceiling planes!
Level->aabbTree = new DoomLevelAABBTree(Level);
}

View file

@ -86,6 +86,49 @@ DoomLevelMesh::DoomLevelMesh(FLevelLocals &doomMap)
Collision = std::make_unique<TriangleMeshShape>(MeshVertices.Data(), MeshVertices.Size(), MeshElements.Data(), MeshElements.Size());
}
void DoomLevelMesh::CreatePortals()
{
std::map<LevelMeshPortal, int, IdenticalPortalComparator> transformationIndices; // TODO use the list of portals from the level to avoids duplicates?
transformationIndices.emplace(LevelMeshPortal{}, 0); // first portal is an identity matrix
for (auto& surface : Surfaces)
{
auto displacement = [&]() {
if (surface.Type == ST_FLOOR || surface.Type == ST_CEILING)
{
auto d = surface.Subsector->sector->GetPortalDisplacement(surface.Type == ST_FLOOR ? sector_t::floor : sector_t::ceiling);
return FVector3(d.X, d.Y, 0);
}
else if(surface.Type == ST_MIDDLESIDE)
{
auto d = surface.Side->linedef->getPortalDisplacement();
return FVector3(d.X, d.Y, 0);
}
return FVector3(0, 0, 0);
}();
if (!displacement.isZero())
{
LevelMeshPortal transformation;
transformation.transformation.translate(displacement.X, displacement.Y, displacement.Z);
auto& index = transformationIndices[transformation];
if (index == 0) // new transformation was created
{
index = Portals.Size();
Portals.Push(transformation);
}
surface.portalIndex = index;
}
else
{
surface.portalIndex = 0;
}
}
}
void DoomLevelMesh::UpdateLightLists()
{
for (auto& surface : Surfaces)

View file

@ -52,6 +52,7 @@ public:
void SetupLightmapUvs();
void CreatePortals();
private:
void CreateSubsectorSurfaces(FLevelLocals &doomMap);
void CreateCeilingSurface(FLevelLocals &doomMap, subsector_t *sub, sector_t *sector, int typeIndex, bool is3DFloor);