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.

406 lines
18 KiB

  1. //========= Copyright � 1996-2007, Valve Corporation, All rights reserved. ============//
  2. #include "BaseVSShader.h"
  3. #include "paintblob_helper.h"
  4. #include "cpp_shader_constant_register_map.h"
  5. /*
  6. #include "mathlib/vmatrix.h"
  7. #include "convar.h"
  8. */
  9. // Auto generated inc files
  10. #include "paintblob_vs20.inc"
  11. #include "paintblob_ps20b.inc"
  12. void InitParamsPaintBlob( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, PaintBlobVars_t &info )
  13. {
  14. // Set material parameter default values
  15. SET_PARAM_INT_IF_NOT_DEFINED( info.m_nBackSurface, kDefaultBackSurface );
  16. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nUVScale, kDefaultUVScale );
  17. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nBumpStrength, kDefaultBumpStrength );
  18. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nFresnelBumpStrength, kDefaultFresnelBumpStrength );
  19. SET_PARAM_INT_IF_NOT_DEFINED( info.m_nInteriorEnable, kDefaultInteriorEnable );
  20. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nInteriorFogStrength, kDefaultInteriorFogStrength );
  21. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nInteriorBackgroundBoost, kDefaultInteriorBackgroundBoost );
  22. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nInteriorAmbientScale, kDefaultInteriorAmbientScale );
  23. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nInteriorBackLightScale, kDefaultInteriorBackLightScale );
  24. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nInteriorRefractStrength, kDefaultInteriorRefractStrength );
  25. SET_PARAM_VEC_IF_NOT_DEFINED( info.m_nFresnelParams, kDefaultFresnelParams, 3 );
  26. SET_PARAM_VEC_IF_NOT_DEFINED( info.m_nBaseColorTint, kDefaultBaseColorTint, 3 );
  27. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nDiffuseScale, kDefaultDiffuseScale );
  28. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nSpecExp, kDefaultSpecExp );
  29. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nSpecScale, kDefaultSpecScale );
  30. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nSpecExp2, kDefaultSpecExp );
  31. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nSpecScale2, kDefaultSpecScale );
  32. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nRimLightExp, kDefaultRimLightExp );
  33. SET_PARAM_FLOAT_IF_NOT_DEFINED( info.m_nRimLightScale, kDefaultRimLightScale );
  34. SET_PARAM_VEC_IF_NOT_DEFINED( info.m_nUVProjOffset, kDefaultUVProjOffset, 3 );
  35. SET_PARAM_VEC_IF_NOT_DEFINED( info.m_nBBMin, kDefaultBB, 3 );
  36. SET_PARAM_VEC_IF_NOT_DEFINED( info.m_nBBMax, kDefaultBB, 3 );
  37. // FLASHLIGHTFIXME: Do ShaderAPI::BindFlashlightTexture
  38. Assert( info.m_nFlashlightTexture >= 0 );
  39. if ( g_pHardwareConfig->SupportsBorderColor() )
  40. {
  41. params[info.m_nFlashlightTexture]->SetStringValue( "effects/flashlight_border" );
  42. }
  43. else
  44. {
  45. params[info.m_nFlashlightTexture]->SetStringValue( "effects/flashlight001" );
  46. }
  47. SET_PARAM_INT_IF_NOT_DEFINED( info.m_nFlashlightTextureFrame, 0 );
  48. SET_PARAM_INT_IF_NOT_DEFINED( info.m_nBumpFrame, kDefaultBumpFrame )
  49. SET_PARAM_INT_IF_NOT_DEFINED( info.m_nContactShadows, kDefaultContactShadows );
  50. // Set material flags
  51. SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
  52. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT );
  53. if ( params[info.m_nInteriorEnable]->IsDefined() && params[info.m_nInteriorEnable]->GetIntValue() != 0 )
  54. {
  55. SET_FLAGS2( MATERIAL_VAR2_NEEDS_FULL_FRAME_BUFFER_TEXTURE );
  56. }
  57. }
  58. void InitPaintBlob( CBaseVSShader *pShader, IMaterialVar** params, PaintBlobVars_t &info )
  59. {
  60. // Load textures
  61. if ( (info.m_nBaseTexture != -1) && params[info.m_nBaseTexture]->IsDefined() )
  62. {
  63. pShader->LoadTexture( info.m_nBaseTexture, TEXTUREFLAGS_SRGB );
  64. }
  65. if ( (info.m_nNormalMap != -1) && params[info.m_nNormalMap]->IsDefined() )
  66. {
  67. pShader->LoadTexture( info.m_nNormalMap );
  68. }
  69. if ( (info.m_nSpecMap != -1) && params[info.m_nSpecMap]->IsDefined() )
  70. {
  71. pShader->LoadTexture( info.m_nSpecMap );
  72. }
  73. if ( (info.m_nLightWarpTexture != -1) && params[info.m_nLightWarpTexture]->IsDefined() )
  74. {
  75. pShader->LoadTexture( info.m_nLightWarpTexture, TEXTUREFLAGS_SRGB );
  76. }
  77. if ( (info.m_nFresnelWarpTexture != -1) && params[info.m_nFresnelWarpTexture]->IsDefined() )
  78. {
  79. pShader->LoadTexture( info.m_nFresnelWarpTexture );
  80. }
  81. if ( (info.m_nOpacityTexture != -1) && params[info.m_nOpacityTexture]->IsDefined() )
  82. {
  83. pShader->LoadTexture( info.m_nOpacityTexture );
  84. }
  85. if ( (info.m_nEnvMap != -1) && params[info.m_nEnvMap]->IsDefined() )
  86. {
  87. pShader->LoadCubeMap( info.m_nEnvMap, TEXTUREFLAGS_SRGB );
  88. }
  89. if ( (info.m_nFlashlightTexture != -1) && params[info.m_nFlashlightTexture]->IsDefined() )
  90. {
  91. pShader->LoadTexture( info.m_nFlashlightTexture, TEXTUREFLAGS_SRGB );
  92. }
  93. }
  94. void DrawPaintBlob( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI,
  95. IShaderShadow* pShaderShadow, PaintBlobVars_t &info, VertexCompressionType_t vertexCompression )
  96. {
  97. bool bHasFlashlight = pShader->UsingFlashlight( params );
  98. bool bBackSurface = (info.m_nBackSurface != -1) && ( params[info.m_nBackSurface]->GetIntValue() > 0 );
  99. bool bLightWarp = (info.m_nLightWarpTexture != -1) && params[info.m_nLightWarpTexture]->IsDefined();
  100. bool bFresnelWarp = (info.m_nFresnelWarpTexture != -1) && params[info.m_nFresnelWarpTexture]->IsDefined();
  101. bool bOpacityTexture = (info.m_nOpacityTexture != -1) && params[info.m_nOpacityTexture]->IsDefined();
  102. bool bInteriorLayer = (info.m_nInteriorEnable != -1) && ( params[info.m_nInteriorEnable]->GetIntValue() > 0 );
  103. bool bContactShadows = (info.m_nContactShadows != -1) && ( params[info.m_nContactShadows]->GetIntValue() > 0 );
  104. bool bSpecMap = (info.m_nSpecMap != -1) && params[info.m_nSpecMap]->IsDefined();
  105. bool bEnvMap = (info.m_nEnvMap != -1) && params[info.m_nEnvMap]->IsDefined();
  106. bool bFlattenStaticControlFlow = !g_pHardwareConfig->SupportsStaticControlFlow();
  107. SHADOW_STATE
  108. {
  109. // Set stream format (note that this shader supports compression)
  110. unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL;
  111. int nTexCoordCount = 1;
  112. int userDataSize = 0;
  113. int texCoordDims[4] = { 4, 4, 4, 4 };
  114. pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, texCoordDims, userDataSize );
  115. ShadowFilterMode_t nShadowFilterMode = SHADOWFILTERMODE_DEFAULT;
  116. if ( bHasFlashlight )
  117. {
  118. nShadowFilterMode = g_pHardwareConfig->GetShadowFilterMode( false /* bForceLowQuality */ , true /* bPS30 */ ); // Based upon vendor and device dependent formats
  119. }
  120. // Vertex Shader
  121. DECLARE_STATIC_VERTEX_SHADER( paintblob_vs20 );
  122. SET_STATIC_VERTEX_SHADER_COMBO( FLATTEN_STATIC_CONTROL_FLOW, bFlattenStaticControlFlow );
  123. SET_STATIC_VERTEX_SHADER( paintblob_vs20 );
  124. // Pixel Shader
  125. if( /* g_pHardwareConfig->SupportsPixelShaders_3_0() */ true )
  126. {
  127. DECLARE_STATIC_PIXEL_SHADER( paintblob_ps20b );
  128. SET_STATIC_PIXEL_SHADER_COMBO( BACK_SURFACE, bBackSurface );
  129. SET_STATIC_PIXEL_SHADER_COMBO( LIGHT_WARP, bLightWarp );
  130. SET_STATIC_PIXEL_SHADER_COMBO( FRESNEL_WARP, bFresnelWarp );
  131. SET_STATIC_PIXEL_SHADER_COMBO( OPACITY_TEXTURE, bOpacityTexture );
  132. SET_STATIC_PIXEL_SHADER_COMBO( INTERIOR_LAYER, bInteriorLayer );
  133. SET_STATIC_PIXEL_SHADER_COMBO( HIGH_PRECISION_DEPTH, (g_pHardwareConfig->GetHDRType() == HDR_TYPE_FLOAT) ? true : false );
  134. SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode );
  135. SET_STATIC_PIXEL_SHADER_COMBO( CONTACT_SHADOW, bContactShadows ); // only do contact shadows on outer shell (which has interior layer enabled)
  136. SET_STATIC_PIXEL_SHADER( paintblob_ps20b );
  137. }
  138. else
  139. {
  140. Assert( !"No ps_3_0" );
  141. }
  142. // Textures
  143. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); //[sRGB] Base
  144. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true );
  145. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); // Bump
  146. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, false );
  147. pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); //[sRGB] Backbuffer
  148. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, true );
  149. pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); // Spec mask
  150. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, false );
  151. pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); //[sRGB] Light warp
  152. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER4, true );
  153. pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); // Fresnel warp // TODO: Could be in alpha of lightwarp
  154. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER5, false );
  155. pShaderShadow->EnableTexture( SHADER_SAMPLER6, true ); // Opacity
  156. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER6, false );
  157. pShaderShadow->EnableTexture( SHADER_SAMPLER7, true ); //[sRGB] Envmap
  158. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER7, true );
  159. if( bHasFlashlight )
  160. {
  161. pShaderShadow->EnableTexture( SHADER_SAMPLER8, true ); // Shadow depth map
  162. //pShaderShadow->SetShadowDepthFiltering( SHADER_SAMPLER8 );
  163. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER8, false );
  164. pShaderShadow->EnableTexture( SHADER_SAMPLER9, true ); // Noise map
  165. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER9, false );
  166. pShaderShadow->EnableTexture( SHADER_SAMPLER10, true ); //[sRGB] Flashlight cookie
  167. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER10, true );
  168. }
  169. pShaderShadow->EnableSRGBWrite( true );
  170. pShaderShadow->EnableAlphaWrites( true );
  171. // Per-instance state
  172. pShader->PI_BeginCommandBuffer();
  173. pShader->PI_SetVertexShaderAmbientLightCube();
  174. pShader->PI_SetPixelShaderAmbientLightCube( PSREG_AMBIENT_CUBE );
  175. pShader->PI_SetPixelShaderLocalLighting( PSREG_LIGHT_INFO_ARRAY );
  176. pShader->PI_EndCommandBuffer();
  177. }
  178. DYNAMIC_STATE
  179. {
  180. ///////////////////////
  181. // VERTEX SHADER SETUP
  182. ///////////////////////
  183. LightState_t lightState = { 0, false, false };
  184. pShaderAPI->GetDX9LightState( &lightState );
  185. // Set Vertex Shader Combos
  186. DECLARE_DYNAMIC_VERTEX_SHADER( paintblob_vs20 );
  187. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
  188. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  189. SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, bFlattenStaticControlFlow ? lightState.m_nNumLights : 0 );
  190. SET_DYNAMIC_VERTEX_SHADER( paintblob_vs20 );
  191. // VS constants
  192. float flConsts[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  193. flConsts[0] = IS_PARAM_DEFINED( info.m_nUVScale ) ? params[info.m_nUVScale]->GetFloatValue() : kDefaultUVScale;
  194. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, flConsts );
  195. if ( IS_PARAM_DEFINED( info.m_nUVProjOffset ) )
  196. params[info.m_nUVProjOffset]->GetVecValue( flConsts, 3 );
  197. else
  198. memcpy( flConsts, kDefaultUVProjOffset, sizeof( kDefaultUVProjOffset ) );
  199. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, flConsts );
  200. if ( IS_PARAM_DEFINED( info.m_nBBMin ) )
  201. params[info.m_nBBMin]->GetVecValue( flConsts, 3 );
  202. else
  203. memcpy( flConsts, kDefaultBB, sizeof( kDefaultBB ) );
  204. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, flConsts );
  205. if ( IS_PARAM_DEFINED( info.m_nBBMax ) )
  206. params[info.m_nBBMax]->GetVecValue( flConsts, 3 );
  207. else
  208. memcpy( flConsts, kDefaultBB, sizeof( kDefaultBB ) );
  209. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, flConsts );
  210. //////////////////////
  211. // PIXEL SHADER SETUP
  212. //////////////////////
  213. // Bind textures
  214. pShader->BindTexture( SHADER_SAMPLER0, TEXTURE_BINDFLAGS_SRGBREAD, BASETEXTURE );
  215. pShader->BindTexture( SHADER_SAMPLER1, TEXTURE_BINDFLAGS_NONE, info.m_nNormalMap, info.m_nBumpFrame );
  216. pShaderAPI->BindStandardTexture( SHADER_SAMPLER2, TEXTURE_BINDFLAGS_SRGBREAD, TEXTURE_FRAME_BUFFER_FULL_TEXTURE_0 ); // Refraction Map
  217. if ( bSpecMap )
  218. {
  219. pShader->BindTexture( SHADER_SAMPLER3, TEXTURE_BINDFLAGS_NONE, info.m_nSpecMap );
  220. }
  221. else
  222. {
  223. pShaderAPI->BindStandardTexture( SHADER_SAMPLER3, TEXTURE_BINDFLAGS_NONE, TEXTURE_WHITE );
  224. }
  225. if ( bLightWarp )
  226. {
  227. pShader->BindTexture( SHADER_SAMPLER4, TEXTURE_BINDFLAGS_SRGBREAD, info.m_nLightWarpTexture );
  228. }
  229. if ( bFresnelWarp )
  230. {
  231. pShader->BindTexture( SHADER_SAMPLER5, TEXTURE_BINDFLAGS_NONE, info.m_nFresnelWarpTexture );
  232. }
  233. if ( bOpacityTexture )
  234. {
  235. pShader->BindTexture( SHADER_SAMPLER6, TEXTURE_BINDFLAGS_NONE, info.m_nOpacityTexture );
  236. }
  237. if ( bEnvMap )
  238. {
  239. pShader->BindTexture( SHADER_SAMPLER7, TEXTURE_BINDFLAGS_NONE, info.m_nEnvMap );
  240. }
  241. else
  242. {
  243. pShaderAPI->BindStandardTexture( SHADER_SAMPLER7, TEXTURE_BINDFLAGS_NONE, TEXTURE_BLACK );
  244. }
  245. // flashlightfixme: put this in common code.
  246. bool bFlashlightShadows = false;
  247. if( bHasFlashlight )
  248. {
  249. Assert( info.m_nFlashlightTexture >= 0 && info.m_nFlashlightTextureFrame >= 0 );
  250. pShader->BindTexture( SHADER_SAMPLER10, TEXTURE_BINDFLAGS_SRGBREAD, info.m_nFlashlightTexture, info.m_nFlashlightTextureFrame );
  251. VMatrix worldToTexture;
  252. ITexture *pFlashlightDepthTexture;
  253. FlashlightState_t state = pShaderAPI->GetFlashlightStateEx( worldToTexture, &pFlashlightDepthTexture );
  254. bFlashlightShadows = state.m_bEnableShadows;
  255. SetFlashLightColorFromState( state, pShaderAPI, PSREG_FLASHLIGHT_COLOR );
  256. if( pFlashlightDepthTexture && g_pConfig->ShadowDepthTexture() && state.m_bEnableShadows )
  257. {
  258. pShader->BindTexture( SHADER_SAMPLER8, TEXTURE_BINDFLAGS_SHADOWDEPTH, pFlashlightDepthTexture );
  259. pShaderAPI->BindStandardTexture( SHADER_SAMPLER9, TEXTURE_BINDFLAGS_NONE, TEXTURE_SHADOW_NOISE_2D );
  260. }
  261. float atten[4], pos[4], tweaks[4];
  262. atten[0] = state.m_fConstantAtten; // Set the flashlight attenuation factors
  263. atten[1] = state.m_fLinearAtten;
  264. atten[2] = state.m_fQuadraticAtten;
  265. atten[3] = state.m_FarZAtten;
  266. pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_ATTENUATION, atten, 1 );
  267. pos[0] = state.m_vecLightOrigin[0]; // Set the flashlight origin
  268. pos[1] = state.m_vecLightOrigin[1];
  269. pos[2] = state.m_vecLightOrigin[2];
  270. pos[3] = state.m_FarZ;
  271. pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_POSITION_RIM_BOOST, pos, 1 ); // steps on rim boost
  272. pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_TO_WORLD_TEXTURE, worldToTexture.Base(), 4 );
  273. // Tweaks associated with a given flashlight
  274. tweaks[0] = ShadowFilterFromState( state );
  275. tweaks[1] = ShadowAttenFromState( state );
  276. pShader->HashShadow2DJitter( state.m_flShadowJitterSeed, &tweaks[2], &tweaks[3] );
  277. pShaderAPI->SetPixelShaderConstant( PSREG_ENVMAP_TINT__SHADOW_TWEAKS, tweaks, 1 );
  278. // Dimensions of screen, used for screen-space noise map sampling
  279. float vScreenScale[4] = {1280.0f / 32.0f, 720.0f / 32.0f, 0, 0};
  280. int nWidth, nHeight;
  281. pShaderAPI->GetBackBufferDimensions( nWidth, nHeight );
  282. int nTexWidth, nTexHeight;
  283. pShaderAPI->GetStandardTextureDimensions( &nTexWidth, &nTexHeight, TEXTURE_SHADOW_NOISE_2D );
  284. vScreenScale[0] = (float) nWidth / nTexWidth;
  285. vScreenScale[1] = (float) nHeight / nTexHeight;
  286. vScreenScale[2] = 1.0f / state.m_flShadowMapResolution;
  287. vScreenScale[3] = 2.0f / state.m_flShadowMapResolution;
  288. pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_SCREEN_SCALE, vScreenScale, 1 );
  289. if ( IsX360() )
  290. {
  291. pShaderAPI->SetBooleanPixelShaderConstant( 0, &state.m_nShadowQuality, 1 );
  292. }
  293. }
  294. flConsts[0] = IS_PARAM_DEFINED( info.m_nBumpStrength ) ? params[info.m_nBumpStrength]->GetFloatValue() : kDefaultBumpStrength;
  295. flConsts[1] = (g_pHardwareConfig->GetHDRType() == HDR_TYPE_FLOAT) ? 8192.0f : 192.0f; // destalpha dest scale factor. TODO: put this in its own const and call shaderAPI method to set
  296. flConsts[2] = IS_PARAM_DEFINED( info.m_nInteriorFogStrength ) ? params[info.m_nInteriorFogStrength]->GetFloatValue() : kDefaultInteriorFogStrength;
  297. flConsts[3] = IS_PARAM_DEFINED( info.m_nInteriorRefractStrength ) ? params[info.m_nInteriorRefractStrength]->GetFloatValue() : kDefaultInteriorRefractStrength;
  298. pShaderAPI->SetPixelShaderConstant( 0, flConsts, 1 );
  299. Assert( IS_PARAM_DEFINED( info.m_nFresnelParams ) );
  300. if ( IS_PARAM_DEFINED( info.m_nFresnelParams ) )
  301. params[info.m_nFresnelParams]->GetVecValue( flConsts, 3 );
  302. else
  303. memcpy( flConsts, kDefaultFresnelParams, sizeof( kDefaultFresnelParams ) );
  304. flConsts[3] = params[info.m_nInteriorBackgroundBoost]->GetFloatValue();
  305. pShaderAPI->SetPixelShaderConstant( 1, flConsts, 1 );
  306. flConsts[0] = IS_PARAM_DEFINED( info.m_nRimLightExp ) ? params[info.m_nRimLightExp]->GetFloatValue() : kDefaultRimLightExp;
  307. flConsts[1] = IS_PARAM_DEFINED( info.m_nRimLightScale ) ? params[info.m_nRimLightScale]->GetFloatValue() : kDefaultRimLightScale;
  308. flConsts[2] = IS_PARAM_DEFINED( info.m_nSpecScale ) ? params[info.m_nSpecScale]->GetFloatValue() : kDefaultSpecScale;
  309. flConsts[3] = IS_PARAM_DEFINED( info.m_nSpecExp2 ) ? params[info.m_nSpecExp2]->GetFloatValue() : kDefaultSpecExp;
  310. pShaderAPI->SetPixelShaderConstant( 3, flConsts, 1 );
  311. flConsts[0] = IS_PARAM_DEFINED( info.m_nSpecScale2 ) ? params[info.m_nSpecScale2]->GetFloatValue() : kDefaultSpecScale;
  312. flConsts[1] = IS_PARAM_DEFINED( info.m_nFresnelBumpStrength ) ? params[info.m_nFresnelBumpStrength]->GetFloatValue() : kDefaultFresnelBumpStrength;
  313. flConsts[2] = IS_PARAM_DEFINED( info.m_nDiffuseScale ) ? params[info.m_nDiffuseScale]->GetFloatValue() : kDefaultDiffuseScale;
  314. flConsts[3] = IS_PARAM_DEFINED( info.m_nInteriorAmbientScale ) ? params[info.m_nInteriorAmbientScale]->GetFloatValue() : kDefaultInteriorAmbientScale;
  315. pShaderAPI->SetPixelShaderConstant( 10, flConsts, 1 );
  316. pShaderAPI->GetWorldSpaceCameraPosition( flConsts );
  317. flConsts[3] = IS_PARAM_DEFINED( info.m_nSpecExp ) ? params[info.m_nSpecExp]->GetFloatValue() : kDefaultSpecExp;
  318. pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, flConsts, 1 );
  319. // Depth alpha [ TODO: support fog ]
  320. bool bWriteDepthToAlpha = pShaderAPI->ShouldWriteDepthToDestAlpha();
  321. flConsts[0] = bWriteDepthToAlpha ? 1.0f : 0.0f;
  322. pShaderAPI->SetPixelShaderConstant( PSREG_FOG_PARAMS, flConsts, 1 );
  323. if ( IS_PARAM_DEFINED( info.m_nBaseColorTint ) )
  324. params[info.m_nBaseColorTint]->GetVecValue( flConsts, 3 );
  325. else
  326. memcpy( flConsts, kDefaultBaseColorTint, sizeof( kDefaultBaseColorTint ) );
  327. flConsts[3] = IS_PARAM_DEFINED( info.m_nInteriorBackLightScale ) ? params[info.m_nInteriorBackLightScale]->GetFloatValue() : kDefaultInteriorBackLightScale;
  328. pShaderAPI->SetPixelShaderConstant( 19, flConsts, 1 );
  329. // Set Pixel Shader Combos
  330. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  331. {
  332. DECLARE_DYNAMIC_PIXEL_SHADER( paintblob_ps20b );
  333. SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights );
  334. SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHT, bHasFlashlight );
  335. SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows );
  336. SET_DYNAMIC_PIXEL_SHADER( paintblob_ps20b );
  337. }
  338. }
  339. pShader->Draw();
  340. }