Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
6.9 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #ifndef PORTALRENDERABLE_FLATBASIC_H
  8. #define PORTALRENDERABLE_FLATBASIC_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "PortalRender.h"
  13. struct PortalMeshPoint_t;
  14. #define PORTALRENDERFIXMESH_OUTERBOUNDPLANES 12
  15. //As seen in "Portal"
  16. class CPortalRenderable_FlatBasic : public C_BaseAnimating, public CPortalRenderable
  17. {
  18. DECLARE_CLASS( CPortalRenderable_FlatBasic, C_BaseAnimating );
  19. public:
  20. CPortalRenderable_FlatBasic( void );
  21. //generates a 8x6 tiled set of quads, each clipped to the view frustum. Helps vs11/ps11 portal shaders interpolate correctly. Not necessary for vs20/ps20 portal shaders or stencil mode.
  22. virtual void DrawComplexPortalMesh( IMatRenderContext *pRenderContext, const IMaterial *pMaterial, float fForwardOffsetModifier = 0.0f );
  23. //generates a single quad
  24. virtual void DrawSimplePortalMesh( IMatRenderContext *pRenderContext, const IMaterial *pMaterial, float fForwardOffsetModifier = 0.0f, float flAlpha = 1.0f, const Vector *pVertexColor = NULL );
  25. //draws a screenspace mesh to replace missing pixels caused by the camera near plane intersecting the portal mesh
  26. virtual void DrawRenderFixMesh( IMatRenderContext *pRenderContext, const IMaterial *pMaterialOverride = NULL, float fFrontClipDistance = 0.3f );
  27. virtual void DrawPortal( IMatRenderContext *pRenderContext );
  28. virtual int BindPortalMaterial( IMatRenderContext *pRenderContext, int nPassIndex, bool *pAllowRingMeshOptimizationOut );
  29. virtual void DrawStencilMask( IMatRenderContext *pRenderContext ); //Draw to wherever you can see through the portal. The mask will later be filled with the portal view.
  30. virtual void DrawPostStencilFixes( IMatRenderContext *pRenderContext ); //After done drawing to the portal mask, we need to fix the depth buffer as well as fog. So draw your mesh again, writing to z and with the fog color alpha'd in by distance
  31. //When we're in a configuration that sees through recursive portal views to a depth of 2, we should be able to cheaply approximate even further depth using pixels from previous frames
  32. virtual void DrawDepthDoublerMesh( IMatRenderContext *pRenderContext, float fForwardOffsetModifier = 0.25f );
  33. virtual void RenderPortalViewToBackBuffer( CViewRender *pViewRender, const CViewSetup &cameraView );
  34. virtual void RenderPortalViewToTexture( CViewRender *pViewRender, const CViewSetup &cameraView );
  35. void AddToVisAsExitPortal( ViewCustomVisibility_t *pCustomVisibility );
  36. virtual bool ShouldUpdatePortalView_BasedOnView( const CViewSetup &currentView, const CUtlVector<VPlane> &currentComplexFrustum ); //portal is both visible, and will display at least some portion of a remote view
  37. virtual bool ShouldUpdatePortalView_BasedOnPixelVisibility( float fScreenFilledByStencilMaskLastFrame_Normalized );
  38. virtual bool ShouldUpdateDepthDoublerTexture( const CViewSetup &viewSetup );
  39. virtual void GetToolRecordingState( KeyValues *msg );
  40. virtual void HandlePortalPlaybackMessage( KeyValues *pKeyValues );
  41. virtual const Vector &GetFogOrigin( void ) const { return m_ptOrigin; };
  42. virtual SkyboxVisibility_t SkyBoxVisibleFromPortal( void ) { return m_InternallyMaintainedData.m_nSkyboxVisibleFromCorners; };
  43. virtual bool DoesExitViewIntersectWaterPlane( float waterZ, int leafWaterDataID ) const;
  44. virtual float GetPortalDistanceBias() const;
  45. bool WillUseDepthDoublerThisDraw( void ) const; //returns true if the DrawPortal() would draw a depth doubler mesh if you were to call it right now
  46. virtual CPortalRenderable *GetLinkedPortal() const { return m_pLinkedPortal; };
  47. bool CalcFrustumThroughPortal( const Vector &ptCurrentViewOrigin, Frustum OutputFrustum );
  48. bool CalcFrustumThroughPolygon( const Vector *pPolyVertices, int iPolyVertCount, const Vector &ptCurrentViewOrigin, Frustum OutputFrustum );
  49. virtual float GetPortalGhostAlpha( void ) const { return 1.0; }
  50. static IMesh *CreateMeshForPortals( IMatRenderContext *pRenderContext, int nPortalCount, CPortalRenderable **ppPortals, CUtlVector< ClampedPortalMeshRenderInfo_t > &clampedPortalMeshRenderInfos );
  51. virtual int DrawModel( int flags, const RenderableInstance_t &instance ) { return 0; } // Prevent the model from rendering as a normal model
  52. virtual IClientModelRenderable* GetClientModelRenderable() { return NULL; }
  53. bool ComputeClipSpacePortalCorners( Vector4D *pClipSpacePortalCornersOut, const VMatrix &matViewProj ) const;
  54. protected:
  55. void ClipFixToBoundingAreaAndDraw( PortalMeshPoint_t *pVerts, const IMaterial *pMaterial );
  56. void Internal_DrawRenderFixMesh( IMatRenderContext *pRenderContext, const IMaterial *pMaterial );
  57. // renders a quad that simulates fog as an overlay for something else (most notably the hole we create for stencil mode portals)
  58. void RenderFogQuad( void );
  59. void PortalMoved( void ); // call this if you've moved the portal around so we can update internally maintained data
  60. struct FlatBasicPortal_InternalData_t
  61. {
  62. VPlane m_BoundingPlanes[PORTALRENDERFIXMESH_OUTERBOUNDPLANES + 2]; // +2 for front and back
  63. VisOverrideData_t m_VisData; // a data to use for visibility calculations (to override area portal culling)
  64. int m_iViewLeaf; // leaf to start in for area portal flowing through calculations
  65. VMatrix m_DepthDoublerTextureView[MAX_SPLITSCREEN_CLIENTS]; //cached version of view matrix at depth 1 for use when drawing the depth doubler mesh
  66. bool m_bUsableDepthDoublerConfiguration; //every time a portal moves we re-evaluate whether the depth doubler will reasonably approximate more views
  67. SkyboxVisibility_t m_nSkyboxVisibleFromCorners;
  68. Vector m_ptForwardOrigin;
  69. Vector m_ptCorners[4];
  70. float m_fPlaneDist; //combines with m_vForward to make a plane
  71. };
  72. FlatBasicPortal_InternalData_t m_InternallyMaintainedData;
  73. public:
  74. CPortalRenderable_FlatBasic *m_pLinkedPortal;
  75. Vector m_ptOrigin;
  76. Vector m_vForward, m_vUp, m_vRight;
  77. QAngle m_qAbsAngle;
  78. bool m_bIsPortal2; //for any set of portals, one must be portal 1, and the other portal 2. Uses different render targets
  79. #if 0
  80. //SFM stuff
  81. Vector m_ptLastRecordedOrigin;
  82. QAngle m_qLastRecordedAngle;
  83. #endif
  84. private:
  85. float m_fHalfWidth, m_fHalfHeight;
  86. static CUtlStack<Vector4D> ms_clipPlaneStack;
  87. public:
  88. inline float GetHalfWidth( void ) const { return m_fHalfWidth; }
  89. inline float GetHalfHeight( void ) const { return m_fHalfHeight; }
  90. inline Vector GetLocalMins( void ) const { return Vector( 0.0f, -m_fHalfWidth, -m_fHalfHeight ); }
  91. inline Vector GetLocalMaxs( void ) const { return Vector( 64.0f, m_fHalfWidth, m_fHalfHeight ); }
  92. inline void SetHalfSizes( float fHalfWidth, float fHalfHeight ) { m_fHalfWidth = fHalfWidth; m_fHalfHeight = fHalfHeight; }
  93. };
  94. #endif //#ifndef PORTALRENDERABLE_FLATBASIC_H