Plane shadow vertices must be created after the level mesh, otherwise they do not receive the lightmap UV coordinates

This commit is contained in:
Magnus Norddahl 2023-12-16 01:20:03 +01:00
commit 1f6356f414
4 changed files with 25 additions and 25 deletions

View file

@ -3709,13 +3709,6 @@ void MapLoader::LoadLevel(MapData *map, const char *lumpname, int position)
}
InitRenderInfo(); // create hardware independent renderer resources for the level. This must be done BEFORE the PolyObj Spawn!!!
Level->ClearDynamic3DFloorData(); // CreateVBO must be run on the plain 3D floor data.
CreateVBO(*screen->RenderState(), Level->sectors);
for (auto &sec : Level->sectors)
{
P_Recalculate3DFloors(&sec);
}
SWRenderer->SetColormap(Level); //The SW renderer needs to do some special setup for the level's default colormap.
InitPortalGroups(Level);
@ -3728,5 +3721,12 @@ void MapLoader::LoadLevel(MapData *map, const char *lumpname, int position)
InitLevelMesh(map);
Level->ClearDynamic3DFloorData(); // CreateVBO must be run on the plain 3D floor data.
CreateVBO(*screen->RenderState(), Level->sectors);
for (auto& sec : Level->sectors)
{
P_Recalculate3DFloors(&sec);
}
Level->aabbTree = new DoomLevelAABBTree(Level);
}

View file

@ -115,19 +115,19 @@ void DoomLevelSubmesh::CreateStaticSurfaces(FLevelLocals& doomMap)
state.EnableTexture(true);
state.EnableBrightmap(true);
state.AlphaFunc(Alpha_GEqual, 0.f);
CreateWallSurface(side, disp, state, result.list);
CreateWallSurface(side, disp, state, result.list, false, true);
for (HWWall& portal : result.portals)
{
Portals.Push(portal);
}
CreateWallSurface(side, disp, state, result.portals, true);
CreateWallSurface(side, disp, state, result.portals, true, false);
// final pass: translucent stuff
state.AlphaFunc(Alpha_GEqual, gl_mask_sprite_threshold);
state.SetRenderStyle(STYLE_Translucent);
CreateWallSurface(side, disp, state, result.translucent);
CreateWallSurface(side, disp, state, result.translucent, false, true);
state.AlphaFunc(Alpha_GEqual, 0.f);
state.SetRenderStyle(STYLE_Normal);
}
@ -171,7 +171,7 @@ void DoomLevelSubmesh::CreateStaticSurfaces(FLevelLocals& doomMap)
}
}
void DoomLevelSubmesh::CreateWallSurface(side_t* side, HWWallDispatcher& disp, MeshBuilder& state, TArray<HWWall>& list, bool isSky)
void DoomLevelSubmesh::CreateWallSurface(side_t* side, HWWallDispatcher& disp, MeshBuilder& state, TArray<HWWall>& list, bool isSky, bool translucent)
{
for (HWWall& wallpart : list)
{
@ -202,7 +202,7 @@ void DoomLevelSubmesh::CreateWallSurface(side_t* side, HWWallDispatcher& disp, M
state.AlphaFunc(Alpha_GEqual, 0.f);
}
wallpart.DrawWall(&disp, state, false);
wallpart.DrawWall(&disp, state, translucent);
}
int pipelineID = 0;

View file

@ -64,7 +64,7 @@ private:
void CreateIndexes();
void CreateWallSurface(side_t* side, HWWallDispatcher& disp, MeshBuilder& state, TArray<HWWall>& list, bool isSky = false);
void CreateWallSurface(side_t* side, HWWallDispatcher& disp, MeshBuilder& state, TArray<HWWall>& list, bool isSky, bool translucent);
void CreateFlatSurface(HWFlatDispatcher& disp, MeshBuilder& state, TArray<HWFlat>& list, bool isSky = false);
static FVector4 ToPlane(const FVector3& pt1, const FVector3& pt2, const FVector3& pt3)

View file

@ -214,7 +214,7 @@ static void SetFlatVertex(FFlatVertex& ffv, vertex_t* vt, const secplane_t& plan
//
//==========================================================================
static int CreateIndexedSectorVerticesLM(FRenderState& renderstate, sector_t* sec, const secplane_t& plane, int floor, int h, int lightmapIndex)
static int CreateIndexedSectorVerticesLM(sector_t* sec, const secplane_t& plane, int floor, int h, int lightmapIndex)
{
int i, pos;
float diff;
@ -287,10 +287,10 @@ static int CreateIndexedSectorVerticesLM(FRenderState& renderstate, sector_t* se
return rt;
}
static int CreateIndexedSectorVertices(FRenderState& renderstate, sector_t* sec, const secplane_t& plane, int floor, VertexContainer& verts, int h, int lightmapIndex)
static int CreateIndexedSectorVertices(sector_t* sec, const secplane_t& plane, int floor, VertexContainer& verts, int h, int lightmapIndex)
{
if (sec->HasLightmaps && lightmapIndex != -1)
return CreateIndexedSectorVerticesLM(renderstate, sec, plane, floor, h, lightmapIndex);
return CreateIndexedSectorVerticesLM(sec, plane, floor, h, lightmapIndex);
auto& vbo_shadowdata = sector_vertices;
unsigned vi = vbo_shadowdata.Reserve(verts.vertices.Size());
@ -320,21 +320,21 @@ static int CreateIndexedSectorVertices(FRenderState& renderstate, sector_t* sec,
//
//==========================================================================
static int CreateIndexedVertices(FRenderState& renderstate, int h, sector_t* sec, const secplane_t& plane, int floor, VertexContainers& verts)
static int CreateIndexedVertices(int h, sector_t* sec, const secplane_t& plane, int floor, VertexContainers& verts)
{
auto& vbo_shadowdata = sector_vertices;
sec->vboindex[h] = vbo_shadowdata.Size();
// First calculate the vertices for the sector itself
sec->vboheight[h] = sec->GetPlaneTexZ(h);
sec->ibocount = verts[sec->Index()].indices.Size();
sec->iboindex[h] = CreateIndexedSectorVertices(renderstate, sec, plane, floor, verts[sec->Index()], h, 0);
sec->iboindex[h] = CreateIndexedSectorVertices(sec, plane, floor, verts[sec->Index()], h, 0);
// Next are all sectors using this one as heightsec
TArray<sector_t*>& fakes = sec->e->FakeFloor.Sectors;
for (unsigned g = 0; g < fakes.Size(); g++)
{
sector_t* fsec = fakes[g];
fsec->iboindex[2 + h] = CreateIndexedSectorVertices(renderstate, fsec, plane, false, verts[fsec->Index()], h, -1);
fsec->iboindex[2 + h] = CreateIndexedSectorVertices(fsec, plane, false, verts[fsec->Index()], h, -1);
}
// and finally all attached 3D floors
@ -352,7 +352,7 @@ static int CreateIndexedVertices(FRenderState& renderstate, int h, sector_t* sec
if (dotop || dobottom)
{
auto ndx = CreateIndexedSectorVertices(renderstate, fsec, plane, false, verts[fsec->Index()], h, ffloorIndex + 1);
auto ndx = CreateIndexedSectorVertices(fsec, plane, false, verts[fsec->Index()], h, ffloorIndex + 1);
if (dotop) ffloor->top.vindex = ndx;
if (dobottom) ffloor->bottom.vindex = ndx;
}
@ -369,7 +369,7 @@ static int CreateIndexedVertices(FRenderState& renderstate, int h, sector_t* sec
//
//==========================================================================
static void CreateIndexedFlatVertices(FRenderState& renderstate, TArray<sector_t>& sectors)
static void CreateIndexedFlatVertices(TArray<sector_t>& sectors)
{
auto verts = BuildVertices(sectors);
@ -398,7 +398,7 @@ static void CreateIndexedFlatVertices(FRenderState& renderstate, TArray<sector_t
{
for (auto& sec : sectors)
{
CreateIndexedVertices(renderstate, h, &sec, sec.GetSecPlane(h), h == sector_t::floor, verts);
CreateIndexedVertices(h, &sec, sec.GetSecPlane(h), h == sector_t::floor, verts);
}
}
@ -447,10 +447,10 @@ static void UpdatePlaneVertices(FRenderState& renderstate, sector_t* sec, int pl
//
//==========================================================================
static void CreateVertices(FRenderState& renderstate, TArray<sector_t>& sectors)
static void CreateVertices(TArray<sector_t>& sectors)
{
sector_vertices.Clear();
CreateIndexedFlatVertices(renderstate, sectors);
CreateIndexedFlatVertices(sectors);
}
//==========================================================================
@ -498,6 +498,6 @@ void CheckUpdate(FRenderState& renderstate, sector_t* sector)
void CreateVBO(FRenderState& renderstate, TArray<sector_t>& sectors)
{
sector_vertices.Clear();
CreateVertices(renderstate, sectors);
CreateVertices(sectors);
renderstate.SetShadowData(sector_vertices, sector_indexes);
}