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.

368 lines
11 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #ifndef ISHADERSHADOW_H
  9. #define ISHADERSHADOW_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "shaderapi/shareddefs.h"
  14. #include <materialsystem/imaterial.h>
  15. //-----------------------------------------------------------------------------
  16. // forward declarations
  17. //-----------------------------------------------------------------------------
  18. class CMeshBuilder;
  19. class IMaterialVar;
  20. struct LightDesc_t;
  21. //-----------------------------------------------------------------------------
  22. // important enumerations
  23. //-----------------------------------------------------------------------------
  24. enum ShaderDepthFunc_t
  25. {
  26. SHADER_DEPTHFUNC_NEVER,
  27. SHADER_DEPTHFUNC_NEARER,
  28. SHADER_DEPTHFUNC_EQUAL,
  29. SHADER_DEPTHFUNC_NEAREROREQUAL,
  30. SHADER_DEPTHFUNC_FARTHER,
  31. SHADER_DEPTHFUNC_NOTEQUAL,
  32. SHADER_DEPTHFUNC_FARTHEROREQUAL,
  33. SHADER_DEPTHFUNC_ALWAYS
  34. };
  35. enum ShaderBlendFactor_t
  36. {
  37. SHADER_BLEND_ZERO,
  38. SHADER_BLEND_ONE,
  39. SHADER_BLEND_DST_COLOR,
  40. SHADER_BLEND_ONE_MINUS_DST_COLOR,
  41. SHADER_BLEND_SRC_ALPHA,
  42. SHADER_BLEND_ONE_MINUS_SRC_ALPHA,
  43. SHADER_BLEND_DST_ALPHA,
  44. SHADER_BLEND_ONE_MINUS_DST_ALPHA,
  45. SHADER_BLEND_SRC_ALPHA_SATURATE,
  46. SHADER_BLEND_SRC_COLOR,
  47. SHADER_BLEND_ONE_MINUS_SRC_COLOR
  48. };
  49. enum ShaderBlendOp_t
  50. {
  51. SHADER_BLEND_OP_ADD,
  52. SHADER_BLEND_OP_SUBTRACT,
  53. SHADER_BLEND_OP_REVSUBTRACT,
  54. SHADER_BLEND_OP_MIN,
  55. SHADER_BLEND_OP_MAX
  56. };
  57. enum ShaderAlphaFunc_t
  58. {
  59. SHADER_ALPHAFUNC_NEVER,
  60. SHADER_ALPHAFUNC_LESS,
  61. SHADER_ALPHAFUNC_EQUAL,
  62. SHADER_ALPHAFUNC_LEQUAL,
  63. SHADER_ALPHAFUNC_GREATER,
  64. SHADER_ALPHAFUNC_NOTEQUAL,
  65. SHADER_ALPHAFUNC_GEQUAL,
  66. SHADER_ALPHAFUNC_ALWAYS
  67. };
  68. enum ShaderStencilFunc_t
  69. {
  70. SHADER_STENCILFUNC_NEVER = 0,
  71. SHADER_STENCILFUNC_LESS,
  72. SHADER_STENCILFUNC_EQUAL,
  73. SHADER_STENCILFUNC_LEQUAL,
  74. SHADER_STENCILFUNC_GREATER,
  75. SHADER_STENCILFUNC_NOTEQUAL,
  76. SHADER_STENCILFUNC_GEQUAL,
  77. SHADER_STENCILFUNC_ALWAYS
  78. };
  79. enum ShaderStencilOp_t
  80. {
  81. SHADER_STENCILOP_KEEP = 0,
  82. SHADER_STENCILOP_ZERO,
  83. SHADER_STENCILOP_SET_TO_REFERENCE,
  84. SHADER_STENCILOP_INCREMENT_CLAMP,
  85. SHADER_STENCILOP_DECREMENT_CLAMP,
  86. SHADER_STENCILOP_INVERT,
  87. SHADER_STENCILOP_INCREMENT_WRAP,
  88. SHADER_STENCILOP_DECREMENT_WRAP,
  89. };
  90. enum ShaderTexChannel_t
  91. {
  92. SHADER_TEXCHANNEL_COLOR = 0,
  93. SHADER_TEXCHANNEL_ALPHA
  94. };
  95. enum ShaderPolyModeFace_t
  96. {
  97. SHADER_POLYMODEFACE_FRONT,
  98. SHADER_POLYMODEFACE_BACK,
  99. SHADER_POLYMODEFACE_FRONT_AND_BACK,
  100. };
  101. enum ShaderPolyMode_t
  102. {
  103. SHADER_POLYMODE_POINT,
  104. SHADER_POLYMODE_LINE,
  105. SHADER_POLYMODE_FILL
  106. };
  107. enum ShaderTexArg_t
  108. {
  109. SHADER_TEXARG_TEXTURE = 0,
  110. SHADER_TEXARG_VERTEXCOLOR,
  111. SHADER_TEXARG_SPECULARCOLOR,
  112. SHADER_TEXARG_CONSTANTCOLOR,
  113. SHADER_TEXARG_PREVIOUSSTAGE,
  114. SHADER_TEXARG_NONE,
  115. SHADER_TEXARG_ZERO,
  116. SHADER_TEXARG_TEXTUREALPHA,
  117. SHADER_TEXARG_INVTEXTUREALPHA,
  118. SHADER_TEXARG_ONE,
  119. };
  120. enum ShaderTexOp_t
  121. {
  122. // DX5 shaders support these
  123. SHADER_TEXOP_MODULATE = 0,
  124. SHADER_TEXOP_MODULATE2X,
  125. SHADER_TEXOP_MODULATE4X,
  126. SHADER_TEXOP_SELECTARG1,
  127. SHADER_TEXOP_SELECTARG2,
  128. SHADER_TEXOP_DISABLE,
  129. // DX6 shaders support these
  130. SHADER_TEXOP_ADD,
  131. SHADER_TEXOP_SUBTRACT,
  132. SHADER_TEXOP_ADDSIGNED2X,
  133. SHADER_TEXOP_BLEND_CONSTANTALPHA,
  134. SHADER_TEXOP_BLEND_TEXTUREALPHA,
  135. SHADER_TEXOP_BLEND_PREVIOUSSTAGEALPHA,
  136. SHADER_TEXOP_MODULATECOLOR_ADDALPHA,
  137. SHADER_TEXOP_MODULATEINVCOLOR_ADDALPHA,
  138. // DX7
  139. SHADER_TEXOP_DOTPRODUCT3
  140. };
  141. enum ShaderTexGenParam_t
  142. {
  143. SHADER_TEXGENPARAM_OBJECT_LINEAR,
  144. SHADER_TEXGENPARAM_EYE_LINEAR,
  145. SHADER_TEXGENPARAM_SPHERE_MAP,
  146. SHADER_TEXGENPARAM_CAMERASPACEREFLECTIONVECTOR,
  147. SHADER_TEXGENPARAM_CAMERASPACENORMAL
  148. };
  149. enum ShaderDrawBitField_t
  150. {
  151. SHADER_DRAW_POSITION = 0x0001,
  152. SHADER_DRAW_NORMAL = 0x0002,
  153. SHADER_DRAW_COLOR = 0x0004,
  154. SHADER_DRAW_SPECULAR = 0x0008,
  155. SHADER_DRAW_TEXCOORD0 = 0x0010,
  156. SHADER_DRAW_TEXCOORD1 = 0x0020,
  157. SHADER_DRAW_TEXCOORD2 = 0x0040,
  158. SHADER_DRAW_TEXCOORD3 = 0x0080,
  159. SHADER_DRAW_LIGHTMAP_TEXCOORD0 = 0x0100,
  160. SHADER_DRAW_LIGHTMAP_TEXCOORD1 = 0x0200,
  161. SHADER_DRAW_LIGHTMAP_TEXCOORD2 = 0x0400,
  162. SHADER_DRAW_LIGHTMAP_TEXCOORD3 = 0x0800,
  163. SHADER_DRAW_SECONDARY_TEXCOORD0 = 0x1000,
  164. SHADER_DRAW_SECONDARY_TEXCOORD1 = 0x2000,
  165. SHADER_DRAW_SECONDARY_TEXCOORD2 = 0x4000,
  166. SHADER_DRAW_SECONDARY_TEXCOORD3 = 0x8000,
  167. SHADER_TEXCOORD_MASK = SHADER_DRAW_TEXCOORD0 | SHADER_DRAW_TEXCOORD1 |
  168. SHADER_DRAW_TEXCOORD2 | SHADER_DRAW_TEXCOORD3,
  169. SHADER_LIGHTMAP_TEXCOORD_MASK = SHADER_DRAW_LIGHTMAP_TEXCOORD0 |
  170. SHADER_DRAW_LIGHTMAP_TEXCOORD1 |
  171. SHADER_DRAW_LIGHTMAP_TEXCOORD2 |
  172. SHADER_DRAW_LIGHTMAP_TEXCOORD3,
  173. SHADER_SECONDARY_TEXCOORD_MASK = SHADER_DRAW_SECONDARY_TEXCOORD0 |
  174. SHADER_DRAW_SECONDARY_TEXCOORD1 |
  175. SHADER_DRAW_SECONDARY_TEXCOORD2 |
  176. SHADER_DRAW_SECONDARY_TEXCOORD3,
  177. };
  178. enum ShaderFogMode_t
  179. {
  180. SHADER_FOGMODE_DISABLED = 0,
  181. SHADER_FOGMODE_OO_OVERBRIGHT,
  182. SHADER_FOGMODE_BLACK,
  183. SHADER_FOGMODE_GREY,
  184. SHADER_FOGMODE_FOGCOLOR,
  185. SHADER_FOGMODE_WHITE,
  186. SHADER_FOGMODE_NUMFOGMODES
  187. };
  188. enum ShaderMaterialSource_t
  189. {
  190. SHADER_MATERIALSOURCE_MATERIAL = 0,
  191. SHADER_MATERIALSOURCE_COLOR1,
  192. SHADER_MATERIALSOURCE_COLOR2,
  193. };
  194. // m_ZBias has only two bits in ShadowState_t, so be careful extending this enum
  195. enum PolygonOffsetMode_t
  196. {
  197. SHADER_POLYOFFSET_DISABLE = 0x0,
  198. SHADER_POLYOFFSET_DECAL = 0x1,
  199. SHADER_POLYOFFSET_SHADOW_BIAS = 0x2,
  200. SHADER_POLYOFFSET_RESERVED = 0x3 // Reserved for future use
  201. };
  202. //-----------------------------------------------------------------------------
  203. // The Shader interface versions
  204. //-----------------------------------------------------------------------------
  205. #define SHADERSHADOW_INTERFACE_VERSION "ShaderShadow010"
  206. //-----------------------------------------------------------------------------
  207. // the shader API interface (methods called from shaders)
  208. //-----------------------------------------------------------------------------
  209. abstract_class IShaderShadow
  210. {
  211. public:
  212. // Sets the default *shadow* state
  213. virtual void SetDefaultState() = 0;
  214. // Methods related to depth buffering
  215. virtual void DepthFunc( ShaderDepthFunc_t depthFunc ) = 0;
  216. virtual void EnableDepthWrites( bool bEnable ) = 0;
  217. virtual void EnableDepthTest( bool bEnable ) = 0;
  218. virtual void EnablePolyOffset( PolygonOffsetMode_t nOffsetMode ) = 0;
  219. // These methods for controlling stencil are obsolete and stubbed to do nothing. Stencil
  220. // control is via the shaderapi/material system now, not part of the shadow state.
  221. // Methods related to stencil
  222. virtual void EnableStencil( bool bEnable ) = 0;
  223. virtual void StencilFunc( ShaderStencilFunc_t stencilFunc ) = 0;
  224. virtual void StencilPassOp( ShaderStencilOp_t stencilOp ) = 0;
  225. virtual void StencilFailOp( ShaderStencilOp_t stencilOp ) = 0;
  226. virtual void StencilDepthFailOp( ShaderStencilOp_t stencilOp ) = 0;
  227. virtual void StencilReference( int nReference ) = 0;
  228. virtual void StencilMask( int nMask ) = 0;
  229. virtual void StencilWriteMask( int nMask ) = 0;
  230. // Suppresses/activates color writing
  231. virtual void EnableColorWrites( bool bEnable ) = 0;
  232. virtual void EnableAlphaWrites( bool bEnable ) = 0;
  233. // Methods related to alpha blending
  234. virtual void EnableBlending( bool bEnable ) = 0;
  235. virtual void BlendFunc( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor ) = 0;
  236. // More below...
  237. // Alpha testing
  238. virtual void EnableAlphaTest( bool bEnable ) = 0;
  239. virtual void AlphaFunc( ShaderAlphaFunc_t alphaFunc, float alphaRef /* [0-1] */ ) = 0;
  240. // Wireframe/filled polygons
  241. virtual void PolyMode( ShaderPolyModeFace_t face, ShaderPolyMode_t polyMode ) = 0;
  242. // Back face culling
  243. virtual void EnableCulling( bool bEnable ) = 0;
  244. // constant color + transparency
  245. virtual void EnableConstantColor( bool bEnable ) = 0;
  246. // Indicates the vertex format for use with a vertex shader
  247. // The flags to pass in here come from the VertexFormatFlags_t enum
  248. // If pTexCoordDimensions is *not* specified, we assume all coordinates
  249. // are 2-dimensional
  250. virtual void VertexShaderVertexFormat( unsigned int nFlags,
  251. int nTexCoordCount, int* pTexCoordDimensions, int nUserDataSize ) = 0;
  252. // Pixel and vertex shader methods
  253. virtual void SetVertexShader( const char* pFileName, int nStaticVshIndex ) = 0;
  254. virtual void SetPixelShader( const char* pFileName, int nStaticPshIndex = 0 ) = 0;
  255. // Indicates we're going to light the model
  256. virtual void EnableLighting( bool bEnable ) = 0;
  257. // Enables specular lighting (lighting has also got to be enabled)
  258. virtual void EnableSpecular( bool bEnable ) = 0;
  259. // Convert from linear to gamma color space on writes to frame buffer.
  260. virtual void EnableSRGBWrite( bool bEnable ) = 0;
  261. // Convert from gamma to linear on texture fetch.
  262. virtual void EnableSRGBRead( Sampler_t sampler, bool bEnable ) = 0;
  263. // Activate/deactivate skinning. Indexed blending is automatically
  264. // enabled if it's available for this hardware. When blending is enabled,
  265. // we allocate enough room for 3 weights (max allowed)
  266. virtual void EnableVertexBlend( bool bEnable ) = 0;
  267. // per texture unit stuff
  268. virtual void OverbrightValue( TextureStage_t stage, float value ) = 0;
  269. virtual void EnableTexture( Sampler_t sampler, bool bEnable ) = 0;
  270. virtual void EnableTexGen( TextureStage_t stage, bool bEnable ) = 0;
  271. virtual void TexGen( TextureStage_t stage, ShaderTexGenParam_t param ) = 0;
  272. // alternate method of specifying per-texture unit stuff, more flexible and more complicated
  273. // Can be used to specify different operation per channel (alpha/color)...
  274. virtual void EnableCustomPixelPipe( bool bEnable ) = 0;
  275. virtual void CustomTextureStages( int stageCount ) = 0;
  276. virtual void CustomTextureOperation( TextureStage_t stage, ShaderTexChannel_t channel,
  277. ShaderTexOp_t op, ShaderTexArg_t arg1, ShaderTexArg_t arg2 ) = 0;
  278. // indicates what per-vertex data we're providing
  279. virtual void DrawFlags( unsigned int drawFlags ) = 0;
  280. // A simpler method of dealing with alpha modulation
  281. virtual void EnableAlphaPipe( bool bEnable ) = 0;
  282. virtual void EnableConstantAlpha( bool bEnable ) = 0;
  283. virtual void EnableVertexAlpha( bool bEnable ) = 0;
  284. virtual void EnableTextureAlpha( TextureStage_t stage, bool bEnable ) = 0;
  285. // GR - Separate alpha blending
  286. virtual void EnableBlendingSeparateAlpha( bool bEnable ) = 0;
  287. virtual void BlendFuncSeparateAlpha( ShaderBlendFactor_t srcFactor, ShaderBlendFactor_t dstFactor ) = 0;
  288. virtual void FogMode( ShaderFogMode_t fogMode ) = 0;
  289. virtual void SetDiffuseMaterialSource( ShaderMaterialSource_t materialSource ) = 0;
  290. // Indicates the morph format for use with a vertex shader
  291. // The flags to pass in here come from the MorphFormatFlags_t enum
  292. virtual void SetMorphFormat( MorphFormat_t flags ) = 0;
  293. virtual void DisableFogGammaCorrection( bool bDisable ) = 0; //some blending modes won't work properly with corrected fog
  294. // Alpha to coverage
  295. virtual void EnableAlphaToCoverage( bool bEnable ) = 0;
  296. // Shadow map filtering
  297. virtual void SetShadowDepthFiltering( Sampler_t stage ) = 0;
  298. // More alpha blending state
  299. virtual void BlendOp( ShaderBlendOp_t blendOp ) = 0;
  300. virtual void BlendOpSeparateAlpha( ShaderBlendOp_t blendOp ) = 0;
  301. };
  302. // end class IShaderShadow
  303. #endif // ISHADERSHADOW_H