From 9375750a17e72617ea50840c34d380a9b38b4280 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 13 Jan 2022 20:55:55 +0100 Subject: [PATCH] - added sorting for wall sprites attached to non-orthogonal walls. --- source/core/rendering/scene/hw_drawinfo.cpp | 8 +++++++ source/core/rendering/scene/hw_drawinfo.h | 3 ++- source/core/rendering/scene/hw_drawlist.cpp | 24 +++++++++++++++++++ source/core/rendering/scene/hw_drawlist.h | 1 + .../core/rendering/scene/hw_drawlistadd.cpp | 2 +- 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/source/core/rendering/scene/hw_drawinfo.cpp b/source/core/rendering/scene/hw_drawinfo.cpp index e1035283a..e44dcb900 100644 --- a/source/core/rendering/scene/hw_drawinfo.cpp +++ b/source/core/rendering/scene/hw_drawinfo.cpp @@ -520,12 +520,20 @@ void HWDrawInfo::RenderScene(FRenderState &state) drawlists[GLDL_MASKEDFLATS].SortFlats(this); drawlists[GLDL_MASKEDWALLSV].SortWallsHorz(this); drawlists[GLDL_MASKEDWALLSH].SortWallsVert(this); + drawlists[GLDL_MASKEDWALLSD].SortWallsDiag(this); // these lists are only wall and floor sprites - often attached to walls and floors - so they need to be offset from the plane they may be attached to. drawlists[GLDL_MASKEDWALLSS].DrawWalls(this, state, false); // Each list must draw both its passes before the next one to ensure proper depth buffer contents. + state.SetDepthMask(false); + drawlists[GLDL_MASKEDWALLSD].DrawWalls(this, state, false); + state.SetDepthMask(true); + state.SetColorMask(false); + drawlists[GLDL_MASKEDWALLSD].DrawWalls(this, state, false); + state.SetColorMask(true); + state.SetDepthMask(false); drawlists[GLDL_MASKEDWALLSV].DrawWalls(this, state, false); state.SetDepthMask(true); diff --git a/source/core/rendering/scene/hw_drawinfo.h b/source/core/rendering/scene/hw_drawinfo.h index 600836ecc..cc9cf3114 100644 --- a/source/core/rendering/scene/hw_drawinfo.h +++ b/source/core/rendering/scene/hw_drawinfo.h @@ -75,7 +75,8 @@ enum DrawListType GLDL_PLAINWALLS, GLDL_PLAINFLATS, GLDL_MASKEDWALLS, - GLDL_MASKEDWALLSS, // arbitrary wall sprites. + GLDL_MASKEDWALLSS, // arbitrary wall sprites, not attached to walls + GLDL_MASKEDWALLSD, // arbitrary wall sprites, attached to walls. GLDL_MASKEDWALLSV, // vertical wall sprites GLDL_MASKEDWALLSH, // horizontal wall sprites. These two lists merely exist for easier sorting. GLDL_MASKEDFLATS, diff --git a/source/core/rendering/scene/hw_drawlist.cpp b/source/core/rendering/scene/hw_drawlist.cpp index 1630cedee..168debfea 100644 --- a/source/core/rendering/scene/hw_drawlist.cpp +++ b/source/core/rendering/scene/hw_drawlist.cpp @@ -910,6 +910,30 @@ void HWDrawList::SortWallsHorz(HWDrawInfo* di) } } +//========================================================================== +// +// all we need to do here is to group the sprites by wall. +// +//========================================================================== + +void HWDrawList::SortWallsDiag(HWDrawInfo* di) +{ + auto viewx = di->Viewpoint.Pos.X; + if (drawitems.Size() > 1) + { + std::sort(drawitems.begin(), drawitems.end(), [=](const HWDrawItem& a, const HWDrawItem& b) + { + HWWall* w1 = walls[a.index]; + HWWall* w2 = walls[b.index]; + if (w1->walldist != w2->walldist) return w1->walldist < w2->walldist; + int time1 = w1->Sprite ? w1->Sprite->time : -1; + int time2 = w2->Sprite ? w2->Sprite->time : -1; + return time1 < time2; + }); + + } +} + //========================================================================== // // diff --git a/source/core/rendering/scene/hw_drawlist.h b/source/core/rendering/scene/hw_drawlist.h index ab24c184f..ad0b692cd 100644 --- a/source/core/rendering/scene/hw_drawlist.h +++ b/source/core/rendering/scene/hw_drawlist.h @@ -93,6 +93,7 @@ public: HWFlat *NewFlat(bool slopespr = false); HWSprite *NewSprite(); void Reset(); + void SortWallsDiag(HWDrawInfo* di); void SortWallsHorz(HWDrawInfo* di); void SortWallsVert(HWDrawInfo* di); void SortFlats(HWDrawInfo* di); diff --git a/source/core/rendering/scene/hw_drawlistadd.cpp b/source/core/rendering/scene/hw_drawlistadd.cpp index cee0ff943..720aafa9c 100644 --- a/source/core/rendering/scene/hw_drawlistadd.cpp +++ b/source/core/rendering/scene/hw_drawlistadd.cpp @@ -53,7 +53,7 @@ void HWDrawInfo::AddWall(HWWall *wall) else if (wall->Sprite == nullptr) list = GLDL_MASKEDWALLS; else if (wall->glseg.x1 == wall->glseg.x2) list = GLDL_MASKEDWALLSV; else if (wall->glseg.y1 == wall->glseg.y2) list = GLDL_MASKEDWALLSH; - else list = GLDL_MASKEDWALLSS; + else list = wall->walldist? GLDL_MASKEDWALLSD : GLDL_MASKEDWALLSS; auto newwall = drawlists[list].NewWall(); *newwall = *wall; }