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.

533 lines
23 KiB

  1. //========= Copyright (c) Valve Corporation, All rights reserved. ============//
  2. #include "BaseVSShader.h"
  3. #include "weapondecal_dx9_helper.h"
  4. #include "cpp_shader_constant_register_map.h"
  5. // Auto generated inc files
  6. #include "weapondecal_vs20.inc"
  7. #include "weapondecal_vs30.inc"
  8. #include "weapondecal_ps20b.inc"
  9. #include "weapondecal_ps30.inc"
  10. #include "common_hlsl_cpp_consts.h"
  11. #include "shaderlib/commandbuilder.h"
  12. void InitParamsWeaponDecal( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, WeaponDecalVars_t &info )
  13. {
  14. //static ConVarRef gpu_level( "gpu_level" );
  15. //int nGPULevel = gpu_level.GetInt();
  16. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nWearProgress, kDefaultWearProgress );
  17. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nWearRemapMin, kDefaultWearRemapMin );
  18. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nWearRemapMid, kDefaultWearRemapMid );
  19. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nWearRemapMax, kDefaultWearRemapMax );
  20. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nWearWidthMin, kDefaultWearWidthMin );
  21. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nWearWidthMax, kDefaultWearWidthMax );
  22. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nUnWearStrength, kDefaultUnWearStrength );
  23. SET_PARAM_INT_IF_NOT_DEFINED( info.m_nPhong, kDefaultPhong );
  24. SET_PARAM_INT_IF_NOT_DEFINED( info.m_nPhongExponent, kDefaultPhongExponent );
  25. SET_PARAM_VEC_IF_NOT_DEFINED( info.m_nPhongFresnelRanges, kDefaultPhongFresnelRanges, 3 );
  26. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nPhongAlbedoTint, kDefaultPhongAlbedoTint );
  27. SET_PARAM_INT_IF_NOT_DEFINED( info.m_nPhongBoost, kDefaultPhongBoost );
  28. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nPhongAlbedoBoost, kDefaultPhongAlbedoBoost );
  29. SET_PARAM_VEC_IF_NOT_DEFINED( info.m_nEnvmapTint, kDefaultEnvmapTint, 3 );
  30. SET_PARAM_INT_IF_NOT_DEFINED( info.m_nDecalStyle, kDefaultDecalStyle );
  31. SET_PARAM_VEC_IF_NOT_DEFINED( info.m_nColorTint, kDefaultColorTint, 3 );
  32. SET_PARAM_VEC_IF_NOT_DEFINED( info.m_nColorTint2, kDefaultColorTint2, 3 );
  33. SET_PARAM_VEC_IF_NOT_DEFINED( info.m_nColorTint3, kDefaultColorTint3, 3 );
  34. SET_PARAM_VEC_IF_NOT_DEFINED( info.m_nColorTint4, kDefaultColorTint4, 3 );
  35. SET_PARAM_INT_IF_NOT_DEFINED( info.m_nAlpha, kDefaultAlpha );
  36. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nPatternRotation, kDefaultPatternRotation );
  37. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nPatternScale, kDefaultPatternScale );
  38. SET_PARAM_STRING_IF_NOT_DEFINED( info.m_nBaseTexture, kDefaultBaseTexture );
  39. SET_PARAM_STRING_IF_NOT_DEFINED( info.m_nAOTexture, kDefaultAOTexture );
  40. SET_PARAM_STRING_IF_NOT_DEFINED( info.m_nGrungeTexture, kDefaultGrungeTexture );
  41. SET_PARAM_STRING_IF_NOT_DEFINED( info.m_nWearTexture, kDefaultWearTexture );
  42. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nHighlight, kDefaultHighlight );
  43. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nHighlightCycle, kDefaultHighlightCycle );
  44. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nPeel, kDefaultPeel );
  45. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nWearBias, kDefaultWearBias );
  46. SET_PARAM_INT_IF_NOT_DEFINED( info.m_nAlphaMask, kDefaultAlphaMask );
  47. //SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nFastWearThreshold, kDefaultFastWearThreshold );
  48. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nGrungeScale, kDefaultGrungeScale );
  49. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nDesatBaseTint, kDefaultDesatBaseTint );
  50. //SET_FLAGS( MATERIAL_VAR_ALPHATEST );
  51. SET_FLAGS( MATERIAL_VAR_ALPHA_MODIFIED_BY_PROXY );
  52. SET_FLAGS( MATERIAL_VAR_TRANSLUCENT );
  53. //SET_FLAGS( MATERIAL_VAR_DECAL );
  54. SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
  55. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT );
  56. if ( params[info.m_nDecalStyle]->GetIntValue() == 4 )
  57. {
  58. SET_FLAGS2( MATERIAL_VAR2_NEEDS_TANGENT_SPACES );
  59. }
  60. }
  61. void InitWeaponDecal( CBaseVSShader *pShader, IMaterialVar** params, WeaponDecalVars_t &info )
  62. {
  63. // Load textures
  64. if ( ( info.m_nBaseTexture != -1 ) && params[info.m_nBaseTexture]->IsDefined() )
  65. {
  66. pShader->LoadTexture( info.m_nBaseTexture );
  67. }
  68. if ( ( info.m_nAOTexture != -1 ) && params[info.m_nAOTexture]->IsDefined() )
  69. {
  70. pShader->LoadTexture( info.m_nAOTexture );
  71. }
  72. if ( ( info.m_nExpTexture != -1 ) && params[info.m_nExpTexture]->IsDefined() )
  73. {
  74. pShader->LoadTexture( info.m_nExpTexture );
  75. }
  76. if ( ( info.m_nNormalMap != -1 ) && params[info.m_nNormalMap]->IsDefined() )
  77. {
  78. pShader->LoadTexture( info.m_nNormalMap );
  79. }
  80. if ( ( info.m_nEnvmapTexture != -1 ) && params[info.m_nEnvmapTexture]->IsDefined() )
  81. {
  82. pShader->LoadCubeMap( info.m_nEnvmapTexture, TEXTUREFLAGS_SRGB );
  83. }
  84. if ( ( info.m_nGrungeTexture != -1 ) && params[info.m_nGrungeTexture]->IsDefined() )
  85. {
  86. pShader->LoadTexture( info.m_nGrungeTexture );
  87. }
  88. if ( ( info.m_nWearTexture != -1 ) && params[info.m_nWearTexture]->IsDefined() )
  89. {
  90. pShader->LoadTexture( info.m_nWearTexture );
  91. }
  92. if ( ( info.m_nHologramSpectrum != -1 ) && params[info.m_nHologramSpectrum]->IsDefined() )
  93. {
  94. pShader->LoadTexture( info.m_nHologramSpectrum );
  95. }
  96. if ( ( info.m_nHologramMask != -1 ) && params[info.m_nHologramMask]->IsDefined() )
  97. {
  98. pShader->LoadTexture( info.m_nHologramMask );
  99. }
  100. if ( ( info.m_nAnisoDirTexture != -1 ) && params[info.m_nAnisoDirTexture]->IsDefined() )
  101. {
  102. pShader->LoadTexture( info.m_nAnisoDirTexture );
  103. }
  104. }
  105. class CWeaponDecal_DX9_Context : public CBasePerMaterialContextData
  106. {
  107. public:
  108. CCommandBufferBuilder< CFixedCommandStorageBuffer< 800 > > m_SemiStaticCmdsOut;
  109. };
  110. void DrawWeaponDecal( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI,
  111. IShaderShadow* pShaderShadow, WeaponDecalVars_t &info, VertexCompressionType_t vertexCompression,
  112. CBasePerMaterialContextData **pContextDataPtr )
  113. {
  114. CWeaponDecal_DX9_Context *pContextData = reinterpret_cast< CWeaponDecal_DX9_Context *> ( *pContextDataPtr );
  115. bool bPhong = ( info.m_nPhong != -1 ) && ( params[info.m_nPhong]->GetIntValue() == 1 );
  116. bool bMirrorHorizontal = ( info.m_nMirrorHorizontal!= -1 ) && ( params[info.m_nMirrorHorizontal]->GetIntValue() == 1 );
  117. bool bBaseTexture = ( info.m_nBaseTexture != -1 ) && params[info.m_nBaseTexture]->IsTexture();
  118. bool bAOTexture = ( info.m_nAOTexture != -1 ) && params[info.m_nAOTexture ]->IsTexture();
  119. bool bExpTexture = ( info.m_nExpTexture != -1 ) && params[info.m_nExpTexture]->IsTexture();
  120. bool bNormalMap = ( info.m_nNormalMap != -1 ) && params[info.m_nNormalMap]->IsTexture();
  121. bool bEnvmapTexture = ( info.m_nEnvmapTexture != -1 ) && params[info.m_nEnvmapTexture]->IsTexture();
  122. bool bHologramSpectrum = ( info.m_nHologramSpectrum!= -1 ) && params[info.m_nHologramSpectrum]->IsTexture();
  123. bool bHologramMask = ( info.m_nHologramMask != -1 ) && params[info.m_nHologramMask]->IsTexture();
  124. bool bGrungeTexture = ( info.m_nGrungeTexture != -1 ) && params[info.m_nGrungeTexture]->IsTexture();
  125. bool bWearTexture = ( info.m_nWearTexture != -1 ) && params[info.m_nWearTexture]->IsTexture();
  126. bool bAnisoDirTexture = ( info.m_nAnisoDirTexture != -1 ) && params[info.m_nAnisoDirTexture]->IsTexture();
  127. bool bThirdPerson = ( info.m_nThirdPerson != -1 ) && ( params[info.m_nThirdPerson]->GetIntValue() == 1 );
  128. bool bHighlight = ( info.m_nHighlight != -1 ) && ( params[info.m_nHighlight]->GetFloatValue() > 0 );
  129. bool bPeel = ( info.m_nPeel != -1 ) && ( params[info.m_nPeel]->GetFloatValue() > 0 ) && bHighlight == false;
  130. int nDecalStyle = params[info.m_nDecalStyle]->GetIntValue();
  131. bool bAlphaMask = ( info.m_nAlphaMask != -1 ) && ( params[info.m_nAlphaMask]->GetIntValue() == 1 );
  132. bool bSFM = ( ToolsEnabled() && IsPlatformWindowsPC() && g_pHardwareConfig->SupportsPixelShaders_3_0() ) ? true : false;
  133. bool bDesatBaseTint = ( info.m_nDesatBaseTint != -1 ) && ( params[info.m_nDesatBaseTint]->GetFloatValue() > 0 );
  134. //bool bFlashlight = pShader->UsingFlashlight( params );
  135. if ( ( pShader->IsSnapshotting() && pShaderShadow ) || (! pContextData ) || ( pContextData->m_bMaterialVarsChanged ) )
  136. {
  137. if ( pShader->IsSnapshotting() )
  138. {
  139. // Set stream format (note that this shader supports compression)
  140. int userDataSize = 0;
  141. unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED;
  142. int nTexCoordCount = 1;
  143. pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize );
  144. // Vertex Shader
  145. if ( g_pHardwareConfig->SupportsPixelShaders_3_0() )
  146. {
  147. DECLARE_STATIC_VERTEX_SHADER( weapondecal_vs30 );
  148. SET_STATIC_VERTEX_SHADER_COMBO( MIRROR, bMirrorHorizontal );
  149. SET_STATIC_VERTEX_SHADER_COMBO( NORMALMAP, ( nDecalStyle == 4 ) || ( nDecalStyle == 5 ) );
  150. SET_STATIC_VERTEX_SHADER( weapondecal_vs30 );
  151. }
  152. else
  153. {
  154. DECLARE_STATIC_VERTEX_SHADER( weapondecal_vs20 );
  155. SET_STATIC_VERTEX_SHADER_COMBO( MIRROR, bMirrorHorizontal );
  156. SET_STATIC_VERTEX_SHADER_COMBO( NORMALMAP, ( nDecalStyle == 4 ) || ( nDecalStyle == 5 ) );
  157. SET_STATIC_VERTEX_SHADER( weapondecal_vs20 );
  158. }
  159. // Pixel Shader
  160. if ( g_pHardwareConfig->SupportsPixelShaders_3_0() )
  161. {
  162. DECLARE_STATIC_PIXEL_SHADER( weapondecal_ps30 );
  163. SET_STATIC_PIXEL_SHADER_COMBO( ALPHAMASK, bAlphaMask );
  164. SET_STATIC_PIXEL_SHADER_COMBO( PHONG, bPhong );
  165. SET_STATIC_PIXEL_SHADER_COMBO( PHONGEXPONENTTEXTURE, bExpTexture );
  166. SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP, bEnvmapTexture );
  167. SET_STATIC_PIXEL_SHADER_COMBO( DECALSTYLE, nDecalStyle );
  168. SET_STATIC_PIXEL_SHADER_COMBO( THIRDPERSON, bThirdPerson );
  169. SET_STATIC_PIXEL_SHADER_COMBO( CASCADED_SHADOW_MAPPING, g_pHardwareConfig->SupportsCascadedShadowMapping() && !bSFM );
  170. SET_STATIC_PIXEL_SHADER_COMBO( DESATBASETINT, bDesatBaseTint );
  171. SET_STATIC_PIXEL_SHADER( weapondecal_ps30 );
  172. }
  173. else
  174. {
  175. DECLARE_STATIC_PIXEL_SHADER( weapondecal_ps20b );
  176. SET_STATIC_PIXEL_SHADER_COMBO( PHONG, bPhong );
  177. SET_STATIC_PIXEL_SHADER_COMBO( PHONGEXPONENTTEXTURE, bExpTexture );
  178. SET_STATIC_PIXEL_SHADER_COMBO( CUBEMAP, bEnvmapTexture );
  179. SET_STATIC_PIXEL_SHADER_COMBO( DECALSTYLE, nDecalStyle );
  180. SET_STATIC_PIXEL_SHADER_COMBO( THIRDPERSON, bThirdPerson );
  181. SET_STATIC_PIXEL_SHADER_COMBO( DESATBASETINT, bDesatBaseTint );
  182. SET_STATIC_PIXEL_SHADER( weapondecal_ps20b );
  183. }
  184. pShader->EnableAlphaBlending( SHADER_BLEND_SRC_ALPHA, SHADER_BLEND_ONE_MINUS_SRC_ALPHA );
  185. // Textures
  186. if ( bBaseTexture )
  187. {
  188. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); // [sRGB] Base
  189. }
  190. if( bAOTexture && !bThirdPerson )
  191. {
  192. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); // [sRGB] Ambient Occlusion
  193. }
  194. if( bExpTexture )
  195. {
  196. pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); // Exponent
  197. }
  198. //if( bEnvmapTexture )
  199. //{
  200. // pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); // Envmap
  201. //}
  202. if( bWearTexture && !bThirdPerson )
  203. {
  204. pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); // Scratches
  205. }
  206. if( bGrungeTexture && !bThirdPerson )
  207. {
  208. pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); // [sRGB] Grunge
  209. }
  210. if( bHologramSpectrum || bNormalMap )
  211. {
  212. pShaderShadow->EnableTexture( SHADER_SAMPLER6, true ); // Hologram spectrum or normal map
  213. }
  214. if( bHologramMask )
  215. {
  216. pShaderShadow->EnableTexture( SHADER_SAMPLER7, true ); // Hologram spectrum
  217. }
  218. if ( bAnisoDirTexture )
  219. {
  220. pShaderShadow->EnableTexture( SHADER_SAMPLER8, true ); // Anisotropy Direction map
  221. }
  222. //if ( bFlashlight )
  223. //{
  224. // pShader->SetAdditiveBlendingShadowState( info.m_nBaseTexture, true );
  225. //}
  226. pShaderShadow->EnableAlphaWrites( false );
  227. pShaderShadow->EnableDepthWrites( false );
  228. pShaderShadow->EnableSRGBWrite( true );
  229. pShaderShadow->EnableBlending( true );
  230. pShader->PI_BeginCommandBuffer();
  231. pShader->PI_SetPixelShaderAmbientLightCube( PSREG_AMBIENT_CUBE );
  232. pShader->PI_SetPixelShaderLocalLighting( PSREG_LIGHT_INFO_ARRAY );
  233. //pShader->PI_SetModulationPixelShaderDynamicState_LinearColorSpace( 1 );
  234. pShader->PI_EndCommandBuffer();
  235. }
  236. if ( pShaderAPI && ( (! pContextData ) || ( pContextData->m_bMaterialVarsChanged ) ) )
  237. {
  238. if ( !pContextData ) // make sure allocated
  239. {
  240. pContextData = new CWeaponDecal_DX9_Context;
  241. *pContextDataPtr = pContextData;
  242. }
  243. pContextData->m_bMaterialVarsChanged = false;
  244. pContextData->m_SemiStaticCmdsOut.Reset();
  245. ///////////////////////////
  246. // Semi-static block
  247. ///////////////////////////
  248. // VS Constants
  249. //pContextData->m_SemiStaticCmdsOut.SetVertexShaderTextureScaledTransform( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, info.m_nBaseTextureTransform, info.m_nPatternScale );
  250. pContextData->m_SemiStaticCmdsOut.SetVertexShaderTextureScaledTransformRotate( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0,
  251. info.m_nBaseTextureTransform,
  252. info.m_nPatternScale,
  253. info.m_nPatternRotation );
  254. //derive basetexture aspect ratio
  255. float flAspectRatioHeight = 1.0f;
  256. if ( bBaseTexture )
  257. {
  258. ITexture *pBaseTexture = params[info.m_nBaseTexture]->GetTextureValue();
  259. if ( pBaseTexture )
  260. {
  261. float flWidth = pBaseTexture->GetActualWidth();
  262. float flHeight = pBaseTexture->GetActualHeight();
  263. if ( flHeight != 0 )
  264. flAspectRatioHeight = flWidth / flHeight;
  265. }
  266. }
  267. float fvVsConst2[4] = { flAspectRatioHeight, 0.0f, 0.0f, 0.0f };
  268. pContextData->m_SemiStaticCmdsOut.SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, fvVsConst2, 1 );
  269. if ( bBaseTexture )
  270. {
  271. pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER0, TEXTURE_BINDFLAGS_SRGBREAD, info.m_nBaseTexture, -1 );
  272. }
  273. if( bAOTexture && !bThirdPerson )
  274. {
  275. pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER1, TEXTURE_BINDFLAGS_SRGBREAD, info.m_nAOTexture, -1 );
  276. }
  277. if( bExpTexture )
  278. {
  279. pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER2, TEXTURE_BINDFLAGS_NONE, info.m_nExpTexture, -1 );
  280. }
  281. if( bNormalMap && ( nDecalStyle == 4 || nDecalStyle == 5 ) )
  282. {
  283. pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER6, TEXTURE_BINDFLAGS_NONE, info.m_nNormalMap, -1 );
  284. }
  285. if( bEnvmapTexture )
  286. {
  287. pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER3, TEXTURE_BINDFLAGS_SRGBREAD, info.m_nEnvmapTexture, -1 );
  288. }
  289. if( bWearTexture && !bThirdPerson )
  290. {
  291. pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER4, TEXTURE_BINDFLAGS_NONE, info.m_nWearTexture, -1 );
  292. }
  293. if( bGrungeTexture && !bThirdPerson )
  294. {
  295. pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER9, TEXTURE_BINDFLAGS_SRGBREAD, info.m_nGrungeTexture, -1 );
  296. }
  297. if ( bHologramSpectrum && ( nDecalStyle != 4 ) && ( nDecalStyle != 5 ) )
  298. {
  299. pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER6, TEXTURE_BINDFLAGS_SRGBREAD, info.m_nHologramSpectrum, -1 );
  300. }
  301. if( bHologramMask )
  302. {
  303. pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER7, TEXTURE_BINDFLAGS_NONE, info.m_nHologramMask, -1 );
  304. }
  305. if ( bAnisoDirTexture )
  306. {
  307. pContextData->m_SemiStaticCmdsOut.BindTexture( pShader, SHADER_SAMPLER8, TEXTURE_BINDFLAGS_NONE, info.m_nAnisoDirTexture, -1 );
  308. }
  309. //pContextData->m_SemiStaticCmdsOut.SetPixelShaderTextureTransform( 10, info.m_nBaseTextureTransform );
  310. pContextData->m_SemiStaticCmdsOut.BindStandardTexture( SHADER_SAMPLER5, TEXTURE_BINDFLAGS_NONE, TEXTURE_NORMALIZATION_CUBEMAP_SIGNED );
  311. // PS Constants
  312. float flGrungeScale = params[info.m_nGrungeScale]->GetFloatValue();
  313. //remap wear midpoint along a simple bezier parabola
  314. //y = 2(1-x) x MID + x^2
  315. float flX = params[info.m_nWearProgress]->GetFloatValue();
  316. float flP = params[info.m_nWearRemapMid]->GetFloatValue();
  317. float flRemappedWear = 2.0f * ( 1.0f - flX ) * flX * flP + ( flX * flX );
  318. //remap wear to custom min/max bounds
  319. flRemappedWear *= ( params[info.m_nWearRemapMax]->GetFloatValue() - params[info.m_nWearRemapMin]->GetFloatValue() );
  320. flRemappedWear += params[info.m_nWearRemapMin]->GetFloatValue();
  321. //we already shipped wear progress levels, this is an additional param that individual stickers
  322. //can drive to bias their wear AGAIN as they move away from 0
  323. flRemappedWear += flX * flX * params[info.m_nWearBias]->GetFloatValue();
  324. //lerp wear width along wear progress
  325. float flLerpedWearWidth = Lerp( params[info.m_nWearProgress]->GetFloatValue(), params[info.m_nWearWidthMin]->GetFloatValue(), params[info.m_nWearWidthMax]->GetFloatValue() );
  326. float fvConst0[4] = { params[info.m_nWearProgress]->GetFloatValue(),
  327. flLerpedWearWidth,
  328. flRemappedWear,
  329. params[info.m_nUnWearStrength]->GetFloatValue() };
  330. pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 0, fvConst0, 1 );
  331. float fvConst1[4] = { params[info.m_nPhongExponent]->GetFloatValue(),
  332. params[info.m_nPhongBoost]->GetFloatValue(),
  333. params[info.m_nPhongAlbedoBoost]->GetFloatValue(),
  334. //1.0f - params[info.m_nFastWearThreshold]->GetFloatValue() };
  335. flGrungeScale };
  336. pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 1, fvConst1, 1 );
  337. float fvConst2[4] = { params[info.m_nPhongFresnelRanges]->GetVecValue()[0],
  338. params[info.m_nPhongFresnelRanges]->GetVecValue()[1],
  339. params[info.m_nPhongFresnelRanges]->GetVecValue()[2],
  340. params[info.m_nPhongAlbedoTint]->GetFloatValue() };
  341. pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 2, fvConst2, 1 );
  342. float fvConst3[4] = { params[info.m_nEnvmapTint]->GetVecValue()[0],
  343. params[info.m_nEnvmapTint]->GetVecValue()[1],
  344. params[info.m_nEnvmapTint]->GetVecValue()[2],
  345. SrgbGammaToLinear( params[info.m_nColorTint3]->GetVecValue()[0] / 255.0 ) };
  346. pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 3, fvConst3, 1 );
  347. float fvConst10[4] = { SrgbGammaToLinear( params[info.m_nColorTint]->GetVecValue()[0] / 255.0 ),
  348. SrgbGammaToLinear( params[info.m_nColorTint]->GetVecValue()[1] / 255.0 ),
  349. SrgbGammaToLinear( params[info.m_nColorTint]->GetVecValue()[2] / 255.0 ),
  350. SrgbGammaToLinear( params[info.m_nColorTint3]->GetVecValue()[1] / 255.0 ) };
  351. pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 10, fvConst10, 1 );
  352. float fvConst11[4] = { SrgbGammaToLinear( params[info.m_nColorTint2]->GetVecValue()[0] / 255.0 ),
  353. SrgbGammaToLinear( params[info.m_nColorTint2]->GetVecValue()[1] / 255.0 ),
  354. SrgbGammaToLinear( params[info.m_nColorTint2]->GetVecValue()[2] / 255.0 ),
  355. SrgbGammaToLinear( params[info.m_nColorTint3]->GetVecValue()[2] / 255.0 ) };
  356. pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 11, fvConst11, 1 );
  357. float fvConst13[4] = { SrgbGammaToLinear( params[info.m_nColorTint4]->GetVecValue()[0] / 255.0 ),
  358. SrgbGammaToLinear( params[info.m_nColorTint4]->GetVecValue()[1] / 255.0 ),
  359. SrgbGammaToLinear( params[info.m_nColorTint4]->GetVecValue()[2] / 255.0 ),
  360. params[info.m_nDesatBaseTint]->GetFloatValue() };
  361. pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant( 13, fvConst13, 1 );
  362. if ( bHighlight )
  363. {
  364. float fvConst14[4] = { params[info.m_nHighlight]->GetFloatValue(),
  365. params[info.m_nHighlightCycle]->GetFloatValue(),
  366. 0.0f, 0.0f };
  367. pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant(14, fvConst14, 1);
  368. }
  369. else if ( bPeel )
  370. {
  371. float fvConst14[4] = { params[info.m_nPeel]->GetFloatValue(),
  372. params[info.m_nHighlightCycle]->GetFloatValue(),
  373. 0.0f, 0.0f };
  374. pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant(14, fvConst14, 1);
  375. }
  376. pContextData->m_SemiStaticCmdsOut.End();
  377. }
  378. }
  379. if ( pShaderAPI ) //DYNAMIC_STATE
  380. {
  381. if ( IsPC() && pShaderAPI->InFlashlightMode() )
  382. {
  383. // Don't draw anything for the flashlight pass
  384. pShader->Draw( false );
  385. return;
  386. }
  387. #ifdef _PS3
  388. CCommandBufferBuilder< CDynamicCommandStorageBuffer > DynamicCmdsOut;
  389. ShaderApiFast( pShaderAPI )->ExecuteCommandBuffer( pContextData->m_SemiStaticCmdsOut.Base() );
  390. #else
  391. CCommandBufferBuilder< CFixedCommandStorageBuffer< 600 > > DynamicCmdsOut;
  392. DynamicCmdsOut.Call( pContextData->m_SemiStaticCmdsOut.Base() );
  393. #endif
  394. ///////////////////////////
  395. // dynamic block
  396. ///////////////////////////
  397. int numBones = ShaderApiFast( pShaderAPI )->GetCurrentNumBones();
  398. LightState_t lightState = { 0, false, false };
  399. ShaderApiFast( pShaderAPI )->GetDX9LightState( &lightState );
  400. // VERTEX SHADER SETUP
  401. if ( g_pHardwareConfig->SupportsPixelShaders_3_0() )
  402. {
  403. DECLARE_DYNAMIC_VERTEX_SHADER( weapondecal_vs30 );
  404. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, ( numBones > 0 ) );
  405. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  406. SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, IsPlatformOSX() ? Min( 2, lightState.m_nNumLights ) : lightState.m_nNumLights );
  407. SET_DYNAMIC_VERTEX_SHADER( weapondecal_vs30 );
  408. }
  409. else
  410. {
  411. DECLARE_DYNAMIC_VERTEX_SHADER( weapondecal_vs20 );
  412. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, ( numBones > 0 ) );
  413. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  414. SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, IsPlatformOSX() ? Min( 2, lightState.m_nNumLights ) : lightState.m_nNumLights );
  415. SET_DYNAMIC_VERTEX_SHADER( weapondecal_vs20 );
  416. }
  417. // VS constants
  418. bool bCSMEnabled;
  419. bCSMEnabled = pShaderAPI->IsCascadedShadowMapping() && !bSFM;
  420. if ( bCSMEnabled )
  421. {
  422. ITexture *pDepthTextureAtlas = NULL;
  423. const CascadedShadowMappingState_t &cascadeState = pShaderAPI->GetCascadedShadowMappingState( &pDepthTextureAtlas );
  424. if ( pDepthTextureAtlas )
  425. {
  426. DynamicCmdsOut.BindTexture( pShader, SHADER_SAMPLER15, TEXTURE_BINDFLAGS_SHADOWDEPTH, pDepthTextureAtlas, 0 );
  427. DynamicCmdsOut.SetPixelShaderConstant( 64, &cascadeState.m_vLightColor.x, CASCADED_SHADOW_MAPPING_CONSTANT_BUFFER_SIZE );
  428. }
  429. }
  430. // PIXEL SHADER SETUP
  431. if ( g_pHardwareConfig->SupportsPixelShaders_3_0() )
  432. {
  433. DECLARE_DYNAMIC_PIXEL_SHADER( weapondecal_ps30 );
  434. SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, IsPlatformOSX() ? Min( 2, lightState.m_nNumLights ) : lightState.m_nNumLights );
  435. SET_DYNAMIC_PIXEL_SHADER_COMBO( DYN_CSM_ENABLED, ( IsPlatformOSX() ? 0 : ( bCSMEnabled ? 1 : 0 ) ) );
  436. SET_DYNAMIC_PIXEL_SHADER_COMBO( HIGHLIGHT, bHighlight ? 2 : 0 );
  437. SET_DYNAMIC_PIXEL_SHADER_COMBO( PEEL, bPeel ? 1 : 0 );
  438. SET_DYNAMIC_PIXEL_SHADER( weapondecal_ps30 );
  439. }
  440. else
  441. {
  442. DECLARE_DYNAMIC_PIXEL_SHADER( weapondecal_ps20b );
  443. SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, IsPlatformOSX() ? Min( 2, lightState.m_nNumLights ) : lightState.m_nNumLights );
  444. SET_DYNAMIC_PIXEL_SHADER_COMBO( DYN_CSM_ENABLED, ( IsPlatformOSX() ? 0 : ( bCSMEnabled ? 1 : 0 ) ) );
  445. SET_DYNAMIC_PIXEL_SHADER_COMBO( HIGHLIGHT, bHighlight ? 1 : 0 );
  446. SET_DYNAMIC_PIXEL_SHADER_COMBO( PEEL, bPeel ? 1 : 0 );
  447. SET_DYNAMIC_PIXEL_SHADER( weapondecal_ps20b );
  448. }
  449. float vEyePos[4] = { 0, 0, 0, 0 };
  450. ShaderApiFast( pShaderAPI )->GetWorldSpaceCameraPosition( vEyePos );
  451. DynamicCmdsOut.SetPixelShaderConstant( 12, vEyePos, 1 );
  452. if ( bEnvmapTexture )
  453. {
  454. bool bHdr = ( g_pHardwareConfig->GetHDRType() != HDR_TYPE_NONE );
  455. DynamicCmdsOut.BindEnvCubemapTexture( pShader, SHADER_SAMPLER3, bHdr ? TEXTURE_BINDFLAGS_NONE : TEXTURE_BINDFLAGS_SRGBREAD, info.m_nEnvmapTexture, 0 /*info.m_nEnvmapFrame*/ );
  456. }
  457. DynamicCmdsOut.End();
  458. // end dynamic block
  459. pShaderAPI->ExecuteCommandBuffer( DynamicCmdsOut.Base() );
  460. }
  461. pShader->Draw();
  462. }