mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-02-22 20:11:14 +00:00
Merge LightmapSurface into DoomLevelMeshSurface
This commit is contained in:
parent
dd07316072
commit
ac962c80e3
9 changed files with 65 additions and 84 deletions
|
@ -37,7 +37,7 @@ enum LevelMeshSurfaceType
|
|||
|
||||
struct LevelMeshSurface
|
||||
{
|
||||
LevelMeshSurfaceType type = ST_UNKNOWN;
|
||||
LevelMeshSurfaceType Type = ST_UNKNOWN;
|
||||
int typeIndex;
|
||||
int numVerts;
|
||||
unsigned int startVertIndex;
|
||||
|
|
|
@ -177,7 +177,7 @@ void VkLightmap::RenderAtlasImage(size_t pageIndex)
|
|||
|
||||
SceneVertex* vertex = &vertices.Vertices[firstVertex];
|
||||
|
||||
if (surface->type == ST_FLOOR || surface->type == ST_CEILING)
|
||||
if (surface->Type == ST_FLOOR || surface->Type == ST_CEILING)
|
||||
{
|
||||
for (int idx = 0; idx < vertexCount; idx++)
|
||||
{
|
||||
|
|
|
@ -455,7 +455,7 @@ public:
|
|||
|
||||
// Lightmaps
|
||||
bool lightmaps = false;
|
||||
TArray<LightmapSurface> LMSurfaces;
|
||||
TArray<DoomLevelMeshSurface*> LMSurfaces;
|
||||
FVector3 SunDirection;
|
||||
FVector3 SunColor;
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ struct sector_t;
|
|||
class AActor;
|
||||
struct FSection;
|
||||
struct FLevelLocals;
|
||||
struct LightmapSurface;
|
||||
struct DoomLevelMeshSurface;
|
||||
|
||||
const uint16_t NO_INDEX = 0xffffu;
|
||||
const uint32_t NO_SIDE = 0xffffffffu;
|
||||
|
@ -1228,7 +1228,7 @@ struct side_t
|
|||
uint16_t Flags;
|
||||
int UDMFIndex; // needed to access custom UDMF fields which are stored in loading order.
|
||||
FLightNode * lighthead; // all dynamic lights that may affect this wall
|
||||
LightmapSurface* lightmap;
|
||||
DoomLevelMeshSurface** lightmap; // all mesh surfaces belonging to this sidedef. Used for lightmapping
|
||||
seg_t **segs; // all segs belonging to this sidedef in ascending order. Used for precise rendering
|
||||
int numsegs;
|
||||
int sidenum;
|
||||
|
@ -1643,7 +1643,7 @@ struct subsector_t
|
|||
// 2: has one-sided walls
|
||||
FPortalCoverage portalcoverage[2];
|
||||
|
||||
LightmapSurface *lightmap[2];
|
||||
DoomLevelMeshSurface** lightmap[2]; // all mesh surfaces belonging to this subsector. Used for lightmapping
|
||||
};
|
||||
|
||||
|
||||
|
@ -1688,18 +1688,6 @@ struct FMiniBSP
|
|||
TArray<vertex_t> Verts;
|
||||
};
|
||||
|
||||
// Lightmap data
|
||||
|
||||
struct LightmapSurface
|
||||
{
|
||||
LevelMeshSurfaceType Type;
|
||||
subsector_t *Subsector;
|
||||
side_t *Side;
|
||||
sector_t *ControlSector;
|
||||
uint32_t LightmapNum;
|
||||
float *TexCoords;
|
||||
};
|
||||
|
||||
//
|
||||
// OTHER TYPES
|
||||
//
|
||||
|
|
|
@ -49,7 +49,7 @@ DoomLevelMesh::DoomLevelMesh(FLevelLocals &doomMap)
|
|||
MeshUVIndex.Push(j);
|
||||
}
|
||||
|
||||
if (s.type == ST_FLOOR || s.type == ST_CEILING)
|
||||
if (s.Type == ST_FLOOR || s.Type == ST_CEILING)
|
||||
{
|
||||
for (int j = 2; j < numVerts; j++)
|
||||
{
|
||||
|
@ -62,7 +62,7 @@ DoomLevelMesh::DoomLevelMesh(FLevelLocals &doomMap)
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (s.type == ST_MIDDLESIDE || s.type == ST_UPPERSIDE || s.type == ST_LOWERSIDE)
|
||||
else if (s.Type == ST_MIDDLESIDE || s.Type == ST_UPPERSIDE || s.Type == ST_LOWERSIDE)
|
||||
{
|
||||
if (!IsDegenerate(verts[0], verts[1], verts[2]))
|
||||
{
|
||||
|
@ -81,7 +81,6 @@ DoomLevelMesh::DoomLevelMesh(FLevelLocals &doomMap)
|
|||
}
|
||||
}
|
||||
|
||||
// To do: these functions still broken.
|
||||
SetupLightmapUvs();
|
||||
BindLightmapSurfacesToGeometry(doomMap);
|
||||
|
||||
|
@ -101,7 +100,7 @@ void DoomLevelMesh::BindLightmapSurfacesToGeometry(FLevelLocals& doomMap)
|
|||
allSurfaces += 2 + doomMap.subsectors[i].sector->e->XFloor.ffloors.Size() * 2;
|
||||
|
||||
doomMap.LMSurfaces.Resize(allSurfaces);
|
||||
memset(&doomMap.LMSurfaces[0], 0, sizeof(LightmapSurface) * allSurfaces);
|
||||
memset(&doomMap.LMSurfaces[0], 0, sizeof(DoomLevelMeshSurface*) * allSurfaces);
|
||||
|
||||
// Link the surfaces to sectors, sides and their 3D floors
|
||||
|
||||
|
@ -125,79 +124,72 @@ void DoomLevelMesh::BindLightmapSurfacesToGeometry(FLevelLocals& doomMap)
|
|||
size_t index = 0;
|
||||
for (auto& surface : Surfaces)
|
||||
{
|
||||
LightmapSurface l;
|
||||
memset(&l, 0, sizeof(LightmapSurface));
|
||||
surface.TexCoords = (float*)&LightmapUvs[surface.startUvIndex];
|
||||
|
||||
l.ControlSector = (sector_t*)surface.controlSector;
|
||||
l.Type = surface.type;
|
||||
l.LightmapNum = 0;
|
||||
surface.LightmapNum = surface.atlasPageIndex;
|
||||
|
||||
l.TexCoords = (float*)&LightmapUvs[surface.startUvIndex];
|
||||
|
||||
l.LightmapNum = surface.atlasPageIndex;
|
||||
|
||||
if (surface.type == ST_FLOOR || surface.type == ST_CEILING)
|
||||
if (surface.Type == ST_FLOOR || surface.Type == ST_CEILING)
|
||||
{
|
||||
l.Subsector = &doomMap.subsectors[surface.typeIndex];
|
||||
if (l.Subsector->firstline && l.Subsector->firstline->sidedef)
|
||||
l.Subsector->firstline->sidedef->sector->HasLightmaps = true;
|
||||
SetSubsectorLightmap(l);
|
||||
surface.Subsector = &doomMap.subsectors[surface.typeIndex];
|
||||
if (surface.Subsector->firstline && surface.Subsector->firstline->sidedef)
|
||||
surface.Subsector->firstline->sidedef->sector->HasLightmaps = true;
|
||||
SetSubsectorLightmap(&surface);
|
||||
}
|
||||
else
|
||||
{
|
||||
l.Side = &doomMap.sides[surface.typeIndex];
|
||||
SetSideLightmap(l);
|
||||
surface.Side = &doomMap.sides[surface.typeIndex];
|
||||
SetSideLightmap(&surface);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DoomLevelMesh::SetSubsectorLightmap(const LightmapSurface& surface)
|
||||
void DoomLevelMesh::SetSubsectorLightmap(DoomLevelMeshSurface* surface)
|
||||
{
|
||||
if (!surface.ControlSector)
|
||||
if (!surface->ControlSector)
|
||||
{
|
||||
int index = surface.Type == ST_CEILING ? 1 : 0;
|
||||
surface.Subsector->lightmap[index][0] = surface;
|
||||
int index = surface->Type == ST_CEILING ? 1 : 0;
|
||||
surface->Subsector->lightmap[index][0] = surface;
|
||||
}
|
||||
else
|
||||
{
|
||||
int index = surface.Type == ST_CEILING ? 0 : 1;
|
||||
const auto& ffloors = surface.Subsector->sector->e->XFloor.ffloors;
|
||||
int index = surface->Type == ST_CEILING ? 0 : 1;
|
||||
const auto& ffloors = surface->Subsector->sector->e->XFloor.ffloors;
|
||||
for (unsigned int i = 0; i < ffloors.Size(); i++)
|
||||
{
|
||||
if (ffloors[i]->model == surface.ControlSector)
|
||||
if (ffloors[i]->model == surface->ControlSector)
|
||||
{
|
||||
surface.Subsector->lightmap[index][i + 1] = surface;
|
||||
surface->Subsector->lightmap[index][i + 1] = surface;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DoomLevelMesh::SetSideLightmap(const LightmapSurface& surface)
|
||||
void DoomLevelMesh::SetSideLightmap(DoomLevelMeshSurface* surface)
|
||||
{
|
||||
if (!surface.ControlSector)
|
||||
if (!surface->ControlSector)
|
||||
{
|
||||
if (surface.Type == ST_UPPERSIDE)
|
||||
if (surface->Type == ST_UPPERSIDE)
|
||||
{
|
||||
surface.Side->lightmap[0] = surface;
|
||||
surface->Side->lightmap[0] = surface;
|
||||
}
|
||||
else if (surface.Type == ST_MIDDLESIDE)
|
||||
else if (surface->Type == ST_MIDDLESIDE)
|
||||
{
|
||||
surface.Side->lightmap[1] = surface;
|
||||
surface.Side->lightmap[2] = surface;
|
||||
surface->Side->lightmap[1] = surface;
|
||||
surface->Side->lightmap[2] = surface;
|
||||
}
|
||||
else if (surface.Type == ST_LOWERSIDE)
|
||||
else if (surface->Type == ST_LOWERSIDE)
|
||||
{
|
||||
surface.Side->lightmap[3] = surface;
|
||||
surface->Side->lightmap[3] = surface;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto& ffloors = surface.Side->sector->e->XFloor.ffloors;
|
||||
const auto& ffloors = surface->Side->sector->e->XFloor.ffloors;
|
||||
for (unsigned int i = 0; i < ffloors.Size(); i++)
|
||||
{
|
||||
if (ffloors[i]->model == surface.ControlSector)
|
||||
if (ffloors[i]->model == surface->ControlSector)
|
||||
{
|
||||
surface.Side->lightmap[4 + i] = surface;
|
||||
surface->Side->lightmap[4 + i] = surface;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -231,7 +223,7 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side)
|
|||
if (side->linedef->special == Line_Horizon && front != back)
|
||||
{
|
||||
DoomLevelMeshSurface surf;
|
||||
surf.type = ST_MIDDLESIDE;
|
||||
surf.Type = ST_MIDDLESIDE;
|
||||
surf.typeIndex = typeIndex;
|
||||
surf.bSky = front->GetTexture(sector_t::floor) == skyflatnum || front->GetTexture(sector_t::ceiling) == skyflatnum;
|
||||
|
||||
|
@ -277,9 +269,9 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side)
|
|||
continue;
|
||||
|
||||
DoomLevelMeshSurface surf;
|
||||
surf.type = ST_MIDDLESIDE;
|
||||
surf.Type = ST_MIDDLESIDE;
|
||||
surf.typeIndex = typeIndex;
|
||||
surf.controlSector = xfloor->model;
|
||||
surf.ControlSector = xfloor->model;
|
||||
surf.bSky = false;
|
||||
|
||||
FVector3 verts[4];
|
||||
|
@ -338,10 +330,10 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side)
|
|||
MeshVertices.Push(verts[3]);
|
||||
|
||||
surf.plane = ToPlane(verts[0], verts[1], verts[2]);
|
||||
surf.type = ST_LOWERSIDE;
|
||||
surf.Type = ST_LOWERSIDE;
|
||||
surf.typeIndex = typeIndex;
|
||||
surf.bSky = false;
|
||||
surf.controlSector = nullptr;
|
||||
surf.ControlSector = nullptr;
|
||||
|
||||
Surfaces.Push(surf);
|
||||
}
|
||||
|
@ -376,10 +368,10 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side)
|
|||
MeshVertices.Push(verts[3]);
|
||||
|
||||
surf.plane = ToPlane(verts[0], verts[1], verts[2]);
|
||||
surf.type = ST_UPPERSIDE;
|
||||
surf.Type = ST_UPPERSIDE;
|
||||
surf.typeIndex = typeIndex;
|
||||
surf.bSky = bSky;
|
||||
surf.controlSector = nullptr;
|
||||
surf.ControlSector = nullptr;
|
||||
|
||||
Surfaces.Push(surf);
|
||||
}
|
||||
|
@ -414,9 +406,9 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side)
|
|||
MeshVertices.Push(verts[3]);
|
||||
|
||||
surf.plane = ToPlane(verts[0], verts[1], verts[2]);
|
||||
surf.type = ST_MIDDLESIDE;
|
||||
surf.Type = ST_MIDDLESIDE;
|
||||
surf.typeIndex = typeIndex;
|
||||
surf.controlSector = nullptr;
|
||||
surf.ControlSector = nullptr;
|
||||
|
||||
Surfaces.Push(surf);
|
||||
}
|
||||
|
@ -453,9 +445,9 @@ void DoomLevelMesh::CreateFloorSurface(FLevelLocals &doomMap, subsector_t *sub,
|
|||
verts[j].Z = (float)plane.ZatPoint(verts[j]);
|
||||
}
|
||||
|
||||
surf.type = ST_FLOOR;
|
||||
surf.Type = ST_FLOOR;
|
||||
surf.typeIndex = typeIndex;
|
||||
surf.controlSector = is3DFloor ? sector : nullptr;
|
||||
surf.ControlSector = is3DFloor ? sector : nullptr;
|
||||
surf.plane = FVector4((float)plane.Normal().X, (float)plane.Normal().Y, (float)plane.Normal().Z, (float)plane.D);
|
||||
|
||||
Surfaces.Push(surf);
|
||||
|
@ -492,9 +484,9 @@ void DoomLevelMesh::CreateCeilingSurface(FLevelLocals &doomMap, subsector_t *sub
|
|||
verts[j].Z = (float)plane.ZatPoint(verts[j]);
|
||||
}
|
||||
|
||||
surf.type = ST_CEILING;
|
||||
surf.Type = ST_CEILING;
|
||||
surf.typeIndex = typeIndex;
|
||||
surf.controlSector = is3DFloor ? sector : nullptr;
|
||||
surf.ControlSector = is3DFloor ? sector : nullptr;
|
||||
surf.plane = FVector4((float)plane.Normal().X, (float)plane.Normal().Y, (float)plane.Normal().Z, (float)plane.D);
|
||||
|
||||
Surfaces.Push(surf);
|
||||
|
@ -661,7 +653,7 @@ void DoomLevelMesh::SetupLightmapUvs()
|
|||
// Reorder vertices into renderer format
|
||||
for (LevelMeshSurface& surface : Surfaces)
|
||||
{
|
||||
if (surface.type == ST_FLOOR)
|
||||
if (surface.Type == ST_FLOOR)
|
||||
{
|
||||
// reverse vertices on floor
|
||||
for (int j = surface.startUvIndex + surface.numVerts - 1, k = surface.startUvIndex; j > k; j--, k++)
|
||||
|
@ -669,7 +661,7 @@ void DoomLevelMesh::SetupLightmapUvs()
|
|||
std::swap(LightmapUvs[k], LightmapUvs[j]);
|
||||
}
|
||||
}
|
||||
else if (surface.type != ST_CEILING) // walls
|
||||
else if (surface.Type != ST_CEILING) // walls
|
||||
{
|
||||
// from 0 1 2 3
|
||||
// to 0 2 1 3
|
||||
|
|
|
@ -14,7 +14,11 @@ struct FLevelLocals;
|
|||
|
||||
struct DoomLevelMeshSurface : public LevelMeshSurface
|
||||
{
|
||||
sector_t* controlSector;
|
||||
subsector_t* Subsector;
|
||||
side_t* Side;
|
||||
sector_t* ControlSector;
|
||||
uint32_t LightmapNum; // To do: same as atlasPageIndex. Delete one of them!
|
||||
float* TexCoords;
|
||||
};
|
||||
|
||||
class DoomLevelMesh : public LevelMesh
|
||||
|
@ -53,8 +57,8 @@ private:
|
|||
void CreateSideSurfaces(FLevelLocals &doomMap, side_t *side);
|
||||
|
||||
void BindLightmapSurfacesToGeometry(FLevelLocals& doomMap);
|
||||
void SetSubsectorLightmap(const LightmapSurface& surface);
|
||||
void SetSideLightmap(const LightmapSurface& surface);
|
||||
void SetSubsectorLightmap(DoomLevelMeshSurface* surface);
|
||||
void SetSideLightmap(DoomLevelMeshSurface* surface);
|
||||
|
||||
static bool IsTopSideSky(sector_t* frontsector, sector_t* backsector, side_t* side);
|
||||
static bool IsTopSideVisible(side_t* side);
|
||||
|
|
|
@ -239,7 +239,7 @@ static int CreateIndexedSectorVerticesLM(FRenderState& renderstate, sector_t* se
|
|||
for (i = 0, pos = 0; i < sec->subsectorcount; i++)
|
||||
{
|
||||
subsector_t* sub = sec->subsectors[i];
|
||||
LightmapSurface* lightmap = &sub->lightmap[h][lightmapIndex];
|
||||
DoomLevelMeshSurface* lightmap = sub->lightmap[h][lightmapIndex];
|
||||
if (lightmap->Type != ST_UNKNOWN)
|
||||
{
|
||||
float* luvs = lightmap->TexCoords;
|
||||
|
|
|
@ -155,7 +155,7 @@ public:
|
|||
vertex_t * vertexes[2]; // required for polygon splitting
|
||||
FGameTexture *texture;
|
||||
TArray<lightlist_t> *lightlist;
|
||||
LightmapSurface *lightmap;
|
||||
DoomLevelMeshSurface* lightmap;
|
||||
|
||||
HWSeg glseg;
|
||||
float ztop[2],zbottom[2];
|
||||
|
|
|
@ -1264,7 +1264,7 @@ void HWWall::DoTexture(HWDrawInfo *di, FRenderState& state, int _type,seg_t * se
|
|||
|
||||
if (seg->sidedef->lightmap && type >= RENDERWALL_TOP && type <= RENDERWALL_BOTTOM)
|
||||
{
|
||||
lightmap = &seg->sidedef->lightmap[type - RENDERWALL_TOP];
|
||||
lightmap = seg->sidedef->lightmap[type - RENDERWALL_TOP];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1654,12 +1654,9 @@ void HWWall::BuildFFBlock(HWDrawInfo *di, FRenderState& state, seg_t * seg, F3DF
|
|||
|
||||
lightmap = nullptr;
|
||||
if (seg->sidedef == seg->linedef->sidedef[0])
|
||||
lightmap = seg->linedef->sidedef[1]->lightmap;
|
||||
lightmap = seg->linedef->sidedef[1]->lightmap[4 + roverIndex];
|
||||
else
|
||||
lightmap = seg->linedef->sidedef[0]->lightmap;
|
||||
|
||||
if (lightmap)
|
||||
lightmap += 4 + roverIndex;
|
||||
lightmap = seg->linedef->sidedef[0]->lightmap[4 + roverIndex];
|
||||
|
||||
if (rover->flags&FF_FOG)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue