mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-03-13 22:42:07 +00:00
Sector portals sunlight only
This commit is contained in:
parent
cd6dd34f72
commit
efeab91a75
5 changed files with 69 additions and 2 deletions
|
@ -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:
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue