Skip to content

Commit 0b30b4a

Browse files
dileepvrRicardoLuis0
authored andcommitted
Revert using older stencil method for stacked sectors (and reflective flats) if viewpoint is not allowed OoB. There was some bug with nearby skyplanes otherwise.
1 parent b0889b9 commit 0b30b4a

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

src/rendering/hwrenderer/scene/hw_portal.cpp

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ bool HWMirrorPortal::Setup(HWDrawInfo *di, FRenderState &rstate, Clipper *clippe
507507
}
508508

509509
auto &vp = di->Viewpoint;
510+
state->vpIsAllowedOoB = vp.IsAllowedOoB();
510511
di->UpdateCurrentMapSection();
511512

512513
di->mClipPortal = this;
@@ -611,6 +612,7 @@ bool HWLineToLinePortal::Setup(HWDrawInfo *di, FRenderState &rstate, Clipper *cl
611612
return false;
612613
}
613614
auto &vp = di->Viewpoint;
615+
state->vpIsAllowedOoB = vp.IsAllowedOoB();
614616
di->mClipPortal = this;
615617

616618
line_t *origin = glport->lines[0]->mOrigin;
@@ -690,6 +692,7 @@ bool HWSkyboxPortal::Setup(HWDrawInfo *di, FRenderState &rstate, Clipper *clippe
690692
return false;
691693
}
692694
auto &vp = di->Viewpoint;
695+
state->vpIsAllowedOoB = vp.IsAllowedOoB();
693696

694697
state->skyboxrecursion++;
695698
state->PlaneMirrorMode = 0;
@@ -801,6 +804,7 @@ bool HWSectorStackPortal::Setup(HWDrawInfo *di, FRenderState &rstate, Clipper *c
801804

802805
FSectorPortalGroup *portal = origin;
803806
auto &vp = di->Viewpoint;
807+
state->vpIsAllowedOoB = vp.IsAllowedOoB();
804808

805809
vp.Pos += origin->mDisplacement;
806810
vp.ActorPos += origin->mDisplacement;
@@ -836,16 +840,23 @@ bool HWSectorStackPortal::Setup(HWDrawInfo *di, FRenderState &rstate, Clipper *c
836840

837841
void HWSectorStackPortal::DrawPortalStencil(FRenderState &state, int pass)
838842
{
839-
bool isceiling = planesused & (1 << sector_t::ceiling);
840-
for (unsigned int i = 0; i < lines.Size(); i++)
843+
if (mState->vpIsAllowedOoB)
841844
{
842-
flat.section = lines[i].sub->section;
843-
flat.iboindex = lines[i].sub->sector->iboindex[isceiling ? sector_t::ceiling : sector_t::floor];
844-
flat.plane.GetFromSector(lines[i].sub->sector, isceiling ? sector_t::ceiling : sector_t::floor);
845-
// if (isceiling) flat.plane.plane.FlipVert(); // Doesn't do anything. Stencil is a screen-space projection
845+
bool isceiling = planesused & (1 << sector_t::ceiling);
846+
for (unsigned int i = 0; i < lines.Size(); i++)
847+
{
848+
flat.section = lines[i].sub->section;
849+
flat.iboindex = lines[i].sub->sector->iboindex[isceiling ? sector_t::ceiling : sector_t::floor];
850+
flat.plane.GetFromSector(lines[i].sub->sector, isceiling ? sector_t::ceiling : sector_t::floor);
851+
// if (isceiling) flat.plane.plane.FlipVert(); // Doesn't do anything. Stencil is a screen-space projection
846852

847-
state.SetNormal(flat.plane.plane.Normal().X, flat.plane.plane.Normal().Z, flat.plane.plane.Normal().Y);
848-
state.DrawIndexed(DT_Triangles, flat.iboindex + flat.section->vertexindex, flat.section->vertexcount, i == 0);
853+
state.SetNormal(flat.plane.plane.Normal().X, flat.plane.plane.Normal().Z, flat.plane.plane.Normal().Y);
854+
state.DrawIndexed(DT_Triangles, flat.iboindex + flat.section->vertexindex, flat.section->vertexcount, i == 0);
855+
}
856+
}
857+
else
858+
{
859+
HWPortal::DrawPortalStencil(state, pass);
849860
}
850861
}
851862

@@ -884,6 +895,7 @@ bool HWPlaneMirrorPortal::Setup(HWDrawInfo *di, FRenderState &rstate, Clipper *c
884895
std::swap(screen->instack[sector_t::floor], screen->instack[sector_t::ceiling]);
885896

886897
auto &vp = di->Viewpoint;
898+
state->vpIsAllowedOoB = vp.IsAllowedOoB();
887899
old_pm = state->PlaneMirrorMode;
888900

889901
// the player is always visible in a mirror.
@@ -908,16 +920,23 @@ bool HWPlaneMirrorPortal::Setup(HWDrawInfo *di, FRenderState &rstate, Clipper *c
908920

909921
void HWPlaneMirrorPortal::DrawPortalStencil(FRenderState &state, int pass)
910922
{
911-
bool isceiling = planesused & (1 << sector_t::ceiling);
912-
for (unsigned int i = 0; i < lines.Size(); i++)
923+
if (mState->vpIsAllowedOoB)
913924
{
914-
flat.section = lines[i].sub->section;
915-
flat.iboindex = lines[i].sub->sector->iboindex[isceiling ? sector_t::ceiling : sector_t::floor];
916-
flat.plane.GetFromSector(lines[i].sub->sector, isceiling ? sector_t::ceiling : sector_t::floor);
917-
// if (isceiling) flat.plane.plane.FlipVert(); // Doesn't do anything. Stencil is a screen-space projection
925+
bool isceiling = planesused & (1 << sector_t::ceiling);
926+
for (unsigned int i = 0; i < lines.Size(); i++)
927+
{
928+
flat.section = lines[i].sub->section;
929+
flat.iboindex = lines[i].sub->sector->iboindex[isceiling ? sector_t::ceiling : sector_t::floor];
930+
flat.plane.GetFromSector(lines[i].sub->sector, isceiling ? sector_t::ceiling : sector_t::floor);
931+
// if (isceiling) flat.plane.plane.FlipVert(); // Doesn't do anything. Stencil is a screen-space projection
918932

919-
state.SetNormal(flat.plane.plane.Normal().X, flat.plane.plane.Normal().Z, flat.plane.plane.Normal().Y);
920-
state.DrawIndexed(DT_Triangles, flat.iboindex + flat.section->vertexindex, flat.section->vertexcount, i == 0);
933+
state.SetNormal(flat.plane.plane.Normal().X, flat.plane.plane.Normal().Z, flat.plane.plane.Normal().Y);
934+
state.DrawIndexed(DT_Triangles, flat.iboindex + flat.section->vertexindex, flat.section->vertexcount, i == 0);
935+
}
936+
}
937+
else
938+
{
939+
HWPortal::DrawPortalStencil(state, pass);
921940
}
922941
}
923942

src/rendering/hwrenderer/scene/hw_portal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ class HWPortal
5959
TArray<unsigned int> mPrimIndices;
6060
unsigned int mTopCap = ~0u, mBottomCap = ~0u;
6161

62-
virtual void DrawPortalStencil(FRenderState &state, int pass);
63-
6462
public:
6563
FPortalSceneState * mState;
6664
TArray<HWWall> lines;
@@ -84,6 +82,7 @@ class HWPortal
8482
virtual bool NeedDepthBuffer() { return true; }
8583
virtual void DrawContents(HWDrawInfo *di, FRenderState &state) = 0;
8684
virtual void RenderAttached(HWDrawInfo *di) {}
85+
virtual void DrawPortalStencil(FRenderState &state, int pass);
8786
void SetupStencil(HWDrawInfo *di, FRenderState &state, bool usestencil);
8887
void RemoveStencil(HWDrawInfo *di, FRenderState &state, bool usestencil);
8988

@@ -106,6 +105,7 @@ struct FPortalSceneState
106105

107106
int PlaneMirrorMode = 0;
108107
bool inskybox = 0;
108+
bool vpIsAllowedOoB = 0;
109109

110110
UniqueList<HWSkyInfo> UniqueSkies;
111111
UniqueList<HWHorizonInfo> UniqueHorizons;

0 commit comments

Comments
 (0)