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.

696 lines
24 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "BaseVSShader.h"
  8. #include "commandbuilder.h"
  9. #include "pyro_vision_ps20.inc"
  10. #include "pyro_vision_ps20b.inc"
  11. #include "pyro_vision_vs20.inc"
  12. #include "pyro_vision_ps30.inc"
  13. #include "pyro_vision_vs30.inc"
  14. #include "../materialsystem_global.h"
  15. // memdbgon must be the last include file in a .cpp file!!!
  16. #include "tier0/memdbgon.h"
  17. static ConVar mat_visualize_dof( "mat_visualize_dof", "0", FCVAR_CHEAT );
  18. class CPyroVision_DX9_Context : public CBasePerMaterialContextData
  19. {
  20. public:
  21. uint8 *m_pStaticCmds;
  22. CCommandBufferBuilder< CFixedCommandStorageBuffer< 1000 > > m_SemiStaticCmdsOut;
  23. void ResetStaticCmds( void )
  24. {
  25. if ( m_pStaticCmds )
  26. {
  27. delete[] m_pStaticCmds;
  28. m_pStaticCmds = NULL;
  29. }
  30. }
  31. CPyroVision_DX9_Context( void )
  32. {
  33. m_pStaticCmds = NULL;
  34. }
  35. ~CPyroVision_DX9_Context( void )
  36. {
  37. ResetStaticCmds();
  38. }
  39. };
  40. static const float kDefaultStripeScale[ 3 ] = { 0.002f, 0.002f, 0.2f };
  41. static const float kDefaultStripeFadeNormal1[ 3 ] = { 0.0f, 0.0f, 1.0f };
  42. static const float kDefaultStripeFadeNormal2[ 3 ] = { 0.0f, 0.0f, 0.0f };
  43. static const float kDefaultStripeColor[ 3 ] = { 0.0f, 1.0f, 1.0f };
  44. static const float kDefaultSelfIllumTint[ 3 ] = { 1.0f, 1.0f, 1.0f };
  45. static const float kDefaultGrayStep[ 2 ] = { 0.0f, 1.0f };
  46. BEGIN_VS_SHADER( pyro_vision, "Help for pyro vision" )
  47. BEGIN_SHADER_PARAMS
  48. SHADER_PARAM( EFFECT, SHADER_PARAM_TYPE_INTEGER, "0.0", "" )
  49. SHADER_PARAM( VERTEX_LIT, SHADER_PARAM_TYPE_INTEGER, "0.0", "" )
  50. SHADER_PARAM( FULLBRIGHT, SHADER_PARAM_TYPE_INTEGER, "0.0", "" )
  51. SHADER_PARAM( ALPHATESTREFERENCE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" )
  52. SHADER_PARAM( BASETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  53. SHADER_PARAM( BASETEXTURE2, SHADER_PARAM_TYPE_TEXTURE, "shadertest/detail", "detail texture" )
  54. SHADER_PARAM( BLENDMODULATETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "texture to use r/g channels for blend range for" )
  55. SHADER_PARAM( BLENDMASKTRANSFORM, SHADER_PARAM_TYPE_MATRIX, "center .5 .5 scale 1 1 rotate 0 translate 0 0", "$blendmodulatetexture texcoord transform" )
  56. SHADER_PARAM( STRIPETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  57. SHADER_PARAM( STRIPE_SCALE, SHADER_PARAM_TYPE_VEC3, "[ 0.002 0.002 0.2 ]", "" )
  58. SHADER_PARAM( STRIPE_FADE_NORMAL1, SHADER_PARAM_TYPE_VEC3, "[ 0.0 0.0 1.0 ]", "" )
  59. SHADER_PARAM( STRIPE_FADE_NORMAL2, SHADER_PARAM_TYPE_VEC3, "[ 0.0 0.0 0.0 ]", "" )
  60. SHADER_PARAM( STRIPE_COLOR, SHADER_PARAM_TYPE_VEC3, "[ 0.0 0.0 0.0 ]", "" )
  61. SHADER_PARAM( STRIPE_LM_SCALE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" )
  62. // EFFECT 0
  63. SHADER_PARAM( BASE_STEP_RANGE, SHADER_PARAM_TYPE_VEC2, "[ 0.0 1.0 ]", "" )
  64. SHADER_PARAM( LIGHTMAP_STEP_RANGE, SHADER_PARAM_TYPE_VEC2, "[ 0.0 1.0 ]", "" )
  65. SHADER_PARAM( CANVAS, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  66. SHADER_PARAM( CANVAS_SCALE, SHADER_PARAM_TYPE_VEC3, "[ 0.002 0.002 0.2 ]", "" )
  67. SHADER_PARAM( CANVAS_STEP_RANGE, SHADER_PARAM_TYPE_VEC2, "[ 0.0 1.0 ]", "" )
  68. SHADER_PARAM( CANVAS_COLOR_START, SHADER_PARAM_TYPE_VEC3, "[ 0.0 0.0 0.0 ]", "" )
  69. SHADER_PARAM( CANVAS_COLOR_END, SHADER_PARAM_TYPE_VEC3, "[ 0.0 0.0 0.0 ]", "" )
  70. // EFFECT 1
  71. SHADER_PARAM( DIFFUSE_BASE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" )
  72. SHADER_PARAM( DIFFUSE_WHITE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" )
  73. SHADER_PARAM( GRAY_POWER, SHADER_PARAM_TYPE_FLOAT, "0.0", "" )
  74. SHADER_PARAM( GRAY_STEP, SHADER_PARAM_TYPE_VEC2, "[ 0.0 1.0 ]", "" )
  75. SHADER_PARAM( LIGHTMAP_GRADIENTS, SHADER_PARAM_TYPE_FLOAT, "0.0", "" )
  76. SHADER_PARAM( COLORBAR, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  77. SHADER_PARAM( SELFILLUMTINT, SHADER_PARAM_TYPE_COLOR, "[ 1.0 1.0 1.0 ]", "Self-illumination tint" )
  78. // EFFECT 2 Depth of Field
  79. SHADER_PARAM( DOF_START_DISTANCE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" )
  80. SHADER_PARAM( DOF_POWER, SHADER_PARAM_TYPE_FLOAT, "0.0", "" )
  81. SHADER_PARAM( DOF_MAX, SHADER_PARAM_TYPE_FLOAT, "0.0", "" )
  82. // EFFECT 3 Pyro Post
  83. SHADER_PARAM( WARPTEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  84. SHADER_PARAM( NOISETEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  85. SHADER_PARAM( VIGNETTE_TEXTURE, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  86. SHADER_PARAM( VIGNETTE_TILE, SHADER_PARAM_TYPE_TEXTURE, "", "" )
  87. SHADER_PARAM( NOISE_SCALE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" )
  88. SHADER_PARAM( TIME_SCALE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" )
  89. SHADER_PARAM( HEAT_HAZE_SCALE, SHADER_PARAM_TYPE_FLOAT, "0.0", "" )
  90. END_SHADER_PARAMS
  91. SHADER_INIT_PARAMS()
  92. {
  93. SET_PARAM_INT_IF_NOT_DEFINED( EFFECT, 0 );
  94. SET_PARAM_INT_IF_NOT_DEFINED( VERTEX_LIT, 0 );
  95. SET_PARAM_INT_IF_NOT_DEFINED( FULLBRIGHT, 0 );
  96. SET_PARAM_FLOAT_IF_NOT_DEFINED( ALPHATESTREFERENCE, 0.0f );
  97. SET_PARAM_STRING_IF_NOT_DEFINED( BLENDMASKTRANSFORM, "center .5 .5 scale 1 1 rotate 0 translate 0 0" );
  98. SET_PARAM_VEC_IF_NOT_DEFINED( STRIPE_SCALE, kDefaultStripeScale, 3 );
  99. SET_PARAM_VEC_IF_NOT_DEFINED( STRIPE_FADE_NORMAL1, kDefaultStripeFadeNormal1, 3 );
  100. SET_PARAM_VEC_IF_NOT_DEFINED( STRIPE_FADE_NORMAL2, kDefaultStripeFadeNormal2, 3 );
  101. SET_PARAM_VEC_IF_NOT_DEFINED( STRIPE_COLOR, kDefaultStripeColor, 3 );
  102. SET_PARAM_FLOAT_IF_NOT_DEFINED( STRIPE_LM_SCALE, 0.0f );
  103. SET_PARAM_FLOAT_IF_NOT_DEFINED( DIFFUSE_BASE, 0.0f );
  104. SET_PARAM_FLOAT_IF_NOT_DEFINED( DIFFUSE_WHITE, 0.0f );
  105. SET_PARAM_FLOAT_IF_NOT_DEFINED( GRAY_POWER, 1.0f );
  106. SET_PARAM_VEC_IF_NOT_DEFINED( GRAY_STEP, kDefaultGrayStep, 2 );
  107. SET_PARAM_FLOAT_IF_NOT_DEFINED( LIGHTMAP_GRADIENTS, 255.0f );
  108. SET_PARAM_VEC_IF_NOT_DEFINED( SELFILLUMTINT, kDefaultSelfIllumTint, 3 );
  109. SET_PARAM_FLOAT_IF_NOT_DEFINED( DOF_START_DISTANCE, 0.1f );
  110. SET_PARAM_FLOAT_IF_NOT_DEFINED( DOF_POWER, 0.4f );
  111. SET_PARAM_FLOAT_IF_NOT_DEFINED( DOF_MAX, 0.7f );
  112. SET_PARAM_FLOAT_IF_NOT_DEFINED( NOISE_SCALE, 0.2f );
  113. SET_PARAM_FLOAT_IF_NOT_DEFINED( TIME_SCALE, 0.02f );
  114. SET_PARAM_FLOAT_IF_NOT_DEFINED( HEAT_HAZE_SCALE, 0.2f );
  115. bool bVertexLit = params[ VERTEX_LIT ]->GetIntValue() != 0;
  116. if ( bVertexLit )
  117. {
  118. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT );
  119. }
  120. SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
  121. }
  122. SHADER_FALLBACK
  123. {
  124. return 0;
  125. }
  126. SHADER_INIT
  127. {
  128. LoadTexture( BASETEXTURE, TEXTUREFLAGS_SRGB );
  129. if ( params[ CANVAS ]->IsDefined() )
  130. {
  131. LoadTexture( CANVAS, TEXTUREFLAGS_SRGB );
  132. }
  133. if ( params[ COLORBAR ]->IsDefined() )
  134. {
  135. LoadTexture( COLORBAR, TEXTUREFLAGS_SRGB );
  136. }
  137. if ( params[ BASETEXTURE2 ]->IsDefined() )
  138. {
  139. LoadTexture( BASETEXTURE2, TEXTUREFLAGS_SRGB );
  140. }
  141. if ( params[ BLENDMODULATETEXTURE ]->IsDefined() )
  142. {
  143. LoadTexture( BLENDMODULATETEXTURE );
  144. }
  145. if ( params[ STRIPETEXTURE ]->IsDefined() )
  146. {
  147. LoadTexture( STRIPETEXTURE, TEXTUREFLAGS_SRGB );
  148. }
  149. if ( params[ WARPTEXTURE ]->IsDefined() )
  150. {
  151. LoadTexture( WARPTEXTURE );
  152. }
  153. if ( params[ NOISETEXTURE ]->IsDefined() )
  154. {
  155. LoadTexture( NOISETEXTURE );
  156. }
  157. if ( params[ VIGNETTE_TEXTURE ]->IsDefined() )
  158. {
  159. LoadTexture( VIGNETTE_TEXTURE );
  160. }
  161. if ( params[ VIGNETTE_TILE ]->IsDefined() )
  162. {
  163. LoadTexture( VIGNETTE_TILE, TEXTUREFLAGS_SRGB );
  164. }
  165. }
  166. SHADER_DRAW
  167. {
  168. CPyroVision_DX9_Context *pContextData = reinterpret_cast< CPyroVision_DX9_Context *> ( *pContextDataPtr );
  169. bool bNeedRegenStaticCmds = ( !pContextData ) || pShaderShadow;
  170. bool bVertexLit = params[ VERTEX_LIT ]->GetIntValue() != 0;
  171. bool bFullBright = params[ FULLBRIGHT ]->GetIntValue() != 0;
  172. bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow();
  173. bool bHasVertexColor = IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR );
  174. bool bHasBaseTexture2 = ( params[ BASETEXTURE2 ]->IsDefined() ) && ( params[ BASETEXTURE2 ]->IsTexture() );
  175. bool bHasBlendModulateTexture = bHasBaseTexture2 && ( params[ BLENDMODULATETEXTURE ]->IsDefined() ) && ( params[ BLENDMODULATETEXTURE ]->IsTexture() );
  176. bool bHasHeatHaze = ( params[ WARPTEXTURE ]->IsDefined() ) && ( params[ WARPTEXTURE ]->IsTexture() );
  177. int nEffect = params[ EFFECT ]->GetIntValue();
  178. bool bSelfIllum = IS_FLAG_SET( MATERIAL_VAR_SELFILLUM );
  179. bool bVisualizeDoF = mat_visualize_dof.GetBool();
  180. bool bIsAlphaTested = IS_FLAG_SET( MATERIAL_VAR_ALPHATEST ) != 0;
  181. bool bFullyOpaque = !bIsAlphaTested;
  182. bool bHasColorbar = ( params[ COLORBAR ]->IsDefined() ) && ( params[ COLORBAR ]->IsTexture() );
  183. bool bHasStripes = ( params[ STRIPETEXTURE ]->IsDefined() ) && ( params[ STRIPETEXTURE ]->IsTexture() );
  184. bool bHasStripesNormal2 = false;
  185. if ( bHasStripes )
  186. {
  187. Vector vNormal2;
  188. params[ STRIPE_FADE_NORMAL2 ]->GetVecValue( vNormal2.Base(), 3 );
  189. if ( vNormal2.LengthSqr() > 0.5f )
  190. {
  191. bHasStripesNormal2 = true;
  192. }
  193. }
  194. if ( !pContextData ) // make sure allocated
  195. {
  196. pContextData = new CPyroVision_DX9_Context;
  197. *pContextDataPtr = pContextData;
  198. }
  199. if ( nEffect == 3 )
  200. {
  201. static ConVarRef pyro_vignette_distortion( "pyro_vignette_distortion" );
  202. bHasHeatHaze &= pyro_vignette_distortion.GetBool();
  203. }
  204. if ( pShaderShadow || bNeedRegenStaticCmds )
  205. {
  206. pContextData->ResetStaticCmds();
  207. CCommandBufferBuilder< CFixedCommandStorageBuffer< 5000 > > staticCmdsBuf;
  208. Vector4D vParms(0, 0, 0, 0);
  209. params[ STRIPE_SCALE ]->GetVecValue( &vParms.x, 3 );
  210. staticCmdsBuf.SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, vParms.Base() );
  211. staticCmdsBuf.BindTexture( this, SHADER_SAMPLER0, BASETEXTURE, -1 );
  212. staticCmdsBuf.BindStandardTexture( SHADER_SAMPLER1, TEXTURE_LIGHTMAP );
  213. if ( bHasBlendModulateTexture )
  214. {
  215. staticCmdsBuf.BindTexture( this, SHADER_SAMPLER3, BLENDMODULATETEXTURE, -1 );
  216. staticCmdsBuf.BindTexture( this, SHADER_SAMPLER4, BASETEXTURE2, -1 );
  217. }
  218. if ( bHasStripes )
  219. {
  220. staticCmdsBuf.BindTexture( this, SHADER_SAMPLER5, STRIPETEXTURE, -1 );
  221. params[ STRIPE_COLOR ]->GetVecValue( &vParms.x, 3 );
  222. vParms.w = params[ STRIPE_LM_SCALE ]->GetFloatValue();
  223. staticCmdsBuf.SetPixelShaderConstant( 5, vParms.Base() );
  224. params[ STRIPE_FADE_NORMAL1 ]->GetVecValue( &vParms.x, 3 );
  225. staticCmdsBuf.SetPixelShaderConstant( 6, vParms.Base() );
  226. if ( bHasStripesNormal2 )
  227. {
  228. params[ STRIPE_FADE_NORMAL2 ]->GetVecValue( &vParms.x, 3 );
  229. staticCmdsBuf.SetPixelShaderConstant( 7, vParms.Base() );
  230. }
  231. }
  232. switch( nEffect )
  233. {
  234. case 0:
  235. {
  236. params[ CANVAS_SCALE ]->GetVecValue( &vParms.x, 3 );
  237. staticCmdsBuf.SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, vParms.Base() );
  238. staticCmdsBuf.BindTexture( this, SHADER_SAMPLER2, CANVAS, -1 );
  239. params[ BASE_STEP_RANGE ]->GetVecValue( &vParms.x, 2 );
  240. params[ LIGHTMAP_STEP_RANGE ]->GetVecValue( &vParms.z, 2 );
  241. staticCmdsBuf.SetPixelShaderConstant( 0, vParms.Base() );
  242. params[ CANVAS_STEP_RANGE ]->GetVecValue( &vParms.x, 2 );
  243. staticCmdsBuf.SetPixelShaderConstant( 2, vParms.Base() );
  244. params[ CANVAS_COLOR_START ]->GetVecValue( &vParms.x, 3 );
  245. staticCmdsBuf.SetPixelShaderConstant( 3, vParms.Base() );
  246. params[ CANVAS_COLOR_END ]->GetVecValue( &vParms.x, 3 );
  247. staticCmdsBuf.SetPixelShaderConstant( 4, vParms.Base() );
  248. }
  249. break;
  250. case 1:
  251. {
  252. if ( bHasColorbar )
  253. {
  254. staticCmdsBuf.BindTexture( this, SHADER_SAMPLER2, COLORBAR, -1 );
  255. }
  256. vParms.x = params[ GRAY_POWER ]->GetFloatValue();
  257. params[ GRAY_STEP ]->GetVecValue( &vParms.y, 2 );
  258. vParms.w = params[ LIGHTMAP_GRADIENTS ]->GetFloatValue();
  259. staticCmdsBuf.SetPixelShaderConstant( 0, vParms.Base() );
  260. vParms[ 0 ] = params[ DIFFUSE_BASE ]->GetFloatValue();
  261. params[ SELFILLUMTINT ]->GetVecValue( &vParms[ 1 ], 3 );
  262. staticCmdsBuf.SetPixelShaderConstant( 2, vParms.Base() );
  263. }
  264. break;
  265. case 2:
  266. {
  267. staticCmdsBuf.BindTexture( this, SHADER_SAMPLER4, BASETEXTURE2, -1 );
  268. vParms.x = params[ DOF_START_DISTANCE ]->GetFloatValue();
  269. vParms.y = params[ DOF_POWER ]->GetFloatValue();
  270. vParms.z = params[ DOF_MAX ]->GetFloatValue();
  271. vParms.w = 0.0f;
  272. staticCmdsBuf.SetPixelShaderConstant( 0, vParms.Base() );
  273. }
  274. break;
  275. case 3:
  276. {
  277. staticCmdsBuf.BindTexture( this, SHADER_SAMPLER3, NOISETEXTURE, -1 );
  278. staticCmdsBuf.BindTexture( this, SHADER_SAMPLER4, WARPTEXTURE, -1 );
  279. staticCmdsBuf.BindTexture( this, SHADER_SAMPLER5, VIGNETTE_TEXTURE, -1 );
  280. staticCmdsBuf.BindTexture( this, SHADER_SAMPLER6, VIGNETTE_TILE, -1 );
  281. vParms.x = params[ NOISE_SCALE ]->GetFloatValue();
  282. vParms.y = params[ TIME_SCALE ]->GetFloatValue();
  283. vParms.z = params[ HEAT_HAZE_SCALE ]->GetFloatValue();
  284. vParms.w = 0.0f;
  285. staticCmdsBuf.SetPixelShaderConstant( 0, vParms.Base() );
  286. }
  287. break;
  288. }
  289. staticCmdsBuf.StoreEyePosInPixelShaderConstant( 10 );
  290. staticCmdsBuf.SetPixelShaderFogParams( 11 );
  291. staticCmdsBuf.End();
  292. // now, copy buf
  293. pContextData->m_pStaticCmds = new uint8[ staticCmdsBuf.Size() ];
  294. memcpy( pContextData->m_pStaticCmds, staticCmdsBuf.Base(), staticCmdsBuf.Size() );
  295. }
  296. if ( pShaderAPI && pContextData->m_bMaterialVarsChanged )
  297. {
  298. // need to regenerate the semistatic cmds
  299. pContextData->m_SemiStaticCmdsOut.Reset();
  300. pContextData->m_bMaterialVarsChanged = false;
  301. if ( bHasBlendModulateTexture )
  302. {
  303. pContextData->m_SemiStaticCmdsOut.SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_10, BLENDMASKTRANSFORM );
  304. }
  305. Vector4D vParms;
  306. // vParms.x = pShaderAPI->LinearToGamma_HardwareSpecific( 1.0f );
  307. switch( nEffect )
  308. {
  309. case 0:
  310. {
  311. // set up shader modulation color
  312. vParms[ 0 ] = vParms[ 1 ] = vParms[ 2] = vParms[ 3 ] = 1.0f;
  313. ComputeModulationColor( vParms.Base() );
  314. float flLScale = pShaderAPI->GetLightMapScaleFactor();
  315. vParms[ 0 ] *= flLScale;
  316. vParms[ 1 ] *= flLScale;
  317. vParms[ 2 ] *= flLScale;
  318. pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 1, vParms.Base() );
  319. }
  320. break;
  321. case 1:
  322. {
  323. // set up shader modulation color
  324. vParms[ 0 ] = vParms[ 1 ] = vParms[ 2] = vParms[ 3 ] = 1.0f;
  325. ComputeModulationColor( vParms.Base() );
  326. float flLScale = pShaderAPI->GetLightMapScaleFactor();
  327. vParms[ 0 ] *= flLScale;
  328. vParms[ 1 ] *= flLScale;
  329. vParms[ 2 ] *= flLScale;
  330. vParms[ 3 ] = params[ DIFFUSE_WHITE ]->GetFloatValue();
  331. pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 1, vParms.Base() );
  332. }
  333. break;
  334. }
  335. pContextData->m_SemiStaticCmdsOut.SetAmbientCubeDynamicStateVertexShader();
  336. pContextData->m_SemiStaticCmdsOut.End();
  337. }
  338. SHADOW_STATE
  339. {
  340. SetInitialShadowState( );
  341. switch( nEffect )
  342. {
  343. case 0:
  344. case 1:
  345. {
  346. pShaderShadow->EnableDepthWrites( true );
  347. pShaderShadow->EnableDepthTest( true );
  348. SetDefaultBlendingShadowState( BASETEXTURE );
  349. }
  350. break;
  351. case 2:
  352. {
  353. pShaderShadow->EnableDepthWrites( false );
  354. pShaderShadow->EnableDepthTest( false );
  355. pShaderShadow->EnableBlending( true );
  356. pShaderShadow->BlendFunc( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  357. }
  358. break;
  359. case 3:
  360. {
  361. pShaderShadow->EnableDepthWrites( false );
  362. pShaderShadow->EnableDepthTest( false );
  363. pShaderShadow->EnableBlending( false );
  364. }
  365. break;
  366. }
  367. // pShaderShadow->BlendOp( SHADER_BLEND_OP_REVSUBTRACT );
  368. // EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE );
  369. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true );
  370. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true );
  371. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true );
  372. if( g_pHardwareConfig->GetHDRType() == HDR_TYPE_NONE )
  373. {
  374. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true );
  375. }
  376. else
  377. {
  378. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, false );
  379. }
  380. pShaderShadow->EnableTexture( SHADER_SAMPLER2, true );
  381. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, true );
  382. if ( nEffect == 0 || nEffect == 1 )
  383. {
  384. if ( bHasBlendModulateTexture )
  385. {
  386. pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
  387. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, false );
  388. pShaderShadow->EnableTexture( SHADER_SAMPLER4, true );
  389. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER4, true );
  390. }
  391. if ( bHasStripes )
  392. {
  393. pShaderShadow->EnableTexture( SHADER_SAMPLER5, true );
  394. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER5, true );
  395. }
  396. }
  397. if ( nEffect == 2 )
  398. {
  399. pShaderShadow->EnableTexture( SHADER_SAMPLER4, true );
  400. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER4, true );
  401. }
  402. if ( nEffect == 3 )
  403. {
  404. pShaderShadow->EnableTexture( SHADER_SAMPLER3, true );
  405. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, true );
  406. pShaderShadow->EnableTexture( SHADER_SAMPLER4, true );
  407. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER4, true );
  408. pShaderShadow->EnableTexture( SHADER_SAMPLER5, true );
  409. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER5, false );
  410. pShaderShadow->EnableTexture( SHADER_SAMPLER6, true );
  411. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER6, true );
  412. }
  413. pShaderShadow->EnableSRGBWrite( true );
  414. pShaderShadow->EnableAlphaWrites( true );
  415. pShaderShadow->EnableAlphaTest( bIsAlphaTested );
  416. if ( params[ ALPHATESTREFERENCE ]->GetFloatValue() > 0.0f )
  417. {
  418. pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_GEQUAL, params[ ALPHATESTREFERENCE ]->GetFloatValue() );
  419. }
  420. DefaultFog();
  421. int nFormat = 0;
  422. if ( bHasVertexColor )
  423. {
  424. nFormat |= VERTEX_COLOR;
  425. }
  426. if ( bVertexLit )
  427. {
  428. nFormat |= VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED;
  429. pShaderShadow->VertexShaderVertexFormat( nFormat, 1, 0, 0 );
  430. }
  431. else
  432. {
  433. nFormat |= VERTEX_POSITION;
  434. pShaderShadow->VertexShaderVertexFormat( nFormat, 2, 0, 0 );
  435. }
  436. bool bHalfLambert = IS_FLAG_SET( MATERIAL_VAR_HALFLAMBERT );
  437. if ( !g_pHardwareConfig->HasFastVertexTextures() )
  438. {
  439. DECLARE_STATIC_VERTEX_SHADER( pyro_vision_vs20 );
  440. SET_STATIC_VERTEX_SHADER_COMBO( EFFECT, params[ EFFECT ]->GetIntValue() );
  441. SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR ) );
  442. SET_STATIC_VERTEX_SHADER_COMBO( VERTEX_LIT, bVertexLit );
  443. SET_STATIC_VERTEX_SHADER_COMBO( FULLBRIGHT, bFullBright );
  444. SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, bHalfLambert );
  445. SET_STATIC_VERTEX_SHADER_COMBO( BASETEXTURE2, bHasBaseTexture2 );
  446. SET_STATIC_VERTEX_SHADER_COMBO( STRIPES, bHasStripes );
  447. SET_STATIC_VERTEX_SHADER_COMBO( STRIPES_USE_NORMAL2, bHasStripesNormal2 );
  448. SET_STATIC_VERTEX_SHADER_COMBO( USE_STATIC_CONTROL_FLOW, bUseStaticControlFlow );
  449. SET_STATIC_VERTEX_SHADER( pyro_vision_vs20 );
  450. if ( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  451. {
  452. DECLARE_STATIC_PIXEL_SHADER( pyro_vision_ps20b );
  453. SET_STATIC_PIXEL_SHADER_COMBO( EFFECT, params[ EFFECT ]->GetIntValue() );
  454. SET_STATIC_PIXEL_SHADER_COMBO( VERTEX_LIT, bVertexLit );
  455. SET_STATIC_PIXEL_SHADER_COMBO( BASETEXTURE2, bHasBaseTexture2 );
  456. SET_STATIC_PIXEL_SHADER_COMBO( FANCY_BLENDING, bHasBlendModulateTexture );
  457. SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM, bSelfIllum );
  458. SET_STATIC_PIXEL_SHADER_COMBO( COLOR_BAR, bHasColorbar );
  459. SET_STATIC_PIXEL_SHADER_COMBO( STRIPES, bHasStripes );
  460. SET_STATIC_PIXEL_SHADER_COMBO( STRIPES_USE_NORMAL2, bHasStripesNormal2 );
  461. SET_STATIC_PIXEL_SHADER( pyro_vision_ps20b );
  462. }
  463. else
  464. {
  465. DECLARE_STATIC_PIXEL_SHADER( pyro_vision_ps20 );
  466. SET_STATIC_PIXEL_SHADER_COMBO( EFFECT, params[ EFFECT ]->GetIntValue() );
  467. SET_STATIC_PIXEL_SHADER_COMBO( VERTEX_LIT, bVertexLit );
  468. SET_STATIC_PIXEL_SHADER_COMBO( BASETEXTURE2, bHasBaseTexture2 );
  469. SET_STATIC_PIXEL_SHADER_COMBO( FANCY_BLENDING, bHasBlendModulateTexture );
  470. SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM, bSelfIllum );
  471. SET_STATIC_PIXEL_SHADER_COMBO( COLOR_BAR, bHasColorbar );
  472. SET_STATIC_PIXEL_SHADER_COMBO( STRIPES, bHasStripes );
  473. SET_STATIC_PIXEL_SHADER_COMBO( STRIPES_USE_NORMAL2, bHasStripesNormal2 );
  474. SET_STATIC_PIXEL_SHADER( pyro_vision_ps20 );
  475. }
  476. }
  477. else
  478. {
  479. DECLARE_STATIC_VERTEX_SHADER( pyro_vision_vs30 );
  480. SET_STATIC_VERTEX_SHADER_COMBO( EFFECT, params[ EFFECT ]->GetIntValue() );
  481. SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR ) );
  482. SET_STATIC_VERTEX_SHADER_COMBO( VERTEX_LIT, bVertexLit );
  483. SET_STATIC_VERTEX_SHADER_COMBO( FULLBRIGHT, bFullBright );
  484. SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, bHalfLambert );
  485. SET_STATIC_VERTEX_SHADER_COMBO( BASETEXTURE2, bHasBaseTexture2 );
  486. SET_STATIC_VERTEX_SHADER_COMBO( STRIPES, bHasStripes );
  487. SET_STATIC_VERTEX_SHADER_COMBO( STRIPES_USE_NORMAL2, bHasStripesNormal2 );
  488. SET_STATIC_VERTEX_SHADER( pyro_vision_vs30 );
  489. DECLARE_STATIC_PIXEL_SHADER( pyro_vision_ps30 );
  490. SET_STATIC_PIXEL_SHADER_COMBO( EFFECT, params[ EFFECT ]->GetIntValue() );
  491. SET_STATIC_PIXEL_SHADER_COMBO( VERTEX_LIT, bVertexLit );
  492. SET_STATIC_PIXEL_SHADER_COMBO( BASETEXTURE2, bHasBaseTexture2 );
  493. SET_STATIC_PIXEL_SHADER_COMBO( FANCY_BLENDING, bHasBlendModulateTexture );
  494. SET_STATIC_PIXEL_SHADER_COMBO( SELFILLUM, bSelfIllum );
  495. SET_STATIC_PIXEL_SHADER_COMBO( COLOR_BAR, bHasColorbar );
  496. SET_STATIC_PIXEL_SHADER_COMBO( STRIPES, bHasStripes );
  497. SET_STATIC_PIXEL_SHADER_COMBO( STRIPES_USE_NORMAL2, bHasStripesNormal2 );
  498. SET_STATIC_PIXEL_SHADER( pyro_vision_ps30 );
  499. }
  500. }
  501. DYNAMIC_STATE
  502. {
  503. CCommandBufferBuilder< CFixedCommandStorageBuffer< 1000 > > DynamicCmdsOut;
  504. DynamicCmdsOut.Call( pContextData->m_pStaticCmds );
  505. DynamicCmdsOut.Call( pContextData->m_SemiStaticCmdsOut.Base() );
  506. pShaderAPI->SetDefaultState();
  507. bool bWriteDepthToAlpha;
  508. if( bFullyOpaque )
  509. {
  510. bWriteDepthToAlpha = pShaderAPI->ShouldWriteDepthToDestAlpha();
  511. }
  512. else
  513. {
  514. //can't write a special value to dest alpha if we're actually using as-intended alpha
  515. bWriteDepthToAlpha = false;
  516. }
  517. Vector4D vParms;
  518. vParms.x = bWriteDepthToAlpha ? 1.0f : 0.0f;
  519. vParms.y = pShaderAPI->CurrentTime();
  520. vParms.z = 0.0f;
  521. vParms.w = 0.0f;
  522. DynamicCmdsOut.SetPixelShaderConstant( 12, vParms.Base() );
  523. int numBones = pShaderAPI->GetCurrentNumBones();
  524. LightState_t lightState = { 0, false, false };
  525. if ( bVertexLit && !bFullBright )
  526. {
  527. pShaderAPI->GetDX9LightState( &lightState );
  528. }
  529. if ( !g_pHardwareConfig->HasFastVertexTextures() )
  530. {
  531. DECLARE_DYNAMIC_VERTEX_SHADER( pyro_vision_vs20 );
  532. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, numBones > 0 );
  533. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  534. SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, lightState.HasDynamicLight() );
  535. SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLightVertex ? 1 : 0 );
  536. SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, bUseStaticControlFlow ? 0 : lightState.m_nNumLights );
  537. SET_DYNAMIC_VERTEX_SHADER( pyro_vision_vs20 );
  538. if ( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  539. {
  540. DECLARE_DYNAMIC_PIXEL_SHADER( pyro_vision_ps20b );
  541. SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() );
  542. SET_DYNAMIC_PIXEL_SHADER_COMBO( VISUALIZE_DOF, bVisualizeDoF );
  543. SET_DYNAMIC_PIXEL_SHADER_COMBO( HEATHAZE, bHasHeatHaze );
  544. SET_DYNAMIC_PIXEL_SHADER( pyro_vision_ps20b );
  545. }
  546. else
  547. {
  548. DECLARE_DYNAMIC_PIXEL_SHADER( pyro_vision_ps20 );
  549. SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() );
  550. SET_DYNAMIC_PIXEL_SHADER_COMBO( VISUALIZE_DOF, bVisualizeDoF );
  551. SET_DYNAMIC_PIXEL_SHADER_COMBO( HEATHAZE, bHasHeatHaze );
  552. SET_DYNAMIC_PIXEL_SHADER( pyro_vision_ps20 );
  553. }
  554. }
  555. else
  556. {
  557. DECLARE_DYNAMIC_VERTEX_SHADER( pyro_vision_vs30 );
  558. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, numBones > 0 );
  559. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  560. SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, lightState.HasDynamicLight() );
  561. SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLightVertex ? 1 : 0 );
  562. SET_DYNAMIC_VERTEX_SHADER( pyro_vision_vs30 );
  563. DECLARE_DYNAMIC_PIXEL_SHADER( pyro_vision_ps30 );
  564. SET_DYNAMIC_PIXEL_SHADER_COMBO( PIXELFOGTYPE, pShaderAPI->GetPixelFogCombo() );
  565. SET_DYNAMIC_PIXEL_SHADER_COMBO( VISUALIZE_DOF, bVisualizeDoF );
  566. SET_DYNAMIC_PIXEL_SHADER_COMBO( HEATHAZE, bHasHeatHaze );
  567. SET_DYNAMIC_PIXEL_SHADER( pyro_vision_ps30 );
  568. }
  569. DynamicCmdsOut.End();
  570. pShaderAPI->ExecuteCommandBuffer( DynamicCmdsOut.Base() );
  571. }
  572. Draw();
  573. }
  574. END_SHADER