Draw decals

This commit is contained in:
Magnus Norddahl 2025-06-01 01:06:51 +02:00
commit 88c57a6677
5 changed files with 29 additions and 48 deletions

View file

@ -334,22 +334,39 @@ void DoomLevelMesh::AddSidesToDrawLists(const TArray<int>& sides, LevelMeshDrawL
{
for (int sideIndex : sides)
{
if (!Sides[sideIndex].NeedsImmediateRendering)
auto& sideInfo = Sides[sideIndex];
if (!sideInfo.NeedsImmediateRendering)
{
for (const DrawRangeInfo& di : Sides[sideIndex].DrawRanges)
for (const DrawRangeInfo& di : sideInfo.DrawRanges)
{
lists.Add(di.DrawType, di.PipelineID, { di.IndexStart, di.IndexStart + di.IndexCount });
}
for (const HWMissing& missing : Sides[sideIndex].MissingUpper)
for (const HWMissing& missing : sideInfo.MissingUpper)
{
di->AddUpperMissingTexture(missing.side, missing.sub, missing.plane);
}
for (const HWMissing& missing : Sides[sideIndex].MissingLower)
for (const HWMissing& missing : sideInfo.MissingLower)
{
di->AddLowerMissingTexture(missing.side, missing.sub, missing.plane);
}
auto& decals = sideInfo.Decals;
if (decals.Size() != 0)
{
int dynlightindex = -1;
if (di->Level->HasDynamicLights && !di->isFullbrightScene() && decals[0].texture != nullptr && !lm_dynlights)
{
dynlightindex = decals[0].SetupLights(di, state, lightdata, level.sides[sideIndex].lighthead);
}
for (const HWDecalCreateInfo& info : decals)
{
info.ProcessDecal(di, state, dynlightindex);
}
}
}
else
{
@ -494,27 +511,6 @@ TArray<HWWall>& DoomLevelMesh::GetSidePortals(int sideIndex)
return Sides[sideIndex].WallPortals;
}
void DoomLevelMesh::ProcessDecals(HWDrawInfo* di, FRenderState& state)
{
for (int sideIndex : level.levelMesh->SideDecals)
{
const auto& side = Sides[sideIndex];
if (side.Decals.Size() == 0)
continue;
int dynlightindex = -1;
if (di->Level->HasDynamicLights && !di->isFullbrightScene() && side.Decals[0].texture != nullptr && !lm_dynlights)
{
dynlightindex = side.Decals[0].SetupLights(di, state, lightdata, level.sides[sideIndex].lighthead);
}
for (const HWDecalCreateInfo& info : side.Decals)
{
info.ProcessDecal(di, state, dynlightindex);
}
}
}
int DoomLevelMesh::GetLightIndex(FDynamicLight* light, int portalgroup)
{
int index;
@ -1068,12 +1064,6 @@ void DoomLevelMesh::CreateSide(FLevelLocals& doomMap, unsigned int sideIndex)
wall.Process(&disp, state, seg, front, back);
// Grab the decals generated
if (result.decals.Size() != 0 && !sideBlock.InSideDecalsList)
{
SideDecals.Push(sideIndex);
sideBlock.InSideDecalsList = true;
}
sideBlock.Decals = result.decals;
state.SetDepthMask(true);
@ -1097,10 +1087,6 @@ void DoomLevelMesh::CreateSide(FLevelLocals& doomMap, unsigned int sideIndex)
CreateWallSurface(side, disp, state, result.maskedOffset, LevelMeshDrawType::MaskedOffset, sideIndex, sideBlock.Lights);
state.ClearDepthBias();
// Part 4: Draw decals (not a real pass)
state.SetDepthFunc(DF_LEqual);
// DrawDecals(state, Decals[0]);
// These things aren't working properly with the level mesh.
bool incompatible = false;
for (const HWWall& wall : result.opaque)

View file

@ -150,15 +150,11 @@ public:
void BuildSectorGroups(const FLevelLocals& doomMap);
void ProcessDecals(HWDrawInfo* drawinfo, FRenderState& state);
void AddSectorsToDrawLists(const TArray<int>& sectors, LevelMeshDrawLists& lists);
void AddSidesToDrawLists(const TArray<int>& sides, LevelMeshDrawLists& lists, HWDrawInfo* di, FRenderState& state);
TArray<HWWall>& GetSidePortals(int sideIndex);
TArray<int> SideDecals;
TArray<int> sectorGroup; // index is sector, value is sectorGroup
TArray<int> sectorPortals[2]; // index is sector+plane, value is index into the portal list
TArray<int> linePortals; // index is linedef, value is index into the portal list

View file

@ -441,6 +441,14 @@ HWDecal *HWDrawInfo::AddDecal(bool onmirror)
void HWDrawInfo::RenderPVS(bool drawpsprites, FRenderState& state)
{
SeenSectors.Clear();
SeenSides.Clear();
SeenSubsectors.Clear();
SeenHackedSubsectors.Clear();
SeenSubsectorPortals.Clear();
SeenFlatsDrawLists.Clear();
SeenSidesDrawLists.Clear();
if (Viewpoint.IsOrtho() || !(gl_levelmesh && !outer))
{
RenderBSP(Level->HeadNode(), drawpsprites, state);
@ -508,8 +516,6 @@ void HWDrawInfo::RenderPVS(bool drawpsprites, FRenderState& state)
if (gl_levelmesh)
level.levelMesh->CurFrameStats.Portals++;
SeenFlatsDrawLists.Clear();
SeenSidesDrawLists.Clear();
level.levelMesh->AddSectorsToDrawLists(SeenSectors.Get(), SeenFlatsDrawLists);
level.levelMesh->AddSidesToDrawLists(SeenSides.Get(), SeenSidesDrawLists, this, state);

View file

@ -228,8 +228,6 @@ struct HWDrawInfo
VisList SeenSectors, SeenSides, SeenSubsectors, SeenHackedSubsectors, SeenSubsectorPortals;
LevelMeshDrawLists SeenFlatsDrawLists, SeenSidesDrawLists;
TArray<bool> QueryResultsBuffer;
HWDrawInfo(HWDrawContext* drawctx) : drawctx(drawctx) { for (HWDrawList& list : drawlists) list.drawctx = drawctx; }
void WorkerThread();

View file

@ -579,11 +579,6 @@ void HWVisibleSetThreads::FindPVS(HWDrawInfo* di)
WTTotal.Unclock();
// Merge results
di->SeenSectors.Clear();
di->SeenSides.Clear();
di->SeenSubsectors.Clear();
di->SeenHackedSubsectors.Clear();
di->SeenSubsectorPortals.Clear();
for (int i = 0; i < SliceCount; i++)
{
if (gl_debug_slice != -1 && gl_debug_slice < SliceCount)