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.

321 lines
11 KiB

  1. //===== Copyright � 1996-2008, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #ifndef ISHADERDYNAMIC_H
  9. #define ISHADERDYNAMIC_H
  10. #ifndef SPU
  11. #ifdef _WIN32
  12. #pragma once
  13. #endif
  14. #include "shaderapi/shareddefs.h"
  15. #include "materialsystem/imaterial.h"
  16. #include "materialsystem/imaterialsystem.h"
  17. typedef intp ShaderAPITextureHandle_t;
  18. #define INVALID_SHADERAPI_TEXTURE_HANDLE 0
  19. //-----------------------------------------------------------------------------
  20. // forward declarations
  21. //-----------------------------------------------------------------------------
  22. class CMeshBuilder;
  23. class IMaterialVar;
  24. struct LightDesc_t;
  25. //-----------------------------------------------------------------------------
  26. // State from ShaderAPI used to select proper vertex and pixel shader combos
  27. //-----------------------------------------------------------------------------
  28. struct LightState_t
  29. {
  30. int m_nNumLights;
  31. bool m_bAmbientLight;
  32. bool m_bStaticLight;
  33. bool m_bStaticLightIndirectOnly; // only valid if m_bStaticLight true
  34. inline int HasDynamicLight() { return (m_bAmbientLight || (m_nNumLights > 0)) ? 1 : 0; }
  35. };
  36. //-----------------------------------------------------------------------------
  37. // Color correction info
  38. //-----------------------------------------------------------------------------
  39. struct ShaderColorCorrectionInfo_t
  40. {
  41. bool m_bIsEnabled;
  42. int m_nLookupCount;
  43. float m_flDefaultWeight;
  44. float m_pLookupWeights[4];
  45. };
  46. #endif // SPU
  47. //-----------------------------------------------------------------------------
  48. // the 3D shader API interface
  49. // This interface is all that shaders see.
  50. //-----------------------------------------------------------------------------
  51. enum StandardTextureId_t
  52. {
  53. // Lightmaps
  54. TEXTURE_LIGHTMAP = 0,
  55. TEXTURE_LIGHTMAP_FULLBRIGHT,
  56. TEXTURE_LIGHTMAP_BUMPED,
  57. TEXTURE_LIGHTMAP_BUMPED_FULLBRIGHT,
  58. // Flat colors
  59. TEXTURE_WHITE,
  60. TEXTURE_BLACK,
  61. TEXTURE_BLACK_ALPHA_ZERO,
  62. TEXTURE_GREY,
  63. TEXTURE_GREY_ALPHA_ZERO,
  64. // Normalmaps
  65. TEXTURE_NORMALMAP_FLAT,
  66. TEXTURE_SSBUMP_FLAT,
  67. // Normalization
  68. TEXTURE_NORMALIZATION_CUBEMAP,
  69. TEXTURE_NORMALIZATION_CUBEMAP_SIGNED,
  70. // Frame-buffer textures
  71. TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0,
  72. TEXTURE_FRAME_BUFFER_FULL_TEXTURE_1,
  73. // Color correction
  74. TEXTURE_COLOR_CORRECTION_VOLUME_0,
  75. TEXTURE_COLOR_CORRECTION_VOLUME_1,
  76. TEXTURE_COLOR_CORRECTION_VOLUME_2,
  77. TEXTURE_COLOR_CORRECTION_VOLUME_3,
  78. // An alias to the Back Frame Buffer
  79. TEXTURE_FRAME_BUFFER_ALIAS,
  80. // Noise for shadow mapping algorithm
  81. TEXTURE_SHADOW_NOISE_2D,
  82. // A texture in which morph data gets accumulated (vs30, fast vertex textures required)
  83. TEXTURE_MORPH_ACCUMULATOR,
  84. // A texture which contains morph weights
  85. TEXTURE_MORPH_WEIGHTS,
  86. // A snapshot of the frame buffer's depth. Currently only valid on the 360
  87. TEXTURE_FRAME_BUFFER_FULL_DEPTH,
  88. // A snapshot of the frame buffer's depth. Currently only valid on the 360
  89. TEXTURE_IDENTITY_LIGHTWARP,
  90. // The current local env_cubemap
  91. TEXTURE_LOCAL_ENV_CUBEMAP,
  92. // Texture containing subdivision surface patch data
  93. TEXTURE_SUBDIVISION_PATCHES,
  94. // Screen-space texture which contains random 3D reflection vectors used in SSAO algorithm
  95. TEXTURE_SSAO_NOISE_2D,
  96. TEXTURE_PAINT,
  97. // Stereo-ized texture that contains eye-dependent stereo constants.
  98. TEXTURE_STEREO_PARAM_MAP,
  99. TEXTURE_MAX_STD_TEXTURES
  100. };
  101. #ifndef SPU
  102. enum TextureFilterMode_t
  103. {
  104. TFILTER_MODE_POINTSAMPLED = 1,
  105. };
  106. enum TessellationMode_t;
  107. //-----------------------------------------------------------------------------
  108. // The Shader interface versions
  109. //-----------------------------------------------------------------------------
  110. #define SHADERDYNAMIC_INTERFACE_VERSION "ShaderDynamic001"
  111. abstract_class IShaderDynamicAPI
  112. {
  113. public:
  114. virtual void BeginPerfEEvent( wchar* name ) {}
  115. virtual void EndPerfEvent() {}
  116. virtual void SetVertexShaderViewProj() = 0;
  117. virtual void UpdateVertexShaderMatrix( int m ) = 0;
  118. virtual void SetVertexShaderModelViewProjAndModelView() = 0;
  119. virtual void SetVertexShaderCameraPos() = 0;
  120. virtual bool SetSkinningMatrices( const MeshInstanceData_t &instance ) = 0;
  121. virtual void BindTexture( Sampler_t sampler, TextureBindFlags_t nBindFlags, ShaderAPITextureHandle_t textureHandle ) = 0;
  122. // returns the current time in seconds....
  123. virtual double CurrentTime() const = 0;
  124. // Gets the lightmap dimensions
  125. virtual void GetLightmapDimensions( int *w, int *h ) = 0;
  126. // Scene fog state.
  127. // This is used by the shaders for picking the proper vertex shader for fogging based on dynamic state.
  128. virtual MaterialFogMode_t GetSceneFogMode( ) = 0;
  129. virtual void GetSceneFogColor( unsigned char *rgb ) = 0;
  130. // Sets the constant register for vertex and pixel shaders
  131. virtual void SetVertexShaderConstant( int var, float const* pVec, int numConst = 1, bool bForce = false ) = 0;
  132. virtual void SetPixelShaderConstant( int var, float const* pVec, int numConst = 1, bool bForce = false ) = 0;
  133. // Sets the default *dynamic* state
  134. virtual void SetDefaultState() = 0;
  135. // Get the current camera position in world space.
  136. virtual void GetWorldSpaceCameraPosition( float* pPos ) const = 0;
  137. virtual void GetWorldSpaceCameraDirection( float* pDir ) const = 0;
  138. virtual int GetCurrentNumBones( void ) const = 0;
  139. virtual MaterialFogMode_t GetCurrentFogType( void ) const = 0;
  140. // Sets the vertex and pixel shaders
  141. virtual void SetVertexShaderIndex( int vshIndex = -1 ) = 0;
  142. virtual void SetPixelShaderIndex( int pshIndex = 0 ) = 0;
  143. // Get the dimensions of the back buffer.
  144. virtual void GetBackBufferDimensions( int& width, int& height ) const = 0;
  145. // Get information about the physical and pixel aspect ratios of the backbuffer.
  146. virtual const AspectRatioInfo_t &GetAspectRatioInfo( void ) const = 0;
  147. // Get the dimensions of the current render target
  148. virtual void GetCurrentRenderTargetDimensions( int& nWidth, int& nHeight ) const = 0;
  149. // Get the current viewport
  150. virtual void GetCurrentViewport( int& nX, int& nY, int& nWidth, int& nHeight ) const = 0;
  151. // FIXME: The following 6 methods used to live in IShaderAPI
  152. // and were moved for stdshader_dx8. Let's try to move them back!
  153. virtual void SetPixelShaderFogParams( int reg ) = 0;
  154. // Use this to get the mesh builder that allows us to modify vertex data
  155. virtual bool InFlashlightMode() const = 0;
  156. virtual const FlashlightState_t &GetFlashlightState( VMatrix &worldToTexture ) const = 0;
  157. virtual bool InEditorMode() const = 0;
  158. virtual bool IsCascadedShadowMapping() const = 0;
  159. virtual const CascadedShadowMappingState_t &GetCascadedShadowMappingState( ITexture **pDepthTextureAtlas, bool bLightMapScale = false ) const = 0;
  160. // Binds a standard texture
  161. virtual void BindStandardTexture( Sampler_t sampler, TextureBindFlags_t nBindFlags, StandardTextureId_t id ) = 0;
  162. virtual ITexture *GetRenderTargetEx( int nRenderTargetID ) const = 0;
  163. virtual void SetToneMappingScaleLinear( const Vector &scale ) = 0;
  164. virtual const Vector &GetToneMappingScaleLinear( void ) const = 0;
  165. virtual void SetFloatRenderingParameter(int parm_number, float value) = 0;
  166. virtual void SetIntRenderingParameter(int parm_number, int value) = 0 ;
  167. virtual void SetVectorRenderingParameter(int parm_number, Vector const &value) = 0 ;
  168. virtual float GetFloatRenderingParameter(int parm_number) const = 0 ;
  169. virtual int GetIntRenderingParameter(int parm_number) const = 0 ;
  170. virtual Vector GetVectorRenderingParameter(int parm_number) const = 0 ;
  171. virtual const FlashlightState_t &GetFlashlightStateEx( VMatrix &worldToTexture, ITexture **pFlashlightDepthTexture ) const = 0;
  172. virtual void GetDX9LightState( LightState_t *state ) const = 0;
  173. virtual int GetPixelFogCombo( ) = 0; //0 is either range fog, or no fog simulated with rigged range fog values. 1 is height fog
  174. virtual void BindStandardVertexTexture( VertexTextureSampler_t sampler, StandardTextureId_t id ) = 0;
  175. // Is hardware morphing enabled?
  176. virtual bool IsHWMorphingEnabled( ) const = 0;
  177. virtual void GetStandardTextureDimensions( int *pWidth, int *pHeight, StandardTextureId_t id ) = 0;
  178. virtual void SetBooleanVertexShaderConstant( int var, BOOL const* pVec, int numBools = 1, bool bForce = false ) = 0;
  179. virtual void SetIntegerVertexShaderConstant( int var, int const* pVec, int numIntVecs = 1, bool bForce = false ) = 0;
  180. virtual void SetBooleanPixelShaderConstant( int var, BOOL const* pVec, int numBools = 1, bool bForce = false ) = 0;
  181. virtual void SetIntegerPixelShaderConstant( int var, int const* pVec, int numIntVecs = 1, bool bForce = false ) = 0;
  182. //Are we in a configuration that needs access to depth data through the alpha channel later?
  183. virtual bool ShouldWriteDepthToDestAlpha( void ) const = 0;
  184. // Returns current matrices
  185. virtual void GetMatrix( MaterialMatrixMode_t matrixMode, float *dst ) = 0;
  186. // deformations
  187. virtual void PushDeformation( DeformationBase_t const *Deformation ) = 0;
  188. virtual void PopDeformation( ) = 0;
  189. virtual int GetNumActiveDeformations() const =0;
  190. // for shaders to set vertex shader constants. returns a packed state which can be used to set
  191. // the dynamic combo. returns # of active deformations
  192. virtual int GetPackedDeformationInformation( int nMaskOfUnderstoodDeformations,
  193. float *pConstantValuesOut,
  194. int nBufferSize,
  195. int nMaximumDeformations,
  196. int *pNumDefsOut ) const = 0;
  197. // This lets the lower level system that certain vertex fields requested
  198. // in the shadow state aren't actually being read given particular state
  199. // known only at dynamic state time. It's here only to silence warnings.
  200. virtual void MarkUnusedVertexFields( unsigned int nFlags, int nTexCoordCount, bool *pUnusedTexCoords ) = 0;
  201. virtual void ExecuteCommandBuffer( uint8 *pCmdBuffer ) =0;
  202. // Interface for mat system to tell shaderapi about color correction
  203. virtual void GetCurrentColorCorrection( ShaderColorCorrectionInfo_t* pInfo ) = 0;
  204. virtual ITexture *GetTextureRenderingParameter(int parm_number) const = 0;
  205. virtual void SetScreenSizeForVPOS( int pshReg = 32 ) = 0;
  206. virtual void SetVSNearAndFarZ( int vshReg ) = 0;
  207. virtual float GetFarZ() = 0;
  208. virtual bool SinglePassFlashlightModeEnabled( void ) = 0;
  209. virtual void GetActualProjectionMatrix( float *pMatrix ) = 0;
  210. virtual void SetDepthFeatheringShaderConstants( int iConstant, float fDepthBlendScale ) = 0;
  211. virtual void GetFlashlightShaderInfo( bool *pShadowsEnabled, bool *pUberLight ) const = 0;
  212. virtual float GetFlashlightAmbientOcclusion( ) const = 0;
  213. // allows overriding texture filtering mode on an already bound texture.
  214. virtual void SetTextureFilterMode( Sampler_t sampler, TextureFilterMode_t nMode ) = 0;
  215. virtual TessellationMode_t GetTessellationMode() const = 0;
  216. virtual float GetSubDHeight() = 0;
  217. #if defined( _GAMECONSOLE )
  218. // Enables console-specific command predication.
  219. // Set values to 'true' if batches should be rendered in the z-pass and/or the render pass.
  220. // Disabling predication returns to default values, which allows D3D to control predication
  221. virtual void EnablePredication( bool bZPass, bool bRenderPass ) = 0;
  222. virtual void DisablePredication() = 0;
  223. #endif // _GAMECONSOLE
  224. virtual bool IsRenderingPaint() const = 0;
  225. virtual bool IsStereoActiveThisFrame() const = 0;
  226. virtual bool IsStandardTextureHandleValid( StandardTextureId_t textureId ) = 0;
  227. };
  228. // end class IShaderDynamicAPI
  229. #endif //SPU
  230. #endif // ISHADERDYNAMIC_H