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.

468 lines
18 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "BaseVSShader.h"
  7. #include "tier1/convar.h"
  8. #include "mathlib/vmatrix.h"
  9. #include "eyes_dx8_dx9_helper.h"
  10. #include "cpp_shader_constant_register_map.h"
  11. #include "eyes_vs20.inc"
  12. #include "eyes_ps20.inc"
  13. #include "eyes_ps20b.inc"
  14. #include "eyes_flashlight_vs20.inc"
  15. #include "eyes_flashlight_ps20.inc"
  16. #include "eyes_flashlight_ps20b.inc"
  17. #if !defined( _X360 ) && !defined( _PS3 )
  18. #include "eyes_vs30.inc"
  19. #include "eyes_ps30.inc"
  20. #include "eyes_flashlight_vs30.inc"
  21. #include "eyes_flashlight_ps30.inc"
  22. #endif
  23. // NOTE: This has to be the last file included!
  24. #include "tier0/memdbgon.h"
  25. void InitParamsEyes_DX8_DX9( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName,
  26. Eyes_DX8_DX9_Vars_t &info )
  27. {
  28. params[FLASHLIGHTTEXTURE]->SetStringValue( GetFlashlightTextureFilename() );
  29. SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
  30. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT );
  31. }
  32. void InitEyes_DX8_DX9( CBaseVSShader *pShader, IMaterialVar** params, Eyes_DX8_DX9_Vars_t &info )
  33. {
  34. pShader->LoadTexture( FLASHLIGHTTEXTURE, TEXTUREFLAGS_SRGB );
  35. pShader->LoadTexture( info.m_nBaseTexture, TEXTUREFLAGS_SRGB );
  36. pShader->LoadTexture( info.m_nIris, TEXTUREFLAGS_SRGB );
  37. pShader->LoadTexture( info.m_nGlint );
  38. // Be sure dilation is zeroed if undefined
  39. if( !params[info.m_nDilation]->IsDefined() )
  40. {
  41. params[info.m_nDilation]->SetFloatValue( 0.0f );
  42. }
  43. }
  44. static void SetDepthFlashlightParams( CBaseVSShader *pShader, IShaderDynamicAPI *pShaderAPI, const VMatrix& worldToTexture, const FlashlightState_t& flashlightState )
  45. {
  46. float atten[4], pos[4], tweaks[4];
  47. atten[0] = flashlightState.m_fConstantAtten; // Set the flashlight attenuation factors
  48. atten[1] = flashlightState.m_fLinearAtten;
  49. atten[2] = flashlightState.m_fQuadraticAtten;
  50. atten[3] = flashlightState.m_FarZAtten;
  51. pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_ATTENUATION, atten, 1 );
  52. pos[0] = flashlightState.m_vecLightOrigin[0]; // Set the flashlight origin
  53. pos[1] = flashlightState.m_vecLightOrigin[1];
  54. pos[2] = flashlightState.m_vecLightOrigin[2];
  55. pos[3] = flashlightState.m_FarZ;
  56. pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_POSITION_RIM_BOOST, pos, 1 );
  57. pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_TO_WORLD_TEXTURE, worldToTexture.Base(), 4 );
  58. // Tweaks associated with a given flashlight
  59. tweaks[0] = ShadowFilterFromState( flashlightState );
  60. tweaks[1] = ShadowAttenFromState( flashlightState );
  61. pShader->HashShadow2DJitter( flashlightState.m_flShadowJitterSeed, &tweaks[2], &tweaks[3] );
  62. pShaderAPI->SetPixelShaderConstant( PSREG_ENVMAP_TINT__SHADOW_TWEAKS, tweaks, 1 );
  63. // Dimensions of screen, used for screen-space noise map sampling
  64. float vScreenScale[4] = {1280.0f / 32.0f, 720.0f / 32.0f, 0, 0};
  65. int nWidth, nHeight;
  66. pShaderAPI->GetBackBufferDimensions( nWidth, nHeight );
  67. int nTexWidth, nTexHeight;
  68. pShaderAPI->GetStandardTextureDimensions( &nTexWidth, &nTexHeight, TEXTURE_SHADOW_NOISE_2D );
  69. vScreenScale[0] = (float) nWidth / nTexWidth;
  70. vScreenScale[1] = (float) nHeight / nTexHeight;
  71. vScreenScale[2] = 1.0f / flashlightState.m_flShadowMapResolution;
  72. vScreenScale[3] = 2.0f / flashlightState.m_flShadowMapResolution;
  73. pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_SCREEN_SCALE, vScreenScale, 1 );
  74. if ( IsX360() )
  75. {
  76. pShaderAPI->SetBooleanPixelShaderConstant( 0, &flashlightState.m_nShadowQuality, 1 );
  77. }
  78. }
  79. static void DrawFlashlight( bool bDX9, CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI,
  80. IShaderShadow* pShaderShadow, Eyes_DX8_DX9_Vars_t &info, VertexCompressionType_t vertexCompression )
  81. {
  82. if( pShaderShadow )
  83. {
  84. pShaderShadow->EnableDepthWrites( false );
  85. pShader->EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); // Write over the eyes that were already there
  86. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); // Spot
  87. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); // Base
  88. pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); // Normalizing cubemap
  89. pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); // Iris
  90. // Set stream format (note that this shader supports compression)
  91. int flags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED;
  92. int nTexCoordCount = 1;
  93. int userDataSize = 0;
  94. pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize );
  95. // Be sure not to write to dest alpha
  96. pShaderShadow->EnableAlphaWrites( false );
  97. #ifdef STDSHADER_DX9_DLL_EXPORT
  98. Assert( bDX9 );
  99. ShadowFilterMode_t nShadowFilterMode = g_pHardwareConfig->GetShadowFilterMode( false /* bForceLowQuality */, g_pHardwareConfig->HasFastVertexTextures() && !IsPlatformX360() && !IsPlatformPS3() ); // Based upon vendor and device dependent formats
  100. #if !defined( _X360 ) && !defined( _PS3 )
  101. if ( !g_pHardwareConfig->HasFastVertexTextures() )
  102. #endif
  103. {
  104. DECLARE_STATIC_VERTEX_SHADER( eyes_flashlight_vs20 );
  105. SET_STATIC_VERTEX_SHADER( eyes_flashlight_vs20 );
  106. if ( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  107. {
  108. DECLARE_STATIC_PIXEL_SHADER( eyes_flashlight_ps20b );
  109. SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode );
  110. SET_STATIC_PIXEL_SHADER( eyes_flashlight_ps20b );
  111. }
  112. else
  113. {
  114. DECLARE_STATIC_PIXEL_SHADER( eyes_flashlight_ps20 );
  115. SET_STATIC_PIXEL_SHADER( eyes_flashlight_ps20 );
  116. }
  117. }
  118. #if !defined( _X360 ) && !defined( _PS3 )
  119. else
  120. {
  121. // The vertex shader uses the vertex id stream
  122. SET_FLAGS2( MATERIAL_VAR2_USES_VERTEXID );
  123. DECLARE_STATIC_VERTEX_SHADER( eyes_flashlight_vs30 );
  124. SET_STATIC_VERTEX_SHADER( eyes_flashlight_vs30 );
  125. DECLARE_STATIC_PIXEL_SHADER( eyes_flashlight_ps30 );
  126. SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode );
  127. SET_STATIC_PIXEL_SHADER( eyes_flashlight_ps30 );
  128. }
  129. #endif
  130. // On DX9, get the gamma read and write correct
  131. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); // Spot
  132. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); // Base
  133. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, true ); // Iris
  134. pShaderShadow->EnableSRGBWrite( true );
  135. if ( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  136. {
  137. pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); // Shadow depth map
  138. //pShaderShadow->SetShadowDepthFiltering( SHADER_SAMPLER4 );
  139. pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); // Shadow noise rotation map
  140. }
  141. #endif
  142. pShader->FogToBlack();
  143. }
  144. else
  145. {
  146. VMatrix worldToTexture;
  147. ITexture *pFlashlightDepthTexture;
  148. FlashlightState_t flashlightState = pShaderAPI->GetFlashlightStateEx( worldToTexture, &pFlashlightDepthTexture );
  149. pShader->BindTexture( SHADER_SAMPLER0, TEXTURE_BINDFLAGS_SRGBREAD, flashlightState.m_pSpotlightTexture, flashlightState.m_nSpotlightTextureFrame );
  150. pShader->BindTexture( SHADER_SAMPLER1, TEXTURE_BINDFLAGS_SRGBREAD, info.m_nBaseTexture, info.m_nFrame );
  151. pShaderAPI->BindStandardTexture( SHADER_SAMPLER2, TEXTURE_BINDFLAGS_NONE, TEXTURE_NORMALIZATION_CUBEMAP );
  152. pShader->BindTexture( SHADER_SAMPLER3, TEXTURE_BINDFLAGS_SRGBREAD, info.m_nIris, info.m_nIrisFrame );
  153. #ifdef STDSHADER_DX9_DLL_EXPORT
  154. Assert( bDX9 );
  155. #if !defined( _X360 ) && !defined( _PS3 )
  156. if ( !g_pHardwareConfig->HasFastVertexTextures() )
  157. #endif
  158. {
  159. DECLARE_DYNAMIC_VERTEX_SHADER( eyes_flashlight_vs20 );
  160. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
  161. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  162. SET_DYNAMIC_VERTEX_SHADER( eyes_flashlight_vs20 );
  163. }
  164. #if !defined( _X360 ) && !defined( _PS3 )
  165. else
  166. {
  167. pShader->SetHWMorphVertexShaderState( VERTEX_SHADER_SHADER_SPECIFIC_CONST_10, VERTEX_SHADER_SHADER_SPECIFIC_CONST_11, SHADER_VERTEXTEXTURE_SAMPLER0 );
  168. DECLARE_DYNAMIC_VERTEX_SHADER( eyes_flashlight_vs30 );
  169. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
  170. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  171. SET_DYNAMIC_VERTEX_SHADER( eyes_flashlight_vs30 );
  172. }
  173. #endif
  174. // float vPSConst[4] = {params[info.m_nDilation]->GetFloatValue(), 0.0f, 0.0f, 0.0f};
  175. // pShaderAPI->SetPixelShaderConstant( 0, vPSConst, 1 );
  176. SetFlashLightColorFromState( flashlightState, pShaderAPI, false );
  177. if( pFlashlightDepthTexture && g_pConfig->ShadowDepthTexture() && flashlightState.m_bEnableShadows )
  178. {
  179. pShader->BindTexture( SHADER_SAMPLER4, TEXTURE_BINDFLAGS_SHADOWDEPTH, pFlashlightDepthTexture, 0 );
  180. pShaderAPI->BindStandardTexture( SHADER_SAMPLER5, TEXTURE_BINDFLAGS_NONE, TEXTURE_SHADOW_NOISE_2D );
  181. }
  182. pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS );
  183. float vEyePos_SpecExponent[4];
  184. pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent );
  185. vEyePos_SpecExponent[3] = 0.0f;
  186. pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 );
  187. #if !defined( _X360 ) && !defined( _PS3 )
  188. if ( !g_pHardwareConfig->HasFastVertexTextures() )
  189. #endif
  190. {
  191. if ( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  192. {
  193. DECLARE_DYNAMIC_PIXEL_SHADER( eyes_flashlight_ps20b );
  194. SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, flashlightState.m_bEnableShadows );
  195. SET_DYNAMIC_PIXEL_SHADER( eyes_flashlight_ps20b );
  196. SetDepthFlashlightParams( pShader, pShaderAPI, worldToTexture, flashlightState );
  197. }
  198. else
  199. {
  200. DECLARE_DYNAMIC_PIXEL_SHADER( eyes_flashlight_ps20 );
  201. SET_DYNAMIC_PIXEL_SHADER( eyes_flashlight_ps20 );
  202. }
  203. }
  204. #if !defined( _X360 ) && !defined( _PS3 )
  205. else
  206. {
  207. DECLARE_DYNAMIC_PIXEL_SHADER( eyes_flashlight_ps30 );
  208. SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, flashlightState.m_bEnableShadows );
  209. SET_DYNAMIC_PIXEL_SHADER_COMBO( UBERLIGHT, flashlightState.m_bUberlight );
  210. SET_DYNAMIC_PIXEL_SHADER( eyes_flashlight_ps30 );
  211. SetDepthFlashlightParams( pShader, pShaderAPI, worldToTexture, flashlightState );
  212. SetupUberlightFromState( pShaderAPI, flashlightState );
  213. }
  214. #endif
  215. #endif
  216. // This uses from VERTEX_SHADER_SHADER_SPECIFIC_CONST_0 to VERTEX_SHADER_SHADER_SPECIFIC_CONST_5
  217. pShader->SetFlashlightVertexShaderConstants( false, -1, false, -1, false );
  218. pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, info.m_nEyeOrigin );
  219. pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_7, info.m_nEyeUp );
  220. pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_8, info.m_nIrisU );
  221. pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_9, info.m_nIrisV );
  222. }
  223. pShader->Draw();
  224. }
  225. static void DrawUsingVertexShader( bool bDX9, CBaseVSShader *pShader, IMaterialVar** params,
  226. IShaderDynamicAPI *pShaderAPI, IShaderShadow* pShaderShadow,
  227. Eyes_DX8_DX9_Vars_t &info, VertexCompressionType_t vertexCompression )
  228. {
  229. SHADOW_STATE
  230. {
  231. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); // Base
  232. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); // Iris
  233. pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); // Glint
  234. // Set stream format (note that this shader supports compression)
  235. int flags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED;
  236. int nTexCoordCount = 1;
  237. int userDataSize = 0;
  238. pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize );
  239. pShaderShadow->EnableAlphaWrites( true ); //we end up hijacking destination alpha for opaques most of the time.
  240. bool bSRGBRead01 = false;
  241. #ifdef STDSHADER_DX9_DLL_EXPORT
  242. Assert( bDX9 );
  243. bSRGBRead01 = true;
  244. #if !defined( _X360 ) && !defined( _PS3 )
  245. if ( !g_pHardwareConfig->HasFastVertexTextures() )
  246. #endif
  247. {
  248. bool bFlattenStaticControlFlow = !g_pHardwareConfig->SupportsStaticControlFlow();
  249. DECLARE_STATIC_VERTEX_SHADER( eyes_vs20 );
  250. SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, IS_FLAG_SET( MATERIAL_VAR_HALFLAMBERT ) );
  251. SET_STATIC_VERTEX_SHADER_COMBO( FLATTEN_STATIC_CONTROL_FLOW, bFlattenStaticControlFlow );
  252. SET_STATIC_VERTEX_SHADER( eyes_vs20 );
  253. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  254. {
  255. DECLARE_STATIC_PIXEL_SHADER( eyes_ps20b );
  256. SET_STATIC_PIXEL_SHADER( eyes_ps20b );
  257. }
  258. else
  259. {
  260. DECLARE_STATIC_PIXEL_SHADER( eyes_ps20 );
  261. SET_STATIC_PIXEL_SHADER( eyes_ps20 );
  262. }
  263. }
  264. #if !defined( _X360 ) && !defined( _PS3 )
  265. else
  266. {
  267. // The vertex shader uses the vertex id stream
  268. SET_FLAGS2( MATERIAL_VAR2_USES_VERTEXID );
  269. DECLARE_STATIC_VERTEX_SHADER( eyes_vs30 );
  270. SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, IS_FLAG_SET( MATERIAL_VAR_HALFLAMBERT ) );
  271. SET_STATIC_VERTEX_SHADER( eyes_vs30 );
  272. DECLARE_STATIC_PIXEL_SHADER( eyes_ps30 );
  273. SET_STATIC_PIXEL_SHADER( eyes_ps30 );
  274. }
  275. #endif
  276. // On DX9, get the gamma read and write correct
  277. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER0, true ); // Base
  278. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); // White
  279. pShaderShadow->EnableSRGBWrite( true );
  280. #endif
  281. pShader->FogToFogColor();
  282. // Per-instance state
  283. pShader->PI_BeginCommandBuffer();
  284. pShader->PI_SetVertexShaderAmbientLightCube();
  285. pShader->PI_SetPixelShaderGlintDamping( 1 );
  286. pShader->PI_EndCommandBuffer();
  287. }
  288. DYNAMIC_STATE
  289. {
  290. TextureBindFlags_t nRead01Flags = TEXTURE_BINDFLAGS_NONE;
  291. #ifdef STDSHADER_DX9_DLL_EXPORT
  292. nRead01Flags = TEXTURE_BINDFLAGS_SRGBREAD;
  293. #endif
  294. pShader->BindTexture( SHADER_SAMPLER0, nRead01Flags, info.m_nBaseTexture, info.m_nFrame );
  295. pShader->BindTexture( SHADER_SAMPLER1, nRead01Flags, info.m_nIris, info.m_nIrisFrame );
  296. pShader->BindTexture( SHADER_SAMPLER2, TEXTURE_BINDFLAGS_NONE, info.m_nGlint );
  297. pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, info.m_nEyeOrigin );
  298. pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, info.m_nEyeUp );
  299. pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, info.m_nIrisU );
  300. pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, info.m_nIrisV );
  301. pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, info.m_nGlintU );
  302. pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_5, info.m_nGlintV );
  303. #ifdef STDSHADER_DX9_DLL_EXPORT
  304. Assert( bDX9 );
  305. LightState_t lightState = {0, false, false};
  306. pShaderAPI->GetDX9LightState( &lightState );
  307. #if !defined( _X360 ) && !defined( _PS3 )
  308. if ( !g_pHardwareConfig->HasFastVertexTextures() )
  309. #endif
  310. {
  311. bool bUseStaticControlFlow = g_pHardwareConfig->SupportsStaticControlFlow();
  312. DECLARE_DYNAMIC_VERTEX_SHADER( eyes_vs20 );
  313. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
  314. SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, lightState.HasDynamicLight() );
  315. SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLight ? 1 : 0 );
  316. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  317. SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, bUseStaticControlFlow ? 0 : lightState.m_nNumLights );
  318. SET_DYNAMIC_VERTEX_SHADER( eyes_vs20 );
  319. }
  320. #if !defined( _X360 ) && !defined( _PS3 )
  321. else
  322. {
  323. pShader->SetHWMorphVertexShaderState( VERTEX_SHADER_SHADER_SPECIFIC_CONST_7, VERTEX_SHADER_SHADER_SPECIFIC_CONST_8, SHADER_VERTEXTEXTURE_SAMPLER0 );
  324. DECLARE_DYNAMIC_VERTEX_SHADER( eyes_vs30 );
  325. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
  326. SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, lightState.HasDynamicLight() );
  327. SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLight ? 1 : 0 );
  328. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  329. SET_DYNAMIC_VERTEX_SHADER( eyes_vs30 );
  330. }
  331. #endif
  332. // Special constant for DX9 eyes: { Dilation, x, x, x };
  333. float vPSConst[4] = {params[info.m_nDilation]->GetFloatValue(), 0.0f, 0.0f, 0.0f};
  334. pShaderAPI->SetPixelShaderConstant( 0, vPSConst, 1 );
  335. pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS );
  336. float vEyePos_SpecExponent[4];
  337. pShaderAPI->GetWorldSpaceCameraPosition( vEyePos_SpecExponent );
  338. vEyePos_SpecExponent[3] = 0.0f;
  339. pShaderAPI->SetPixelShaderConstant( PSREG_EYEPOS_SPEC_EXPONENT, vEyePos_SpecExponent, 1 );
  340. #if !defined( _X360 ) && !defined( _PS3 )
  341. if ( !g_pHardwareConfig->HasFastVertexTextures() )
  342. #endif
  343. {
  344. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  345. {
  346. DECLARE_DYNAMIC_PIXEL_SHADER( eyes_ps20b );
  347. SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, pShaderAPI->ShouldWriteDepthToDestAlpha() );
  348. SET_DYNAMIC_PIXEL_SHADER( eyes_ps20b );
  349. }
  350. else
  351. {
  352. DECLARE_DYNAMIC_PIXEL_SHADER( eyes_ps20 );
  353. SET_DYNAMIC_PIXEL_SHADER( eyes_ps20 );
  354. }
  355. }
  356. #if !defined( _X360 ) && !defined( _PS3 )
  357. else
  358. {
  359. DECLARE_DYNAMIC_PIXEL_SHADER( eyes_ps30 );
  360. SET_DYNAMIC_PIXEL_SHADER_COMBO( WRITE_DEPTH_TO_DESTALPHA, pShaderAPI->ShouldWriteDepthToDestAlpha() );
  361. SET_DYNAMIC_PIXEL_SHADER( eyes_ps30 );
  362. }
  363. #endif
  364. #endif
  365. }
  366. pShader->Draw();
  367. }
  368. static void DrawEyes_DX8_DX9_Internal( bool bDX9, CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI,
  369. IShaderShadow* pShaderShadow, bool bHasFlashlight, Eyes_DX8_DX9_Vars_t &info, VertexCompressionType_t vertexCompression )
  370. {
  371. if( !bHasFlashlight )
  372. {
  373. DrawUsingVertexShader( bDX9, pShader, params, pShaderAPI, pShaderShadow, info, vertexCompression );
  374. }
  375. else
  376. {
  377. DrawFlashlight( bDX9, pShader, params, pShaderAPI, pShaderShadow, info, vertexCompression );
  378. }
  379. }
  380. void DrawEyes_DX8_DX9( bool bDX9, CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI,
  381. IShaderShadow* pShaderShadow, Eyes_DX8_DX9_Vars_t &info, VertexCompressionType_t vertexCompression )
  382. {
  383. SHADOW_STATE
  384. {
  385. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT );
  386. }
  387. bool bHasFlashlight = pShader->UsingFlashlight( params );
  388. if ( bHasFlashlight && ( IsX360() || IsPS3() ) )
  389. {
  390. DrawEyes_DX8_DX9_Internal( bDX9, pShader, params, pShaderAPI, pShaderShadow, false, info, vertexCompression );
  391. if ( pShaderShadow )
  392. {
  393. pShader->SetInitialShadowState( );
  394. }
  395. }
  396. DrawEyes_DX8_DX9_Internal( bDX9, pShader, params, pShaderAPI, pShaderShadow, bHasFlashlight, info, vertexCompression );
  397. }