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.

234 lines
9.5 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =====//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #ifndef ISHADOWMGR_H
  9. #define ISHADOWMGR_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "tier1/interface.h"
  14. #include "mathlib/vmatrix.h"
  15. //-----------------------------------------------------------------------------
  16. // forward declarations
  17. //-----------------------------------------------------------------------------
  18. class IMaterial;
  19. class Vector;
  20. class Vector2D;
  21. struct model_t;
  22. typedef unsigned short ModelInstanceHandle_t;
  23. class IClientRenderable;
  24. class ITexture;
  25. struct FlashlightInstance_t;
  26. struct FlashlightState_t;
  27. // change this when the new version is incompatable with the old
  28. #define ENGINE_SHADOWMGR_INTERFACE_VERSION "VEngineShadowMgr002"
  29. //-----------------------------------------------------------------------------
  30. // Flags for the creation method
  31. //-----------------------------------------------------------------------------
  32. enum ShadowFlags_t
  33. {
  34. SHADOW_FLAGS_FLASHLIGHT = (1 << 0),
  35. SHADOW_FLAGS_SHADOW = (1 << 1),
  36. SHADOW_FLAGS_SIMPLE_PROJECTION = (1 << 2),
  37. // Update this if you add flags
  38. SHADOW_FLAGS_LAST_FLAG = SHADOW_FLAGS_SIMPLE_PROJECTION
  39. };
  40. #define SHADOW_FLAGS_PROJECTED_TEXTURE_TYPE_MASK ( SHADOW_FLAGS_FLASHLIGHT | SHADOW_FLAGS_SHADOW | SHADOW_FLAGS_SIMPLE_PROJECTION )
  41. //-----------------------------------------------------------------------------
  42. //
  43. // Shadow-related functionality exported by the engine
  44. //
  45. //-----------------------------------------------------------------------------
  46. //-----------------------------------------------------------------------------
  47. // This is a handle to shadows, clients can create as many as they want
  48. //-----------------------------------------------------------------------------
  49. typedef unsigned short ShadowHandle_t;
  50. enum
  51. {
  52. SHADOW_HANDLE_INVALID = (ShadowHandle_t)~0
  53. };
  54. //-----------------------------------------------------------------------------
  55. // Used for the creation Flags field of CreateShadow
  56. //-----------------------------------------------------------------------------
  57. enum ShadowCreateFlags_t
  58. {
  59. SHADOW_CACHE_VERTS = ( 1 << 0 ),
  60. SHADOW_FLASHLIGHT = ( 1 << 1 ),
  61. SHADOW_SIMPLE_PROJECTION = ( 1 << 2 ),
  62. SHADOW_ANY_SPLITSCREEN_SLOT = ( 1 << 3 ),
  63. SHADOW_LAST_FLAG = SHADOW_SIMPLE_PROJECTION,
  64. };
  65. //-----------------------------------------------------------------------------
  66. // Information about a particular shadow
  67. //-----------------------------------------------------------------------------
  68. struct ShadowInfo_t
  69. {
  70. // Transforms from world space into texture space of the shadow
  71. VMatrix m_WorldToShadow;
  72. // The shadow should no longer be drawn once it's further than MaxDist
  73. // along z in shadow texture coordinates.
  74. float m_FalloffOffset;
  75. float m_MaxDist;
  76. float m_FalloffAmount; // how much to lighten the shadow maximally
  77. Vector2D m_TexOrigin;
  78. Vector2D m_TexSize;
  79. unsigned char m_FalloffBias;
  80. };
  81. typedef void (*ShadowDrawCallbackFn_t)( void * );
  82. typedef void (*ShadowDrawCallbackFn_t)( void * );
  83. //-----------------------------------------------------------------------------
  84. // The engine's interface to the shadow manager
  85. //-----------------------------------------------------------------------------
  86. abstract_class IShadowMgr
  87. {
  88. public:
  89. // Create, destroy shadows (see ShadowCreateFlags_t for creationFlags)
  90. virtual ShadowHandle_t CreateShadow( IMaterial* pMaterial, IMaterial* pModelMaterial, void* pBindProxy, int creationFlags ) = 0;
  91. virtual void DestroyShadow( ShadowHandle_t handle ) = 0;
  92. // Resets the shadow material (useful for shadow LOD.. doing blobby at distance)
  93. virtual void SetShadowMaterial( ShadowHandle_t handle, IMaterial* pMaterial, IMaterial* pModelMaterial, void* pBindProxy ) = 0;
  94. // Shadow opacity
  95. // virtual void SetShadowOpacity( ShadowHandle_t handle, float alpha ) = 0;
  96. // virtual float GetShadowOpacity( ShadowHandle_t handle ) const = 0;
  97. // Project a shadow into the world
  98. // The two points specify the upper left coordinate and the lower-right
  99. // coordinate of the shadow specified in a shadow "viewplane". The
  100. // projection matrix is a shadow viewplane->world transformation,
  101. // and can be orthographic orperspective.
  102. // I expect that the client DLL will call this method any time the shadow
  103. // changes because the light changes, or because the entity casting the
  104. // shadow moves
  105. // Note that we can't really control the shadows from the engine because
  106. // the engine only knows about pevs, which don't exist on the client
  107. // The shadow matrix specifies a world-space transform for the shadow
  108. // the shadow is projected down the z direction, and the origin of the
  109. // shadow matrix is the origin of the projection ray. The size indicates
  110. // the shadow size measured in the space of the shadow matrix; the
  111. // shadow goes from +/- size.x/2 along the x axis of the shadow matrix
  112. // and +/- size.y/2 along the y axis of the shadow matrix.
  113. virtual void ProjectShadow( ShadowHandle_t handle, const Vector &origin,
  114. const Vector& projectionDir, const VMatrix& worldToShadow, const Vector2D& size,
  115. int nLeafCount, const int *pLeafList,
  116. float maxHeight, float falloffOffset, float falloffAmount, const Vector &vecCasterOrigin ) = 0;
  117. virtual void ProjectFlashlight( ShadowHandle_t handle, const VMatrix &worldToShadow, int nLeafCount, const int *pLeafList ) = 0;
  118. // Gets at information about a particular shadow
  119. virtual const ShadowInfo_t &GetInfo( ShadowHandle_t handle ) = 0;
  120. virtual const Frustum_t &GetFlashlightFrustum( ShadowHandle_t handle ) = 0;
  121. // Methods related to shadows on brush models
  122. virtual void AddShadowToBrushModel( ShadowHandle_t handle,
  123. model_t* pModel, const Vector& origin, const QAngle& angles ) = 0;
  124. // Removes all shadows from a brush model
  125. virtual void RemoveAllShadowsFromBrushModel( model_t* pModel ) = 0;
  126. // Sets the texture coordinate range for a shadow...
  127. virtual void SetShadowTexCoord( ShadowHandle_t handle, float x, float y, float w, float h ) = 0;
  128. // Methods related to shadows on studio models
  129. virtual void AddShadowToModel( ShadowHandle_t shadow, ModelInstanceHandle_t instance ) = 0;
  130. virtual void RemoveAllShadowsFromModel( ModelInstanceHandle_t instance ) = 0;
  131. // Set extra clip planes related to shadows...
  132. // These are used to prevent pokethru and back-casting
  133. virtual void ClearExtraClipPlanes( ShadowHandle_t shadow ) = 0;
  134. virtual void AddExtraClipPlane( ShadowHandle_t shadow, const Vector& normal, float dist ) = 0;
  135. // Allows us to disable particular shadows
  136. virtual void EnableShadow( ShadowHandle_t shadow, bool bEnable ) = 0;
  137. // Set the darkness falloff bias
  138. virtual void SetFalloffBias( ShadowHandle_t shadow, unsigned char ucBias ) = 0;
  139. // Update the state for a flashlight.
  140. virtual void UpdateFlashlightState( ShadowHandle_t shadowHandle, const FlashlightState_t &lightState ) = 0;
  141. virtual void DrawFlashlightDepthTexture( ) = 0;
  142. virtual ShadowHandle_t CreateShadowEx( IMaterial* pMaterial, IMaterial* pModelMaterial, void* pBindProxy, int creationFlags, int nEntIndex ) = 0;
  143. virtual void SetFlashlightDepthTexture( ShadowHandle_t shadowHandle, ITexture *pFlashlightDepthTexture, unsigned char ucShadowStencilBit ) = 0;
  144. virtual const FlashlightState_t &GetFlashlightState( ShadowHandle_t handle ) = 0;
  145. virtual void SetFlashlightRenderState( ShadowHandle_t handle ) = 0;
  146. virtual void DrawVolumetrics() = 0;
  147. virtual int GetNumShadowsOnModel( ModelInstanceHandle_t instance ) = 0;
  148. virtual int GetShadowsOnModel( ModelInstanceHandle_t instance, ShadowHandle_t* pShadowArray, bool bNormalShadows, bool bFlashlightShadows ) = 0;
  149. virtual void FlashlightDrawCallback( ShadowDrawCallbackFn_t pCallback, void *pData ) = 0; //used to draw each additive flashlight pass. The callback is called once per flashlight state for an additive pass.
  150. //Way for the client to determine which flashlight to use in single-pass modes. Does not actually enable the flashlight in any way.
  151. virtual void SetSinglePassFlashlightRenderState( ShadowHandle_t handle ) = 0;
  152. //Enable/Disable the flashlight state set with SetSinglePassFlashlightRenderState.
  153. virtual void PushSinglePassFlashlightStateEnabled( bool bEnable ) = 0;
  154. virtual void PopSinglePassFlashlightStateEnabled( void ) = 0;
  155. virtual bool SinglePassFlashlightModeEnabled( void ) = 0;
  156. // Determine a unique list of flashlights which hit at least one of the specified models
  157. // Accepts an instance count and an array of ModelInstanceHandle_ts.
  158. // Returns the number of FlashlightInstance_ts it's found that affect the models.
  159. // Also fills in a mask of which flashlights affect each ModelInstanceHandle_t
  160. // There can be at most MAX_FLASHLIGHTS_PER_INSTANCE_DRAW_CALL pFlashlights,
  161. // and the size of the pModelUsageMask array must be nInstanceCount.
  162. virtual int SetupFlashlightRenderInstanceInfo( ShadowHandle_t *pUniqueFlashlights, uint32 *pModelUsageMask, int nUsageStride, int nInstanceCount, const ModelInstanceHandle_t *pInstance ) = 0;
  163. // Returns the flashlight state for multiple flashlights
  164. virtual void GetFlashlightRenderInfo( FlashlightInstance_t *pFlashlightState, int nCount, const ShadowHandle_t *pHandles ) = 0;
  165. virtual void RemoveAllDecalsFromShadow( ShadowHandle_t handle ) = 0;
  166. virtual void SkipShadowForEntity( int nEntIndex ) = 0;
  167. //designed for portal usage. Recursive drawing leaves the scissor rect in a bad state for translucents
  168. virtual void PushFlashlightScissorBounds( void ) = 0;
  169. virtual void PopFlashlightScissorBounds( void ) = 0;
  170. // Disables projected shadows
  171. virtual void DisableDropShadows() = 0;
  172. };
  173. #endif