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.

228 lines
6.4 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef VIEW_SHARED_H
  7. #define VIEW_SHARED_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "convar.h"
  12. #include "mathlib/vector.h"
  13. #include "mathlib/camera.h"
  14. #include "materialsystem/MaterialSystemUtil.h"
  15. class CVolumeCuller;
  16. //-----------------------------------------------------------------------------
  17. // Flags passed in with view setup
  18. //-----------------------------------------------------------------------------
  19. enum ClearFlags_t
  20. {
  21. VIEW_CLEAR_COLOR = 0x1,
  22. VIEW_CLEAR_DEPTH = 0x2,
  23. VIEW_CLEAR_FULL_TARGET = 0x4,
  24. VIEW_NO_DRAW = 0x8,
  25. VIEW_CLEAR_OBEY_STENCIL = 0x10, // Draws a quad allowing stencil test to clear through portals
  26. VIEW_CLEAR_STENCIL = 0x20,
  27. };
  28. enum MotionBlurMode_t
  29. {
  30. MOTION_BLUR_DISABLE = 1,
  31. MOTION_BLUR_GAME = 2, // Game uses real-time inter-frame data
  32. MOTION_BLUR_SFM = 3 // Use SFM data passed in CViewSetup structure
  33. };
  34. //-----------------------------------------------------------------------------
  35. // Purpose: Renderer setup data.
  36. //-----------------------------------------------------------------------------
  37. class CViewSetup
  38. {
  39. public:
  40. CViewSetup()
  41. {
  42. m_flAspectRatio = 0.0f;
  43. // These match mat_dof convars
  44. m_flNearBlurDepth = 20.0;
  45. m_flNearFocusDepth = 100.0;
  46. m_flFarFocusDepth = 250.0;
  47. m_flFarBlurDepth = 1000.0;
  48. m_flNearBlurRadius = 10.0;
  49. m_flFarBlurRadius = 5.0;
  50. m_nDoFQuality = 0;
  51. m_bRenderToSubrectOfLargerScreen = false;
  52. m_bDoBloomAndToneMapping = true;
  53. m_nMotionBlurMode = MOTION_BLUR_GAME;
  54. m_bDoDepthOfField = false;
  55. m_bHDRTarget = false;
  56. m_bOffCenter = false;
  57. m_bCacheFullSceneState = false;
  58. m_bDrawWorldNormal = false;
  59. m_bCullFrontFaces = false;
  60. m_bCustomViewMatrix = false;
  61. // m_bUseExplicitViewVector = false;
  62. m_bCustomProjMatrix = false;
  63. m_bCSMView = false;
  64. m_pCSMVolumeCuller = NULL;
  65. }
  66. float ComputeViewMatrices( VMatrix *pWorldToView, VMatrix *pViewToProjection, VMatrix *pWorldToProjection ) const;
  67. // shared by 2D & 3D views
  68. // left side of view window
  69. int x;
  70. int m_nUnscaledX;
  71. // top side of view window
  72. int y;
  73. int m_nUnscaledY;
  74. // width of view window
  75. int width;
  76. int m_nUnscaledWidth;
  77. // height of view window
  78. int height;
  79. int m_nUnscaledHeight;
  80. // X360 csm resolve offsets
  81. #if defined(_X360)
  82. int xCsmDstOffset;
  83. int yCsmDstOffset;
  84. #endif
  85. // the rest are only used by 3D views
  86. // Orthographic projection?
  87. bool m_bOrtho;
  88. // View-space rectangle for ortho projection.
  89. float m_OrthoLeft;
  90. float m_OrthoTop;
  91. float m_OrthoRight;
  92. float m_OrthoBottom;
  93. // Note: This really should be called "m_bCustomCameraMatrix", because m_matCustomViewMatrix is interpreted as world->camera, not world->view.
  94. bool m_bCustomViewMatrix;
  95. matrix3x4_t m_matCustomViewMatrix;
  96. bool m_bCustomProjMatrix;
  97. VMatrix m_matCustomProjMatrix;
  98. const CVolumeCuller *m_pCSMVolumeCuller;
  99. // horizontal FOV in degrees
  100. float fov;
  101. // horizontal FOV in degrees for in-view model
  102. float fovViewmodel;
  103. // 3D origin of camera
  104. Vector origin;
  105. // heading of camera (pitch, yaw, roll)
  106. QAngle angles;
  107. // local Z coordinate of near plane of camera
  108. float zNear;
  109. // local Z coordinate of far plane of camera
  110. float zFar;
  111. // local Z coordinate of near plane of camera ( when rendering view model )
  112. float zNearViewmodel;
  113. // local Z coordinate of far plane of camera ( when rendering view model )
  114. float zFarViewmodel;
  115. // The aspect ratio to use for computing the perspective projection matrix
  116. // (0.0f means use the viewport)
  117. float m_flAspectRatio;
  118. // Camera settings to control depth of field
  119. float m_flNearBlurDepth;
  120. float m_flNearFocusDepth;
  121. float m_flFarFocusDepth;
  122. float m_flFarBlurDepth;
  123. float m_flNearBlurRadius;
  124. float m_flFarBlurRadius;
  125. int m_nDoFQuality;
  126. // Camera settings to control motion blur
  127. MotionBlurMode_t m_nMotionBlurMode;
  128. float m_flShutterTime; // In seconds
  129. Vector m_vShutterOpenPosition; // Start of frame or "shutter open"
  130. QAngle m_shutterOpenAngles; //
  131. Vector m_vShutterClosePosition; // End of frame or "shutter close"
  132. QAngle m_shutterCloseAngles; //
  133. // Controls for off-center projection (needed for poster rendering)
  134. float m_flOffCenterTop;
  135. float m_flOffCenterBottom;
  136. float m_flOffCenterLeft;
  137. float m_flOffCenterRight;
  138. bool m_bOffCenter:1;
  139. // set to true if this is to draw into a subrect of the larger screen
  140. // this really is a hack, but no more than the rest of the way this class is used
  141. bool m_bRenderToSubrectOfLargerScreen:1;
  142. // Controls that the SFM needs to tell the engine when to do certain post-processing steps
  143. bool m_bDoBloomAndToneMapping:1;
  144. bool m_bDoDepthOfField:1;
  145. bool m_bHDRTarget:1;
  146. bool m_bDrawWorldNormal:1;
  147. bool m_bCullFrontFaces:1;
  148. // Cached mode for certain full-scene per-frame varying state such as sun entity coverage
  149. bool m_bCacheFullSceneState:1;
  150. // True if this is a CSM depth view. The CSM world->view matrix doesn't have an XY translation (that's moved into the CSM ortho view->projection
  151. // matrix to address continuity issues), so the usual assumptions made about camera/view space do not necessarily apply.
  152. bool m_bCSMView:1;
  153. };
  154. inline float CViewSetup::ComputeViewMatrices( VMatrix *pWorldToView, VMatrix *pViewToProjection, VMatrix *pWorldToProjection ) const
  155. {
  156. float flAspectRatio = m_flAspectRatio;
  157. if ( flAspectRatio == 0.0f )
  158. {
  159. flAspectRatio = (height != 0) ? ( (float)width / (float)height ) : 1.0f;
  160. }
  161. if( !m_bCustomViewMatrix )
  162. {
  163. ComputeViewMatrix( pWorldToView, origin, angles );
  164. }
  165. else
  166. {
  167. ComputeViewMatrix( pWorldToView, m_matCustomViewMatrix );
  168. }
  169. if ( m_bCustomProjMatrix )
  170. {
  171. *pViewToProjection = m_matCustomProjMatrix;
  172. }
  173. else if ( m_bOrtho )
  174. {
  175. MatrixBuildOrtho( *pViewToProjection, m_OrthoLeft, m_OrthoTop,
  176. m_OrthoRight, m_OrthoBottom, zNear, zFar );
  177. }
  178. else if ( m_bOffCenter ) // Off-center projection, useful for AA jitter and tiled output of posters
  179. {
  180. MatrixBuildPerspectiveOffCenterX( *pViewToProjection, fov, flAspectRatio,
  181. zNear, zFar, m_flOffCenterBottom, m_flOffCenterTop,
  182. m_flOffCenterLeft, m_flOffCenterRight );
  183. }
  184. else
  185. {
  186. MatrixBuildPerspectiveX( *pViewToProjection, fov, flAspectRatio, zNear, zFar );
  187. }
  188. MatrixMultiply( *pViewToProjection, *pWorldToView, *pWorldToProjection );
  189. return flAspectRatio;
  190. }
  191. #endif // VIEW_SHARED_H