Fix func_fake_worldportal clip plane

This commit is contained in:
samisalreadytaken 2022-11-17 08:48:12 +03:00
parent cc0c90693d
commit 1ca7558421
4 changed files with 14 additions and 14 deletions

View File

@ -62,7 +62,7 @@ bool C_FuncFakeWorldPortal::ShouldDraw()
// Iterates through fake world portals instead of just picking one // Iterates through fake world portals instead of just picking one
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
C_FuncFakeWorldPortal *NextFakeWorldPortal( C_FuncFakeWorldPortal *pStart, const CViewSetup& view, 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 // Early out if no cameras
C_FuncFakeWorldPortal *pReflectiveGlass = NULL; C_FuncFakeWorldPortal *pReflectiveGlass = NULL;
@ -109,7 +109,7 @@ C_FuncFakeWorldPortal *NextFakeWorldPortal( C_FuncFakeWorldPortal *pStart, const
if ( vecDelta.Dot( worldPlane.normal ) >= 0 ) // Backface cull if ( vecDelta.Dot( worldPlane.normal ) >= 0 ) // Backface cull
continue; continue;
vecPlaneLocalOrigin = vecLocalOrigin; flLocalPlaneDist = localPlane.dist;
vecAbsPlaneNormal = worldPlane.normal; vecAbsPlaneNormal = worldPlane.normal;
return pReflectiveGlass; return pReflectiveGlass;

View File

@ -54,7 +54,7 @@ public:
// Do we have reflective glass in view? If so, what's the reflection plane? // Do we have reflective glass in view? If so, what's the reflection plane?
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
C_FuncFakeWorldPortal *NextFakeWorldPortal( C_FuncFakeWorldPortal *pStart, const CViewSetup& view, 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 #endif // C_FUNC_FAKE_WORLDPORTAL

View File

@ -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 ); GeneratePerspectiveFrustum( view.origin, view.angles, view.zNear, view.zFar, view.fov, view.m_flAspectRatio, frustum );
Vector vecAbsPlaneNormal; Vector vecAbsPlaneNormal;
Vector vecPlaneLocalOrigin; float flLocalPlaneDist;
C_FuncFakeWorldPortal *pPortalEnt = NextFakeWorldPortal( NULL, view, vecAbsPlaneNormal, vecPlaneLocalOrigin, frustum ); C_FuncFakeWorldPortal *pPortalEnt = NextFakeWorldPortal( NULL, view, vecAbsPlaneNormal, flLocalPlaneDist, frustum );
while ( pPortalEnt != NULL ) while ( pPortalEnt != NULL )
{ {
ITexture *pCameraTarget = pPortalEnt->RenderTarget(); ITexture *pCameraTarget = pPortalEnt->RenderTarget();
int width = pCameraTarget->GetActualWidth(); int width = pCameraTarget->GetActualWidth();
int height = pCameraTarget->GetActualHeight(); 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 #endif
} }
@ -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, bool CViewRender::DrawFakeWorldPortal( ITexture *pRenderTarget, C_FuncFakeWorldPortal *pCameraEnt, const CViewSetup &cameraView, C_BasePlayer *localPlayer,
int x, int y, int width, int height, 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 #ifdef USE_MONITORS
VPROF_INCREMENT_COUNTER( "cameras rendered", 1 ); VPROF_INCREMENT_COUNTER( "cameras rendered", 1 );
@ -3652,15 +3652,15 @@ bool CViewRender::DrawFakeWorldPortal( ITexture *pRenderTarget, C_FuncFakeWorldP
Vector4D plane; Vector4D plane;
// target direction
MatrixGetColumn( targetToWorld, 0, plane.AsVector3D() ); MatrixGetColumn( targetToWorld, 0, plane.AsVector3D() );
VectorNormalize( plane.AsVector3D() ); VectorNormalize( plane.AsVector3D() );
VectorNegate( plane.AsVector3D() ); VectorNegate( plane.AsVector3D() );
// The portal plane's distance from the actual brush's origin plane.w =
float flPlaneDist = vecPlaneLocalOrigin.Length(); 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
// The target's distance from world origin - 0.1;
plane.w = -((pCameraEnt->m_hTargetPlane->GetAbsOrigin() * plane.AsVector3D()).Length() + flPlaneDist) + 0.1f;
CMatRenderContextPtr pRenderContext( materials ); CMatRenderContextPtr pRenderContext( materials );
pRenderContext->PushCustomClipPlane( plane.Base() ); pRenderContext->PushCustomClipPlane( plane.Base() );

View File

@ -454,7 +454,7 @@ private:
#ifdef MAPBASE #ifdef MAPBASE
bool DrawFakeWorldPortal( ITexture *pRenderTarget, C_FuncFakeWorldPortal *pCameraEnt, const CViewSetup &cameraView, C_BasePlayer *localPlayer, bool DrawFakeWorldPortal( ITexture *pRenderTarget, C_FuncFakeWorldPortal *pCameraEnt, const CViewSetup &cameraView, C_BasePlayer *localPlayer,
int x, int y, int width, int height, 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 #endif
// Drawing primitives // Drawing primitives