Team Fortress 2 Source Code as on 22/4/2020
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.

120 lines
5.7 KiB

  1. //========= Copyright 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. struct FlatBasicPortalRenderingMaterials_t
  16. {
  17. CMaterialReference m_PortalMaterials[2];
  18. CMaterialReference m_PortalRenderFixMaterials[2];
  19. CMaterialReference m_PortalDepthDoubler;
  20. CMaterialReference m_PortalStaticOverlay[2];
  21. CMaterialReference m_Portal_Stencil_Hole;
  22. CMaterialReference m_Portal_Refract[2];
  23. //CTextureReference m_PortalLightTransfer_ShadowTexture; //light transfers disabled indefinitely
  24. IMaterialVar *m_pDepthDoubleViewMatrixVar;
  25. };
  26. //As seen in "Portal"
  27. class CPortalRenderable_FlatBasic : public C_BaseAnimating, public CPortalRenderable
  28. {
  29. DECLARE_CLASS( CPortalRenderable_FlatBasic, C_BaseAnimating );
  30. public:
  31. CPortalRenderable_FlatBasic( void );
  32. //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.
  33. virtual void DrawComplexPortalMesh( const IMaterial *pMaterialOverride = NULL, float fForwardOffsetModifier = 0.25f );
  34. //generates a single quad
  35. virtual void DrawSimplePortalMesh( const IMaterial *pMaterialOverride = NULL, float fForwardOffsetModifier = 0.25f );
  36. //draws a screenspace mesh to replace missing pixels caused by the camera near plane intersecting the portal mesh
  37. virtual void DrawRenderFixMesh( const IMaterial *pMaterialOverride = NULL, float fFrontClipDistance = 0.3f );
  38. //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
  39. virtual void DrawDepthDoublerMesh( float fForwardOffsetModifier = 0.25f );
  40. virtual void DrawPortal( void );
  41. virtual void DrawPreStencilMask( void ); //Draw to wherever you can see through the portal. The mask will later be filled with the portal view.
  42. virtual void DrawStencilMask( void ); //Draw to wherever you can see through the portal. The mask will later be filled with the portal view.
  43. virtual void DrawPostStencilFixes( void ); //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
  44. virtual void RenderPortalViewToBackBuffer( CViewRender *pViewRender, const CViewSetup &cameraView );
  45. virtual void RenderPortalViewToTexture( CViewRender *pViewRender, const CViewSetup &cameraView );
  46. void AddToVisAsExitPortal( ViewCustomVisibility_t *pCustomVisibility );
  47. virtual bool ShouldUpdatePortalView_BasedOnView( const CViewSetup &currentView, CUtlVector<VPlane> &currentComplexFrustum ); //portal is both visible, and will display at least some portion of a remote view
  48. virtual bool ShouldUpdatePortalView_BasedOnPixelVisibility( float fScreenFilledByStencilMaskLastFrame_Normalized );
  49. virtual bool ShouldUpdateDepthDoublerTexture( const CViewSetup &viewSetup );
  50. virtual void GetToolRecordingState( bool bActive, KeyValues *msg );
  51. virtual void HandlePortalPlaybackMessage( KeyValues *pKeyValues );
  52. virtual const Vector &GetFogOrigin( void ) const { return m_ptOrigin; };
  53. virtual SkyboxVisibility_t SkyBoxVisibleFromPortal( void ) { return m_InternallyMaintainedData.m_nSkyboxVisibleFromCorners; };
  54. virtual bool DoesExitViewIntersectWaterPlane( float waterZ, int leafWaterDataID ) const;
  55. bool WillUseDepthDoublerThisDraw( void ) const; //returns true if the DrawPortal() would draw a depth doubler mesh if you were to call it right now
  56. virtual CPortalRenderable *GetLinkedPortal() const { return m_pLinkedPortal; };
  57. bool CalcFrustumThroughPortal( const Vector &ptCurrentViewOrigin, Frustum OutputFrustum );
  58. protected:
  59. void ClipFixToBoundingAreaAndDraw( PortalMeshPoint_t *pVerts, const IMaterial *pMaterial );
  60. void Internal_DrawRenderFixMesh( const IMaterial *pMaterial );
  61. // renders a quad that simulates fog as an overlay for something else (most notably the hole we create for stencil mode portals)
  62. void RenderFogQuad( void );
  63. void PortalMoved( void ); // call this if you've moved the portal around so we can update internally maintained data
  64. static const FlatBasicPortalRenderingMaterials_t& m_Materials;
  65. struct FlatBasicPortal_InternalData_t
  66. {
  67. VPlane m_BoundingPlanes[PORTALRENDERFIXMESH_OUTERBOUNDPLANES + 2]; // +2 for front and back
  68. VisOverrideData_t m_VisData; // a data to use for visibility calculations (to override area portal culling)
  69. int m_iViewLeaf; // leaf to start in for area portal flowing through calculations
  70. VMatrix m_DepthDoublerTextureView; //cached version of view matrix at depth 1 for use when drawing the depth doubler mesh
  71. bool m_bUsableDepthDoublerConfiguration; //every time a portal moves we re-evaluate whether the depth doubler will reasonably approximate more views
  72. SkyboxVisibility_t m_nSkyboxVisibleFromCorners;
  73. Vector m_ptForwardOrigin;
  74. Vector m_ptCorners[4];
  75. float m_fPlaneDist; //combines with m_vForward to make a plane
  76. };
  77. FlatBasicPortal_InternalData_t m_InternallyMaintainedData;
  78. public:
  79. CPortalRenderable_FlatBasic *m_pLinkedPortal;
  80. Vector m_ptOrigin;
  81. Vector m_vForward, m_vUp, m_vRight;
  82. float m_fStaticAmount;
  83. float m_fSecondaryStaticAmount; // used to help kludge the end of our recursive rendering chain
  84. float m_fOpenAmount;
  85. bool m_bIsPortal2; //for any set of portals, one must be portal 1, and the other portal 2. Uses different render targets
  86. };
  87. #endif //#ifndef PORTALRENDERABLE_FLATBASIC_H