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.

430 lines
19 KiB

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