@@ -805,17 +805,26 @@ bool HWSectorStackPortal::Setup(HWDrawInfo *di, FRenderState &rstate, Clipper *c
805
805
vp.Pos += origin->mDisplacement ;
806
806
vp.ActorPos += origin->mDisplacement ;
807
807
vp.ViewActor = nullptr ;
808
+ vp.OffPos += origin->mDisplacement ;
808
809
809
810
// avoid recursions!
810
811
if (origin->plane != -1 ) screen->instack [origin->plane ]++;
811
-
812
+ if (lines.Size () > 0 )
813
+ {
814
+ flat.plane .GetFromSector (lines[0 ].sub ->sector ,
815
+ lines[0 ].sub ->sector ->GetPortal (sector_t ::ceiling)->mType & (PORTS_STACKEDSECTORTHING | PORTS_PORTAL | PORTS_LINKEDPORTAL) ?
816
+ sector_t ::ceiling : sector_t ::floor );
817
+ di->SetClipHeight (flat.plane .plane .ZatPoint (vp.Pos ),
818
+ flat.plane .plane .Normal ().Z > 0 ? -1 .f : 1 .f );
819
+ }
812
820
di->SetupView (rstate, vp.Pos .X , vp.Pos .Y , vp.Pos .Z , !!(state->MirrorFlag & 1 ), !!(state->PlaneMirrorFlag & 1 ));
813
821
SetupCoverage (di);
814
822
ClearClipper (di, clipper);
815
823
816
824
// If the viewpoint is not within the portal, we need to invalidate the entire clip area.
817
825
// The portal will re-validate the necessary parts when its subsectors get traversed.
818
826
subsector_t *sub = di->Level ->PointInRenderSubsector (vp.Pos );
827
+ if (vp.IsAllowedOoB ()) sub = di->Level ->PointInRenderSubsector (vp.OffPos );
819
828
if (!(di->ss_renderflags [sub->Index ()] & SSRF_SEEN))
820
829
{
821
830
clipper->SafeAddClipRange (0 , ANGLE_MAX);
@@ -825,6 +834,22 @@ bool HWSectorStackPortal::Setup(HWDrawInfo *di, FRenderState &rstate, Clipper *c
825
834
}
826
835
827
836
837
+ void HWSectorStackPortal::DrawPortalStencil (FRenderState &state, int pass)
838
+ {
839
+ bool isceiling = planesused & (1 << sector_t ::ceiling);
840
+ for (unsigned int i = 0 ; i < lines.Size (); i++)
841
+ {
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
846
+
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 );
849
+ }
850
+ }
851
+
852
+
828
853
void HWSectorStackPortal::Shutdown (HWDrawInfo *di, FRenderState &rstate)
829
854
{
830
855
if (origin->plane != -1 ) screen->instack [origin->plane ]--;
0 commit comments