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.

189 lines
7.1 KiB

  1. //========= Copyright 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 "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. // change this when the new version is incompatable with the old
  26. #define ENGINE_SHADOWMGR_INTERFACE_VERSION "VEngineShadowMgr002"
  27. //-----------------------------------------------------------------------------
  28. // Flags for the creation method
  29. //-----------------------------------------------------------------------------
  30. enum ShadowFlags_t
  31. {
  32. SHADOW_FLAGS_FLASHLIGHT = (1 << 0),
  33. SHADOW_FLAGS_SHADOW = (1 << 1),
  34. // Update this if you add flags
  35. SHADOW_FLAGS_LAST_FLAG = SHADOW_FLAGS_SHADOW
  36. };
  37. #define SHADOW_FLAGS_PROJECTED_TEXTURE_TYPE_MASK ( SHADOW_FLAGS_FLASHLIGHT | SHADOW_FLAGS_SHADOW )
  38. //-----------------------------------------------------------------------------
  39. //
  40. // Shadow-related functionality exported by the engine
  41. //
  42. //-----------------------------------------------------------------------------
  43. //-----------------------------------------------------------------------------
  44. // This is a handle to shadows, clients can create as many as they want
  45. //-----------------------------------------------------------------------------
  46. typedef unsigned short ShadowHandle_t;
  47. enum
  48. {
  49. SHADOW_HANDLE_INVALID = (ShadowHandle_t)~0
  50. };
  51. //-----------------------------------------------------------------------------
  52. // Used for the creation Flags field of CreateShadow
  53. //-----------------------------------------------------------------------------
  54. enum ShadowCreateFlags_t
  55. {
  56. SHADOW_CACHE_VERTS = ( 1 << 0 ),
  57. SHADOW_FLASHLIGHT = ( 1 << 1 ),
  58. SHADOW_LAST_FLAG = SHADOW_FLASHLIGHT,
  59. };
  60. //-----------------------------------------------------------------------------
  61. // Information about a particular shadow
  62. //-----------------------------------------------------------------------------
  63. struct ShadowInfo_t
  64. {
  65. // Transforms from world space into texture space of the shadow
  66. VMatrix m_WorldToShadow;
  67. // The shadow should no longer be drawn once it's further than MaxDist
  68. // along z in shadow texture coordinates.
  69. float m_FalloffOffset;
  70. float m_MaxDist;
  71. float m_FalloffAmount; // how much to lighten the shadow maximally
  72. Vector2D m_TexOrigin;
  73. Vector2D m_TexSize;
  74. unsigned char m_FalloffBias;
  75. };
  76. struct FlashlightState_t;
  77. //-----------------------------------------------------------------------------
  78. // The engine's interface to the shadow manager
  79. //-----------------------------------------------------------------------------
  80. abstract_class IShadowMgr
  81. {
  82. public:
  83. // Create, destroy shadows (see ShadowCreateFlags_t for creationFlags)
  84. virtual ShadowHandle_t CreateShadow( IMaterial* pMaterial, IMaterial* pModelMaterial, void* pBindProxy, int creationFlags ) = 0;
  85. virtual void DestroyShadow( ShadowHandle_t handle ) = 0;
  86. // Resets the shadow material (useful for shadow LOD.. doing blobby at distance)
  87. virtual void SetShadowMaterial( ShadowHandle_t handle, IMaterial* pMaterial, IMaterial* pModelMaterial, void* pBindProxy ) = 0;
  88. // Shadow opacity
  89. // virtual void SetShadowOpacity( ShadowHandle_t handle, float alpha ) = 0;
  90. // virtual float GetShadowOpacity( ShadowHandle_t handle ) const = 0;
  91. // Project a shadow into the world
  92. // The two points specify the upper left coordinate and the lower-right
  93. // coordinate of the shadow specified in a shadow "viewplane". The
  94. // projection matrix is a shadow viewplane->world transformation,
  95. // and can be orthographic orperspective.
  96. // I expect that the client DLL will call this method any time the shadow
  97. // changes because the light changes, or because the entity casting the
  98. // shadow moves
  99. // Note that we can't really control the shadows from the engine because
  100. // the engine only knows about pevs, which don't exist on the client
  101. // The shadow matrix specifies a world-space transform for the shadow
  102. // the shadow is projected down the z direction, and the origin of the
  103. // shadow matrix is the origin of the projection ray. The size indicates
  104. // the shadow size measured in the space of the shadow matrix; the
  105. // shadow goes from +/- size.x/2 along the x axis of the shadow matrix
  106. // and +/- size.y/2 along the y axis of the shadow matrix.
  107. virtual void ProjectShadow( ShadowHandle_t handle, const Vector &origin,
  108. const Vector& projectionDir, const VMatrix& worldToShadow, const Vector2D& size,
  109. int nLeafCount, const int *pLeafList,
  110. float maxHeight, float falloffOffset, float falloffAmount, const Vector &vecCasterOrigin ) = 0;
  111. virtual void ProjectFlashlight( ShadowHandle_t handle, const VMatrix &worldToShadow, int nLeafCount, const int *pLeafList ) = 0;
  112. // Gets at information about a particular shadow
  113. virtual const ShadowInfo_t &GetInfo( ShadowHandle_t handle ) = 0;
  114. virtual const Frustum_t &GetFlashlightFrustum( ShadowHandle_t handle ) = 0;
  115. // Methods related to shadows on brush models
  116. virtual void AddShadowToBrushModel( ShadowHandle_t handle,
  117. model_t* pModel, const Vector& origin, const QAngle& angles ) = 0;
  118. // Removes all shadows from a brush model
  119. virtual void RemoveAllShadowsFromBrushModel( model_t* pModel ) = 0;
  120. // Sets the texture coordinate range for a shadow...
  121. virtual void SetShadowTexCoord( ShadowHandle_t handle, float x, float y, float w, float h ) = 0;
  122. // Methods related to shadows on studio models
  123. virtual void AddShadowToModel( ShadowHandle_t shadow, ModelInstanceHandle_t instance ) = 0;
  124. virtual void RemoveAllShadowsFromModel( ModelInstanceHandle_t instance ) = 0;
  125. // Set extra clip planes related to shadows...
  126. // These are used to prevent pokethru and back-casting
  127. virtual void ClearExtraClipPlanes( ShadowHandle_t shadow ) = 0;
  128. virtual void AddExtraClipPlane( ShadowHandle_t shadow, const Vector& normal, float dist ) = 0;
  129. // Allows us to disable particular shadows
  130. virtual void EnableShadow( ShadowHandle_t shadow, bool bEnable ) = 0;
  131. // Set the darkness falloff bias
  132. virtual void SetFalloffBias( ShadowHandle_t shadow, unsigned char ucBias ) = 0;
  133. // Update the state for a flashlight.
  134. virtual void UpdateFlashlightState( ShadowHandle_t shadowHandle, const FlashlightState_t &lightState ) = 0;
  135. virtual void DrawFlashlightDepthTexture( ) = 0;
  136. virtual void AddFlashlightRenderable( ShadowHandle_t shadow, IClientRenderable *pRenderable ) = 0;
  137. virtual ShadowHandle_t CreateShadowEx( IMaterial* pMaterial, IMaterial* pModelMaterial, void* pBindProxy, int creationFlags ) = 0;
  138. virtual void SetFlashlightDepthTexture( ShadowHandle_t shadowHandle, ITexture *pFlashlightDepthTexture, unsigned char ucShadowStencilBit ) = 0;
  139. virtual const FlashlightState_t &GetFlashlightState( ShadowHandle_t handle ) = 0;
  140. virtual void SetFlashlightRenderState( ShadowHandle_t handle ) = 0;
  141. };
  142. #endif