Skip to content

Commit

Permalink
Fix func_fake_worldportal clip plane
Browse files Browse the repository at this point in the history
  • Loading branch information
samisalreadytaken committed Nov 17, 2022
1 parent 3bcda90 commit d32aded
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions sp/src/game/client/mapbase/c_func_fake_worldportal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ bool C_FuncFakeWorldPortal::ShouldDraw()
// Iterates through fake world portals instead of just picking one
//-----------------------------------------------------------------------------
C_FuncFakeWorldPortal *NextFakeWorldPortal( C_FuncFakeWorldPortal *pStart, const CViewSetup& view,
Vector &vecAbsPlaneNormal, Vector &vecPlaneLocalOrigin, const Frustum_t &frustum )
Vector &vecAbsPlaneNormal, float &flLocalPlaneDist, const Frustum_t &frustum )
{
// Early out if no cameras
C_FuncFakeWorldPortal *pReflectiveGlass = NULL;
Expand Down Expand Up @@ -109,7 +109,7 @@ C_FuncFakeWorldPortal *NextFakeWorldPortal( C_FuncFakeWorldPortal *pStart, const
if ( vecDelta.Dot( worldPlane.normal ) >= 0 ) // Backface cull
continue;

vecPlaneLocalOrigin = vecLocalOrigin;
flLocalPlaneDist = localPlane.dist;
vecAbsPlaneNormal = worldPlane.normal;

return pReflectiveGlass;
Expand Down
2 changes: 1 addition & 1 deletion sp/src/game/client/mapbase/c_func_fake_worldportal.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class C_FuncFakeWorldPortal : public C_BaseEntity
// Do we have reflective glass in view? If so, what's the reflection plane?
//-----------------------------------------------------------------------------
C_FuncFakeWorldPortal *NextFakeWorldPortal( C_FuncFakeWorldPortal *pStart, const CViewSetup& view,
Vector &vecAbsPlaneNormal, Vector &vecPlaneOrigin, const Frustum_t &frustum );
Vector &vecAbsPlaneNormal, float &flLocalPlaneDist, const Frustum_t &frustum );


#endif // C_FUNC_FAKE_WORLDPORTAL
Expand Down
20 changes: 10 additions & 10 deletions sp/src/game/client/viewrender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2107,17 +2107,17 @@ void CViewRender::RenderView( const CViewSetup &view, int nClearFlags, int whatT
GeneratePerspectiveFrustum( view.origin, view.angles, view.zNear, view.zFar, view.fov, view.m_flAspectRatio, frustum );

Vector vecAbsPlaneNormal;
Vector vecPlaneLocalOrigin;
C_FuncFakeWorldPortal *pPortalEnt = NextFakeWorldPortal( NULL, view, vecAbsPlaneNormal, vecPlaneLocalOrigin, frustum );
float flLocalPlaneDist;
C_FuncFakeWorldPortal *pPortalEnt = NextFakeWorldPortal( NULL, view, vecAbsPlaneNormal, flLocalPlaneDist, frustum );
while ( pPortalEnt != NULL )
{
ITexture *pCameraTarget = pPortalEnt->RenderTarget();
int width = pCameraTarget->GetActualWidth();
int height = pCameraTarget->GetActualHeight();

DrawFakeWorldPortal( pCameraTarget, pPortalEnt, viewMiddle, C_BasePlayer::GetLocalPlayer(), 0, 0, width, height, view, vecAbsPlaneNormal, vecPlaneLocalOrigin );
DrawFakeWorldPortal( pCameraTarget, pPortalEnt, viewMiddle, C_BasePlayer::GetLocalPlayer(), 0, 0, width, height, view, vecAbsPlaneNormal, flLocalPlaneDist );

pPortalEnt = NextFakeWorldPortal( pPortalEnt, view, vecAbsPlaneNormal, vecPlaneLocalOrigin, frustum );
pPortalEnt = NextFakeWorldPortal( pPortalEnt, view, vecAbsPlaneNormal, flLocalPlaneDist, frustum );
}
#endif
}
Expand Down Expand Up @@ -3551,7 +3551,7 @@ bool CViewRender::DrawOneMonitor( ITexture *pRenderTarget, int cameraNum, C_Poin
//-----------------------------------------------------------------------------
bool CViewRender::DrawFakeWorldPortal( ITexture *pRenderTarget, C_FuncFakeWorldPortal *pCameraEnt, const CViewSetup &cameraView, C_BasePlayer *localPlayer,
int x, int y, int width, int height,
const CViewSetup &mainView, const Vector &vecAbsPlaneNormal, const Vector &vecPlaneLocalOrigin )
const CViewSetup &mainView, const Vector &vecAbsPlaneNormal, float flLocalPlaneDist )
{
#ifdef USE_MONITORS
VPROF_INCREMENT_COUNTER( "cameras rendered", 1 );
Expand Down Expand Up @@ -3652,15 +3652,15 @@ bool CViewRender::DrawFakeWorldPortal( ITexture *pRenderTarget, C_FuncFakeWorldP

Vector4D plane;

// target direction
MatrixGetColumn( targetToWorld, 0, plane.AsVector3D() );
VectorNormalize( plane.AsVector3D() );
VectorNegate( plane.AsVector3D() );

// The portal plane's distance from the actual brush's origin
float flPlaneDist = vecPlaneLocalOrigin.Length();

// The target's distance from world origin
plane.w = -((pCameraEnt->m_hTargetPlane->GetAbsOrigin() * plane.AsVector3D()).Length() + flPlaneDist) + 0.1f;
plane.w =
MatrixColumnDotProduct( targetToWorld, 3, plane.AsVector3D() ) // target clip plane distance
- flLocalPlaneDist // portal plane distance on the brush. This distance needs to be accounted for while placing the exit target
- 0.1;

CMatRenderContextPtr pRenderContext( materials );
pRenderContext->PushCustomClipPlane( plane.Base() );
Expand Down
2 changes: 1 addition & 1 deletion sp/src/game/client/viewrender.h
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ class CViewRender : public IViewRender,
#ifdef MAPBASE
bool DrawFakeWorldPortal( ITexture *pRenderTarget, C_FuncFakeWorldPortal *pCameraEnt, const CViewSetup &cameraView, C_BasePlayer *localPlayer,
int x, int y, int width, int height,
const CViewSetup &mainView, const Vector &vecAbsPlaneNormal, const Vector &vecPlaneOrigin );
const CViewSetup &mainView, const Vector &vecAbsPlaneNormal, float flLocalPlaneDist );
#endif

// Drawing primitives
Expand Down

0 comments on commit d32aded

Please sign in to comment.