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.

538 lines
22 KiB

  1. //========= Copyright (c) Valve Corporation, All rights reserved. ============//
  2. #include "BaseVSShader.h"
  3. #include "solidenergy_dx9_helper.h"
  4. #include "cpp_shader_constant_register_map.h"
  5. // Auto generated inc files
  6. #include "solidenergy_vs20.inc"
  7. #include "solidenergy_ps20b.inc"
  8. #include "common_hlsl_cpp_consts.h"
  9. #if !defined( _GAMECONSOLE )
  10. #include "solidenergy_vs30.inc"
  11. #include "solidenergy_ps30.inc"
  12. #endif
  13. #include "shaderlib/commandbuilder.h"
  14. void InitParamsSolidEnergy( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, SolidEnergyVars_t &info )
  15. {
  16. static ConVarRef gpu_level( "gpu_level" );
  17. int nGPULevel = gpu_level.GetInt();
  18. // Set material parameter default values
  19. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nDetail1Scale, kDefaultDetailScale );
  20. SET_PARAM_INT_IF_NOT_DEFINED( info.m_nDetail1Frame, kDefaultDetailFrame );
  21. SET_PARAM_INT_IF_NOT_DEFINED( info.m_nDetail1BlendMode, kDefaultDetailBlendMode );
  22. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nDetail2Scale, kDefaultDetailScale );
  23. SET_PARAM_INT_IF_NOT_DEFINED( info.m_nDetail2Frame, kDefaultDetailFrame );
  24. SET_PARAM_INT_IF_NOT_DEFINED( info.m_nDetail2BlendMode, kDefaultDetailBlendMode );
  25. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nDepthBlendScale, kDefaultDepthBlendScale );
  26. SET_PARAM_INT_IF_NOT_DEFINED( info.m_nNeedsTangentT, IS_PARAM_DEFINED( info.m_nTangentTOpacityRanges ) && ( nGPULevel > 1 ) );
  27. SET_PARAM_INT_IF_NOT_DEFINED( info.m_nNeedsTangentS, IS_PARAM_DEFINED( info.m_nTangentSOpacityRanges )&& ( nGPULevel > 1 ) );
  28. SET_PARAM_INT_IF_NOT_DEFINED( info.m_nNeedsNormals, IS_PARAM_DEFINED( info.m_nFresnelOpacityRanges )&& ( nGPULevel > 1 ) );
  29. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nFlowWorldUVScale, kDefaultDetailScale );
  30. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nFlowNormalUVScale, kDefaultDetailScale );
  31. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nFlowTimeIntervalInSeconds, kDefaultTimescale );
  32. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nFlowUVScrollDistance, kDefaultScrollDist );
  33. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nFlowNoiseScale, kDefaultNoiseScale );
  34. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nPowerUp, kDefaultPowerUpIntensity );
  35. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nFlowColorIntensity, kDefaultIntensity );
  36. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nFlowVortexSize, kDefaultVortexSize );
  37. SET_PARAM_VEC_IF_NOT_DEFINED( info.m_nFlowColor, kDefaultFieldColor, 3 );
  38. SET_PARAM_VEC_IF_NOT_DEFINED( info.m_nFlowVortexColor, kDefaultVortexColor, 3 );
  39. SET_PARAM_INT_IF_NOT_DEFINED( info.m_nFlowCheap, nGPULevel < 2 );
  40. SET_PARAM_INT_IF_NOT_DEFINED( info.m_nModel, 0 );
  41. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nOutputIntensity, 1.0f );
  42. if ( nGPULevel < 2 )
  43. {
  44. params[info.m_nDetail2Texture]->SetUndefined();
  45. }
  46. }
  47. void InitSolidEnergy( CBaseVSShader *pShader, IMaterialVar** params, SolidEnergyVars_t &info )
  48. {
  49. // Load textures
  50. if ( ( info.m_nBaseTexture != -1 ) && params[info.m_nBaseTexture]->IsDefined() )
  51. {
  52. pShader->LoadTexture( info.m_nBaseTexture, TEXTUREFLAGS_SRGB );
  53. }
  54. if ( ( info.m_nDetail1Texture != -1 ) && params[info.m_nDetail1Texture]->IsDefined() )
  55. {
  56. pShader->LoadTexture( info.m_nDetail1Texture, TEXTUREFLAGS_SRGB );
  57. }
  58. if ( ( info.m_nDetail2Texture != -1 ) && params[info.m_nDetail2Texture]->IsDefined() )
  59. {
  60. pShader->LoadTexture( info.m_nDetail2Texture, TEXTUREFLAGS_SRGB );
  61. }
  62. if ( ( info.m_nFlowMap != -1 ) && params[info.m_nFlowMap]->IsDefined() )
  63. {
  64. pShader->LoadTexture( info.m_nFlowMap );
  65. if ( ( info.m_nFlowNoiseTexture != -1 ) && params[info.m_nFlowNoiseTexture]->IsDefined() )
  66. {
  67. pShader->LoadTexture( info.m_nFlowNoiseTexture );
  68. }
  69. if ( ( info.m_nFlowBoundsTexture != -1 ) && params[info.m_nFlowBoundsTexture]->IsDefined() )
  70. {
  71. pShader->LoadTexture( info.m_nFlowBoundsTexture );
  72. }
  73. }
  74. if ( ( info.m_nModel != -1 ) && ( params[info.m_nModel]->GetIntValue() != 0 ) )
  75. {
  76. SET_FLAGS( MATERIAL_VAR_MODEL );
  77. }
  78. SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
  79. }
  80. class CSolidEnergy_DX9_Context : public CBasePerMaterialContextData
  81. {
  82. public:
  83. CCommandBufferBuilder< CFixedCommandStorageBuffer< 800 > > m_SemiStaticCmdsOut;
  84. };
  85. void DrawSolidEnergy( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI,
  86. IShaderShadow* pShaderShadow, SolidEnergyVars_t &info, VertexCompressionType_t vertexCompression,
  87. CBasePerMaterialContextData **pContextDataPtr )
  88. {
  89. CSolidEnergy_DX9_Context *pContextData = reinterpret_cast< CSolidEnergy_DX9_Context *> ( *pContextDataPtr );
  90. bool bAlphaBlend = IS_FLAG_SET( MATERIAL_VAR_TRANSLUCENT );
  91. bool bDetail1 = ( info.m_nDetail1Texture != -1 ) && params[info.m_nDetail1Texture]->IsTexture();
  92. bool bDetail2 = bDetail1 && ( info.m_nDetail2Texture != -1 ) && params[info.m_nDetail2Texture]->IsTexture();
  93. bool bDepthBlend = bAlphaBlend && ( info.m_nDepthBlend != -1 ) && ( params[info.m_nDepthBlend]->GetIntValue() != 0 );
  94. bool bHasFlowmap = !bDetail1 && ( info.m_nFlowMap != -1 ) && params[info.m_nFlowMap]->IsTexture();
  95. bool bHasCheapFlow = !( IsGameConsole() ) && bHasFlowmap && ( params[info.m_nFlowCheap]->GetIntValue() != 0 );
  96. if ( pShader->IsSnapshotting() || (! pContextData ) || ( pContextData->m_bMaterialVarsChanged ) )
  97. {
  98. bool bAdditiveBlend = IS_FLAG_SET( MATERIAL_VAR_ADDITIVE );
  99. bool bHasVertexColor = IS_FLAG_SET( MATERIAL_VAR_VERTEXCOLOR );
  100. bool bHasVertexAlpha = IS_FLAG_SET( MATERIAL_VAR_VERTEXALPHA );
  101. bool bModel = IS_FLAG_SET( MATERIAL_VAR_MODEL );
  102. bool bTangentT = ( info.m_nNeedsTangentT != -1 ) && params[info.m_nNeedsTangentT]->GetIntValue();
  103. bool bTangentS = ( info.m_nNeedsTangentS != -1 ) && params[info.m_nNeedsTangentS]->GetIntValue();
  104. if ( bTangentS && bTangentT ) // If both on, T wins
  105. {
  106. bTangentS = false;
  107. }
  108. bool bFresnel = !bTangentS && !bTangentT && ( info.m_nNeedsNormals != -1 ) && params[info.m_nNeedsNormals]->GetIntValue();
  109. int nDetail1BlendMode = ( info.m_nDetail1BlendMode != -1 ) ? params[info.m_nDetail1BlendMode]->GetIntValue() : kDefaultDetailBlendMode;
  110. nDetail1BlendMode = bDetail1 ? clamp( nDetail1BlendMode, 0, kMaxDetailBlendMode ) : 0;
  111. int nDetail2BlendMode = ( info.m_nDetail2BlendMode != -1 ) ? params[info.m_nDetail2BlendMode]->GetIntValue() : kDefaultDetailBlendMode;
  112. nDetail2BlendMode = bDetail2 ? clamp( nDetail2BlendMode, 0, kMaxDetailBlendMode ) : 0;
  113. if ( pShader->IsSnapshotting() )
  114. {
  115. // Set stream format (note that this shader supports compression)
  116. int userDataSize = 0;
  117. unsigned int flags = VERTEX_POSITION | VERTEX_FORMAT_COMPRESSED;
  118. if ( !bModel && ( bTangentS || bTangentT || bHasFlowmap ) )
  119. {
  120. flags |= VERTEX_TANGENT_S;
  121. flags |= VERTEX_TANGENT_T;
  122. }
  123. if ( bModel && ( bTangentS || bTangentT || bHasFlowmap ) )
  124. {
  125. flags |= VERTEX_USERDATA_SIZE( 4 );
  126. userDataSize = 4;
  127. }
  128. if ( bModel || bFresnel || bTangentS || bTangentT || bHasFlowmap )
  129. {
  130. flags |= VERTEX_NORMAL;
  131. }
  132. if ( bHasVertexColor || bHasVertexAlpha )
  133. {
  134. flags |= VERTEX_COLOR;
  135. }
  136. int nTexCoordCount = 1;
  137. pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize );
  138. // Vertex Shader
  139. #if !defined( _GAMECONSOLE )
  140. if ( g_pHardwareConfig->GetDXSupportLevel() < 95 )
  141. #endif
  142. {
  143. DECLARE_STATIC_VERTEX_SHADER( solidenergy_vs20 );
  144. SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, bHasVertexColor || bHasVertexAlpha );
  145. SET_STATIC_VERTEX_SHADER_COMBO( DETAIL1, bDetail1 );
  146. SET_STATIC_VERTEX_SHADER_COMBO( DETAIL2, bDetail2 );
  147. SET_STATIC_VERTEX_SHADER_COMBO( TANGENTTOPACITY, bTangentT );
  148. SET_STATIC_VERTEX_SHADER_COMBO( TANGENTSOPACITY, bTangentS );
  149. SET_STATIC_VERTEX_SHADER_COMBO( FRESNELOPACITY, bFresnel );
  150. SET_STATIC_VERTEX_SHADER_COMBO( FLOWMAP, bHasFlowmap );
  151. SET_STATIC_VERTEX_SHADER_COMBO( MODELFORMAT, bModel );
  152. SET_STATIC_VERTEX_SHADER( solidenergy_vs20 );
  153. }
  154. #if !defined( _GAMECONSOLE )
  155. else
  156. {
  157. DECLARE_STATIC_VERTEX_SHADER( solidenergy_vs30 );
  158. SET_STATIC_VERTEX_SHADER_COMBO( VERTEXCOLOR, bHasVertexColor || bHasVertexAlpha );
  159. SET_STATIC_VERTEX_SHADER_COMBO( DETAIL1, bDetail1 );
  160. SET_STATIC_VERTEX_SHADER_COMBO( DETAIL2, bDetail2 );
  161. SET_STATIC_VERTEX_SHADER_COMBO( TANGENTTOPACITY, bTangentT );
  162. SET_STATIC_VERTEX_SHADER_COMBO( TANGENTSOPACITY, bTangentS );
  163. SET_STATIC_VERTEX_SHADER_COMBO( FRESNELOPACITY, bFresnel );
  164. SET_STATIC_VERTEX_SHADER_COMBO( FLOWMAP, bHasFlowmap );
  165. SET_STATIC_VERTEX_SHADER_COMBO( MODELFORMAT, bModel );
  166. SET_STATIC_VERTEX_SHADER( solidenergy_vs30 );
  167. }
  168. #endif
  169. // Pixel Shader
  170. #if !defined( _GAMECONSOLE )
  171. if ( g_pHardwareConfig->GetDXSupportLevel() < 95 )
  172. #endif
  173. {
  174. DECLARE_STATIC_PIXEL_SHADER( solidenergy_ps20b );
  175. SET_STATIC_PIXEL_SHADER_COMBO( ADDITIVE, bAdditiveBlend );
  176. SET_STATIC_PIXEL_SHADER_COMBO( DETAIL1, bDetail1 );
  177. SET_STATIC_PIXEL_SHADER_COMBO( DETAIL2, bDetail2 );
  178. SET_STATIC_PIXEL_SHADER_COMBO( DETAIL1BLENDMODE, nDetail1BlendMode );
  179. SET_STATIC_PIXEL_SHADER_COMBO( DETAIL2BLENDMODE, nDetail2BlendMode );
  180. SET_STATIC_PIXEL_SHADER_COMBO( VERTEXCOLOR, ( bHasVertexColor || bHasVertexAlpha ) );
  181. SET_STATIC_PIXEL_SHADER_COMBO( TANGENTTOPACITY, bTangentT );
  182. SET_STATIC_PIXEL_SHADER_COMBO( TANGENTSOPACITY, bTangentS );
  183. SET_STATIC_PIXEL_SHADER_COMBO( FRESNELOPACITY, bFresnel );
  184. SET_STATIC_PIXEL_SHADER_COMBO( DEPTHBLEND, bDepthBlend );
  185. SET_STATIC_PIXEL_SHADER_COMBO( FLOWMAP, bHasFlowmap );
  186. SET_STATIC_PIXEL_SHADER_COMBO( FLOW_CHEAP, bHasCheapFlow );
  187. SET_STATIC_PIXEL_SHADER( solidenergy_ps20b );
  188. }
  189. #if !defined( _GAMECONSOLE )
  190. else
  191. {
  192. DECLARE_STATIC_PIXEL_SHADER( solidenergy_ps30 );
  193. SET_STATIC_PIXEL_SHADER_COMBO( ADDITIVE, bAdditiveBlend );
  194. SET_STATIC_PIXEL_SHADER_COMBO( DETAIL1, bDetail1 );
  195. SET_STATIC_PIXEL_SHADER_COMBO( DETAIL2, bDetail2 );
  196. SET_STATIC_PIXEL_SHADER_COMBO( DETAIL1BLENDMODE, nDetail1BlendMode );
  197. SET_STATIC_PIXEL_SHADER_COMBO( DETAIL2BLENDMODE, nDetail2BlendMode );
  198. SET_STATIC_PIXEL_SHADER_COMBO( VERTEXCOLOR, ( bHasVertexColor || bHasVertexAlpha ) );
  199. SET_STATIC_PIXEL_SHADER_COMBO( TANGENTTOPACITY, bTangentT );
  200. SET_STATIC_PIXEL_SHADER_COMBO( TANGENTSOPACITY, bTangentS );
  201. SET_STATIC_PIXEL_SHADER_COMBO( FRESNELOPACITY, bFresnel );
  202. SET_STATIC_PIXEL_SHADER_COMBO( DEPTHBLEND, bDepthBlend );
  203. SET_STATIC_PIXEL_SHADER_COMBO( FLOWMAP, bHasFlowmap );
  204. SET_STATIC_PIXEL_SHADER_COMBO( FLOW_CHEAP, bHasCheapFlow );
  205. SET_STATIC_PIXEL_SHADER( solidenergy_ps30 );
  206. }
  207. #endif
  208. // Textures
  209. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); // [sRGB] Base
  210. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true );
  211. if( bDetail1 )
  212. {
  213. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); // [sRGB] Detail11
  214. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true );
  215. }
  216. if( bDetail2 )
  217. {
  218. pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); // [sRGB] Detail12
  219. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER4, true );
  220. }
  221. if ( bDepthBlend )
  222. {
  223. pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); // Depth (consoles only)
  224. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, false );
  225. }
  226. if ( bHasFlowmap )
  227. {
  228. pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); // Flow map
  229. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER5, false );
  230. pShaderShadow->EnableTexture( SHADER_SAMPLER6, true ); // Flow map noise
  231. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER6, false );
  232. pShaderShadow->EnableTexture( SHADER_SAMPLER7, true ); // Flow map bounds
  233. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER7, false );
  234. }
  235. if ( bAlphaBlend )
  236. {
  237. if ( bAdditiveBlend )
  238. {
  239. pShader->EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE );
  240. }
  241. else
  242. {
  243. pShader->EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  244. }
  245. pShaderShadow->EnableAlphaWrites( false );
  246. pShaderShadow->EnableDepthWrites( !bDepthBlend && !bAdditiveBlend );
  247. }
  248. else
  249. {
  250. pShader->DisableAlphaBlending();
  251. pShaderShadow->EnableAlphaWrites( true );
  252. pShaderShadow->EnableDepthWrites( true );
  253. }
  254. pShaderShadow->EnableSRGBWrite( true );
  255. }
  256. if ( pShaderAPI && ( (! pContextData ) || ( pContextData->m_bMaterialVarsChanged ) ) )
  257. {
  258. if ( !pContextData ) // make sure allocated
  259. {
  260. pContextData = new CSolidEnergy_DX9_Context;
  261. *pContextDataPtr = pContextData;
  262. }
  263. pContextData->m_bMaterialVarsChanged = false;
  264. pContextData->m_SemiStaticCmdsOut.Reset();
  265. ///////////////////////////
  266. // Semi-static block
  267. ///////////////////////////
  268. float flConsts[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  269. // VS consts
  270. if ( info.m_nBaseTextureTransform != -1 )
  271. pContextData->m_SemiStaticCmdsOut.SetVertexShaderTextureTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, info.m_nBaseTextureTransform ); // 0-1
  272. if ( IS_PARAM_DEFINED( info.m_nDetail1TextureTransform ) )
  273. pContextData->m_SemiStaticCmdsOut.SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, info.m_nDetail1TextureTransform, info.m_nDetail1Scale ); // 2-3
  274. else
  275. pContextData->m_SemiStaticCmdsOut.SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, info.m_nBaseTextureTransform, info.m_nDetail1Scale );
  276. if ( IS_PARAM_DEFINED( info.m_nDetail2TextureTransform ) )
  277. pContextData->m_SemiStaticCmdsOut.SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, info.m_nDetail2TextureTransform, info.m_nDetail2Scale ); // 6-7
  278. else
  279. pContextData->m_SemiStaticCmdsOut.SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, info.m_nBaseTextureTransform, info.m_nDetail2Scale );
  280. // PS Constants
  281. pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER0, TEXTURE_BINDFLAGS_SRGBREAD, BASETEXTURE, -1 );
  282. if( bHasFlowmap )
  283. {
  284. pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER5, TEXTURE_BINDFLAGS_NONE, info.m_nFlowMap, info.m_nFlowMapFrame );
  285. pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER6, TEXTURE_BINDFLAGS_NONE, info.m_nFlowNoiseTexture, -1 );
  286. pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER7, TEXTURE_BINDFLAGS_NONE, info.m_nFlowBoundsTexture, -1 );
  287. }
  288. if( IS_PARAM_DEFINED( info.m_nTangentTOpacityRanges ) )
  289. params[info.m_nTangentTOpacityRanges]->GetVecValue( flConsts, 4 );
  290. else
  291. memcpy( flConsts, kDefaultFalloffRanges, sizeof( kDefaultFalloffRanges ) );
  292. pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 0, flConsts, 1 );
  293. if( IS_PARAM_DEFINED( info.m_nTangentSOpacityRanges ) )
  294. params[info.m_nTangentSOpacityRanges]->GetVecValue( flConsts, 4 );
  295. else
  296. memcpy( flConsts, kDefaultFalloffRanges, sizeof( kDefaultFalloffRanges ) );
  297. pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 1, flConsts, 1 );
  298. if( IS_PARAM_DEFINED( info.m_nFresnelOpacityRanges ) )
  299. params[info.m_nFresnelOpacityRanges]->GetVecValue( flConsts, 4 );
  300. else
  301. memcpy( flConsts, kDefaultFalloffRanges, sizeof( kDefaultFalloffRanges ) );
  302. pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 2, flConsts, 1 );
  303. #ifndef _PS3
  304. pContextData->m_SemiStaticCmdsOut.SetDepthFeatheringShaderConstants( 4, params[info.m_nDepthBlendScale]->GetFloatValue() );
  305. #endif
  306. float flOutputIntensity = params[ info.m_nOutputIntensity ]->GetFloatValue();
  307. if ( bHasFlowmap )
  308. {
  309. float vFlowConst1[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  310. vFlowConst1[0] = params[ info.m_nFlowWorldUVScale ]->GetFloatValue();
  311. vFlowConst1[1] = 0.0f; // Empty
  312. vFlowConst1[2] = 0.0f; // Empty
  313. vFlowConst1[3] = flOutputIntensity;
  314. pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 6, vFlowConst1, 1 );
  315. float vFlowConst2[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  316. vFlowConst2[0] = params[ info.m_nFlowTimeIntervalInSeconds ]->GetFloatValue();
  317. vFlowConst2[1] = params[ info.m_nFlowUVScrollDistance ]->GetFloatValue();
  318. vFlowConst2[2] = 0.0f;
  319. vFlowConst2[3] = params[ info.m_nFlowLerpExp ]->GetFloatValue();
  320. pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 7, vFlowConst2, 1 );
  321. float vFlowConst3[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  322. params[info.m_nFlowColor]->GetVecValue( vFlowConst3, 3 );
  323. vFlowConst3[3] = 0.0f; // Empty
  324. pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 8, vFlowConst3, 1 );
  325. float vFlowConst4[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  326. params[info.m_nFlowVortexColor]->GetVecValue( vFlowConst4, 3 );
  327. vFlowConst4[3] = params[ info.m_nFlowVortexSize ]->GetFloatValue();
  328. pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 9, vFlowConst4, 1 );
  329. }
  330. else
  331. {
  332. float vFlowConst1[4] = { 0.0f, 0.0f, 0.0f, flOutputIntensity };
  333. pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 6, vFlowConst1, 1 );
  334. }
  335. pContextData->m_SemiStaticCmdsOut.End();
  336. }
  337. }
  338. if ( pShaderAPI ) //DYNAMIC_STATE
  339. {
  340. if ( IsPC() && pShaderAPI->InFlashlightMode() )
  341. {
  342. // Don't draw anything for the flashlight pass
  343. pShader->Draw( false );
  344. return;
  345. }
  346. #ifdef _PS3
  347. CCommandBufferBuilder< CDynamicCommandStorageBuffer > DynamicCmdsOut;
  348. ShaderApiFast( pShaderAPI )->ExecuteCommandBuffer( pContextData->m_SemiStaticCmdsOut.Base() );
  349. #else
  350. CCommandBufferBuilder< CFixedCommandStorageBuffer< 400 > > DynamicCmdsOut;
  351. DynamicCmdsOut.Call( pContextData->m_SemiStaticCmdsOut.Base() );
  352. #endif
  353. ///////////////////////////
  354. // dynamic block
  355. ///////////////////////////
  356. bool bWriteDepthToAlpha = pShaderAPI->ShouldWriteDepthToDestAlpha() && !bAlphaBlend;
  357. float flPowerUp = params[ info.m_nPowerUp ]->GetFloatValue();
  358. float flIntensity = params[info.m_nFlowColorIntensity]->GetFloatValue();
  359. bool bActive = ( flIntensity > 0.0f );
  360. if ( ( bHasFlowmap ) && ( flPowerUp <= 0.0f ) )
  361. {
  362. bActive = false;
  363. }
  364. bool bPowerup = bActive && bHasFlowmap && ( flPowerUp > 0.0f && flPowerUp < 1.0f );
  365. bool bVortex1 = bActive && bHasFlowmap && ( info.m_nFlowVortex1 != -1 ) && ( params[info.m_nFlowVortex1]->GetIntValue() != 0 );
  366. bool bVortex2 = bActive && bHasFlowmap && ( info.m_nFlowVortex2 != -1 ) && ( params[info.m_nFlowVortex2]->GetIntValue() != 0 );
  367. // VERTEX SHADER SETUP
  368. #if !defined( _GAMECONSOLE )
  369. if ( g_pHardwareConfig->GetDXSupportLevel() < 95 )
  370. #endif
  371. {
  372. DECLARE_DYNAMIC_VERTEX_SHADER( solidenergy_vs20 );
  373. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  374. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
  375. SET_DYNAMIC_VERTEX_SHADER_COMBO( VORTEX1, bVortex1 );
  376. SET_DYNAMIC_VERTEX_SHADER_COMBO( VORTEX2, bVortex2 );
  377. SET_DYNAMIC_VERTEX_SHADER( solidenergy_vs20 );
  378. }
  379. #if !defined( _GAMECONSOLE )
  380. else
  381. {
  382. DECLARE_DYNAMIC_VERTEX_SHADER( solidenergy_vs30 );
  383. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  384. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
  385. SET_DYNAMIC_VERTEX_SHADER_COMBO( VORTEX1, bVortex1 );
  386. SET_DYNAMIC_VERTEX_SHADER_COMBO( VORTEX2, bVortex2 );
  387. SET_DYNAMIC_VERTEX_SHADER( solidenergy_vs30 );
  388. }
  389. #endif
  390. // VS constants
  391. float flConsts[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  392. // Get viewport and render target dimensions and set shader constant to do a 2D mad
  393. int nViewportX, nViewportY, nViewportWidth, nViewportHeight;
  394. pShaderAPI->GetCurrentViewport( nViewportX, nViewportY, nViewportWidth, nViewportHeight );
  395. int nRtWidth, nRtHeight;
  396. pShaderAPI->GetCurrentRenderTargetDimensions( nRtWidth, nRtHeight );
  397. pShaderAPI->GetWorldSpaceCameraPosition( flConsts );
  398. flConsts[3] = 0.0f;
  399. DynamicCmdsOut.SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, flConsts, 1 );
  400. // Compute viewport mad that takes projection space coords (post divide by W) into normalized screenspace, taking into account the currently set viewport.
  401. flConsts[0] = .5f * ( ( float )nViewportWidth / ( float )nRtWidth );
  402. flConsts[1] = -.5f * ( ( float )nViewportHeight / ( float )nRtHeight );
  403. flConsts[2] = flConsts[0] + ( ( float )nViewportX / ( float )nRtWidth );
  404. flConsts[3] = -flConsts[1] + ( ( float )nViewportY / ( float )nRtHeight );
  405. DynamicCmdsOut.SetPixelShaderConstant( DEPTH_FEATHER_VIEWPORT_MAD, flConsts, 1 );
  406. if( bHasFlowmap )
  407. {
  408. float vFlowConst1[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  409. params[info.m_nFlowVortexPos1]->GetVecValue( vFlowConst1, 3 );
  410. vFlowConst1[3] = params[ info.m_nFlowNoiseScale ]->GetFloatValue();
  411. DynamicCmdsOut.SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_9, vFlowConst1, 1 );
  412. float vFlowConst2[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  413. params[info.m_nFlowVortexPos2]->GetVecValue( vFlowConst2, 3 );
  414. vFlowConst2[3] = params[ info.m_nFlowNormalUVScale ]->GetFloatValue();
  415. DynamicCmdsOut.SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_10, vFlowConst2, 1 );
  416. }
  417. // PIXEL SHADER SETUP
  418. #if !defined( _GAMECONSOLE )
  419. if ( g_pHardwareConfig->GetDXSupportLevel() < 95 )
  420. #endif
  421. {
  422. DECLARE_DYNAMIC_PIXEL_SHADER( solidenergy_ps20b );
  423. SET_DYNAMIC_PIXEL_SHADER_COMBO( ACTIVE, bActive );
  424. SET_DYNAMIC_PIXEL_SHADER_COMBO( POWERUP, bPowerup );
  425. SET_DYNAMIC_PIXEL_SHADER_COMBO( VORTEX1, bVortex1 );
  426. SET_DYNAMIC_PIXEL_SHADER_COMBO( VORTEX2, bVortex2 );
  427. SET_DYNAMIC_PIXEL_SHADER( solidenergy_ps20b );
  428. }
  429. #if !defined( _GAMECONSOLE )
  430. else
  431. {
  432. DECLARE_DYNAMIC_PIXEL_SHADER( solidenergy_ps30 );
  433. SET_DYNAMIC_PIXEL_SHADER_COMBO( ACTIVE, bActive );
  434. SET_DYNAMIC_PIXEL_SHADER_COMBO( POWERUP, bPowerup );
  435. SET_DYNAMIC_PIXEL_SHADER_COMBO( VORTEX1, bVortex1 );
  436. SET_DYNAMIC_PIXEL_SHADER_COMBO( VORTEX2, bVortex2 );
  437. SET_DYNAMIC_PIXEL_SHADER( solidenergy_ps30 );
  438. }
  439. #endif
  440. if ( bDetail1 )
  441. {
  442. DynamicCmdsOut.BindTexture( pShader, SHADER_SAMPLER1, TEXTURE_BINDFLAGS_SRGBREAD, info.m_nDetail1Texture, info.m_nDetail1Frame );
  443. }
  444. if ( bDetail2 )
  445. {
  446. DynamicCmdsOut.BindTexture( pShader, SHADER_SAMPLER4, TEXTURE_BINDFLAGS_SRGBREAD, info.m_nDetail2Texture, info.m_nDetail2Frame );
  447. }
  448. if ( bDepthBlend )
  449. {
  450. DynamicCmdsOut.BindStandardTexture( SHADER_SAMPLER3, TEXTURE_BINDFLAGS_NONE, TEXTURE_FRAME_BUFFER_FULL_DEPTH );
  451. }
  452. flConsts[0] = bWriteDepthToAlpha ? 1.0f : 0.0f;
  453. flConsts[1] = pShaderAPI->CurrentTime();
  454. flConsts[2] = params[ info.m_nPowerUp ]->GetFloatValue();
  455. flConsts[3] = params[info.m_nFlowColorIntensity]->GetFloatValue();
  456. DynamicCmdsOut.SetPixelShaderConstant( 3, flConsts, 1 );
  457. DynamicCmdsOut.End();
  458. // end dynamic block
  459. #ifdef _PS3
  460. pShaderAPI->SetDepthFeatheringShaderConstants( 4, params[info.m_nDepthBlendScale]->GetFloatValue() );
  461. #endif
  462. pShaderAPI->ExecuteCommandBuffer( DynamicCmdsOut.Base() );
  463. //no dynamic combos
  464. }
  465. pShader->Draw();
  466. }