Team Fortress 2 Source Code as on 22/4/2020
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.

461 lines
19 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. #include "BaseVSShader.h"
  3. #include "mathlib/vmatrix.h"
  4. #include "eye_refract_helper.h"
  5. #include "cpp_shader_constant_register_map.h"
  6. #include "eyes_flashlight_vs11.inc"
  7. #include "eyes_flashlight_ps11.inc"
  8. #include "eye_refract_vs20.inc"
  9. #include "eye_refract_ps20.inc"
  10. #include "eye_refract_ps20b.inc"
  11. #ifndef _X360
  12. #include "eye_refract_vs30.inc"
  13. #include "eye_refract_ps30.inc"
  14. #endif
  15. #include "convar.h"
  16. static ConVar r_lightwarpidentity( "r_lightwarpidentity","0", FCVAR_CHEAT );
  17. void InitParams_Eyes_Refract( CBaseVSShader *pShader, IMaterialVar** params, const char *pMaterialName, Eye_Refract_Vars_t &info )
  18. {
  19. // FLASHLIGHTFIXME
  20. if ( g_pHardwareConfig->SupportsBorderColor() )
  21. {
  22. params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight_border" );
  23. }
  24. else
  25. {
  26. params[FLASHLIGHTTEXTURE]->SetStringValue( "effects/flashlight001" );
  27. }
  28. // Set material flags
  29. SET_FLAGS2( MATERIAL_VAR2_SUPPORTS_HW_SKINNING );
  30. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT );
  31. // Set material parameter default values
  32. if ( ( info.m_nIntro >= 0 ) && ( !params[info.m_nIntro]->IsDefined() ) )
  33. {
  34. params[info.m_nIntro]->SetIntValue( kDefaultIntro );
  35. }
  36. if ( ( info.m_nDilation >= 0 ) && ( !params[info.m_nDilation]->IsDefined() ) )
  37. {
  38. params[info.m_nDilation]->SetFloatValue( kDefaultDilation );
  39. }
  40. if ( ( info.m_nGlossiness >= 0 ) && ( !params[info.m_nGlossiness]->IsDefined() ) )
  41. {
  42. params[info.m_nGlossiness]->SetFloatValue( kDefaultGlossiness );
  43. }
  44. if ( ( info.m_nSphereTexKillCombo >= 0 ) && ( !params[info.m_nSphereTexKillCombo]->IsDefined() ) )
  45. {
  46. params[info.m_nSphereTexKillCombo]->SetIntValue( kDefaultSphereTexKillCombo );
  47. }
  48. if ( ( info.m_nRaytraceSphere >= 0 ) && ( !params[info.m_nRaytraceSphere]->IsDefined() ) )
  49. {
  50. params[info.m_nRaytraceSphere]->SetIntValue( kDefaultRaytraceSphere );
  51. }
  52. if ( ( info.m_nAmbientOcclColor >= 0 ) && ( !params[info.m_nAmbientOcclColor]->IsDefined() ) )
  53. {
  54. params[info.m_nAmbientOcclColor]->SetVecValue( kDefaultAmbientOcclColor, 4 );
  55. }
  56. if ( ( info.m_nEyeballRadius >= 0 ) && ( !params[info.m_nEyeballRadius]->IsDefined() ) )
  57. {
  58. params[info.m_nEyeballRadius]->SetFloatValue( kDefaultEyeballRadius );
  59. }
  60. if ( ( info.m_nParallaxStrength >= 0 ) && ( !params[info.m_nParallaxStrength]->IsDefined() ) )
  61. {
  62. params[info.m_nParallaxStrength]->SetFloatValue( kDefaultParallaxStrength );
  63. }
  64. if ( ( info.m_nCorneaBumpStrength >= 0 ) && ( !params[info.m_nCorneaBumpStrength]->IsDefined() ) )
  65. {
  66. params[info.m_nCorneaBumpStrength]->SetFloatValue( kDefaultCorneaBumpStrength );
  67. }
  68. }
  69. void Init_Eyes_Refract( CBaseVSShader *pShader, IMaterialVar** params, Eye_Refract_Vars_t &info )
  70. {
  71. pShader->LoadTexture( info.m_nCorneaTexture ); // SHADER_SAMPLER0 (this is a normal, hence not sRGB)
  72. pShader->LoadTexture( info.m_nIris, TEXTUREFLAGS_SRGB ); // SHADER_SAMPLER1
  73. pShader->LoadCubeMap( info.m_nEnvmap, TEXTUREFLAGS_SRGB ); // SHADER_SAMPLER2
  74. pShader->LoadTexture( info.m_nAmbientOcclTexture, TEXTUREFLAGS_SRGB ); // SHADER_SAMPLER3
  75. if ( IS_PARAM_DEFINED( info.m_nDiffuseWarpTexture ) )
  76. {
  77. pShader->LoadTexture( info.m_nDiffuseWarpTexture ); // SHADER_SAMPLER4
  78. }
  79. pShader->LoadTexture( FLASHLIGHTTEXTURE, TEXTUREFLAGS_SRGB ); // SHADER_SAMPLER5
  80. }
  81. void Draw_Eyes_Refract_Internal( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI,
  82. IShaderShadow* pShaderShadow, bool bDrawFlashlightAdditivePass, Eye_Refract_Vars_t &info, VertexCompressionType_t vertexCompression )
  83. {
  84. bool bDiffuseWarp = IS_PARAM_DEFINED( info.m_nDiffuseWarpTexture );
  85. bool bIntro = IS_PARAM_DEFINED( info.m_nIntro ) ? ( params[info.m_nIntro]->GetIntValue() ? true : false ) : false;
  86. SHADOW_STATE
  87. {
  88. SET_FLAGS2( MATERIAL_VAR2_LIGHTING_VERTEX_LIT );
  89. pShaderShadow->EnableTexture( SHADER_SAMPLER0, true ); // Cornea normal
  90. pShaderShadow->EnableTexture( SHADER_SAMPLER1, true ); // Iris
  91. pShaderShadow->EnableTexture( SHADER_SAMPLER2, true ); // Cube reflection
  92. pShaderShadow->EnableTexture( SHADER_SAMPLER3, true ); // Ambient occlusion
  93. // Set stream format (note that this shader supports compression)
  94. unsigned int flags = VERTEX_POSITION | VERTEX_NORMAL | VERTEX_FORMAT_COMPRESSED;
  95. int nTexCoordCount = 1;
  96. int userDataSize = 0;
  97. pShaderShadow->VertexShaderVertexFormat( flags, nTexCoordCount, NULL, userDataSize );
  98. if ( bDiffuseWarp )
  99. {
  100. pShaderShadow->EnableTexture( SHADER_SAMPLER4, true ); // Light warp
  101. }
  102. int nShadowFilterMode = 0;
  103. if ( bDrawFlashlightAdditivePass == true )
  104. {
  105. if ( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  106. {
  107. nShadowFilterMode = g_pHardwareConfig->GetShadowFilterMode(); // Based upon vendor and device dependent formats
  108. }
  109. pShaderShadow->EnableDepthWrites( false );
  110. pShader->EnableAlphaBlending( SHADER_BLEND_ONE, SHADER_BLEND_ONE ); // Write over the eyes that were already there
  111. pShaderShadow->EnableTexture( SHADER_SAMPLER5, true ); // Flashlight cookie
  112. }
  113. #ifndef _X360
  114. if ( !g_pHardwareConfig->HasFastVertexTextures() )
  115. #endif
  116. {
  117. DECLARE_STATIC_VERTEX_SHADER( eye_refract_vs20 );
  118. SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, IS_FLAG_SET( MATERIAL_VAR_HALFLAMBERT ) );
  119. SET_STATIC_VERTEX_SHADER_COMBO( INTRO, bIntro ? 1 : 0 );
  120. SET_STATIC_VERTEX_SHADER_COMBO( FLASHLIGHT, bDrawFlashlightAdditivePass ? 1 : 0 );
  121. SET_STATIC_VERTEX_SHADER_COMBO( LIGHTWARPTEXTURE, bDiffuseWarp ? 1 : 0 );
  122. SET_STATIC_VERTEX_SHADER( eye_refract_vs20 );
  123. if ( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  124. {
  125. bool bSphereTexKillCombo = IS_PARAM_DEFINED( info.m_nSphereTexKillCombo ) ? ( params[info.m_nSphereTexKillCombo]->GetIntValue() ? true : false ) : ( kDefaultSphereTexKillCombo ? true : false );
  126. bool bRayTraceSphere = IS_PARAM_DEFINED( info.m_nRaytraceSphere ) ? ( params[info.m_nRaytraceSphere]->GetIntValue() ? true : false ) : ( kDefaultRaytraceSphere ? true : false );
  127. DECLARE_STATIC_PIXEL_SHADER( eye_refract_ps20b );
  128. SET_STATIC_PIXEL_SHADER_COMBO( SPHERETEXKILLCOMBO, bSphereTexKillCombo ? 1 : 0 );
  129. SET_STATIC_PIXEL_SHADER_COMBO( RAYTRACESPHERE, bRayTraceSphere ? 1 : 0 );
  130. SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, bDrawFlashlightAdditivePass ? 1 : 0 );
  131. SET_STATIC_PIXEL_SHADER_COMBO( LIGHTWARPTEXTURE, bDiffuseWarp ? 1 : 0 );
  132. SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode );
  133. SET_STATIC_PIXEL_SHADER( eye_refract_ps20b );
  134. if ( bDrawFlashlightAdditivePass == true )
  135. {
  136. pShaderShadow->EnableTexture( SHADER_SAMPLER6, true ); // Shadow depth map
  137. pShaderShadow->SetShadowDepthFiltering( SHADER_SAMPLER6 );
  138. pShaderShadow->EnableTexture( SHADER_SAMPLER7, true ); // Noise map
  139. }
  140. }
  141. else
  142. {
  143. DECLARE_STATIC_PIXEL_SHADER( eye_refract_ps20 );
  144. SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, bDrawFlashlightAdditivePass ? 1 : 0 );
  145. SET_STATIC_PIXEL_SHADER_COMBO( LIGHTWARPTEXTURE, bDiffuseWarp ? 1 : 0 );
  146. SET_STATIC_PIXEL_SHADER( eye_refract_ps20 );
  147. }
  148. }
  149. #ifndef _X360
  150. else
  151. {
  152. // The vertex shader uses the vertex id stream
  153. SET_FLAGS2( MATERIAL_VAR2_USES_VERTEXID );
  154. DECLARE_STATIC_VERTEX_SHADER( eye_refract_vs30 );
  155. SET_STATIC_VERTEX_SHADER_COMBO( HALFLAMBERT, IS_FLAG_SET( MATERIAL_VAR_HALFLAMBERT ) );
  156. SET_STATIC_VERTEX_SHADER_COMBO( INTRO, bIntro ? 1 : 0 );
  157. SET_STATIC_VERTEX_SHADER_COMBO( FLASHLIGHT, bDrawFlashlightAdditivePass ? 1 : 0 );
  158. SET_STATIC_VERTEX_SHADER_COMBO( LIGHTWARPTEXTURE, bDiffuseWarp ? 1 : 0 );
  159. SET_STATIC_VERTEX_SHADER( eye_refract_vs30 );
  160. bool bSphereTexKillCombo = IS_PARAM_DEFINED( info.m_nSphereTexKillCombo ) ? ( params[info.m_nSphereTexKillCombo]->GetIntValue() ? true : false ) : ( kDefaultSphereTexKillCombo ? true : false );
  161. bool bRayTraceSphere = IS_PARAM_DEFINED( info.m_nRaytraceSphere ) ? ( params[info.m_nRaytraceSphere]->GetIntValue() ? true : false ) : ( kDefaultRaytraceSphere ? true : false );
  162. DECLARE_STATIC_PIXEL_SHADER( eye_refract_ps30 );
  163. SET_STATIC_PIXEL_SHADER_COMBO( SPHERETEXKILLCOMBO, bSphereTexKillCombo ? 1 : 0 );
  164. SET_STATIC_PIXEL_SHADER_COMBO( RAYTRACESPHERE, bRayTraceSphere ? 1 : 0 );
  165. SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHT, bDrawFlashlightAdditivePass ? 1 : 0 );
  166. SET_STATIC_PIXEL_SHADER_COMBO( LIGHTWARPTEXTURE, bDiffuseWarp ? 1 : 0 );
  167. SET_STATIC_PIXEL_SHADER_COMBO( FLASHLIGHTDEPTHFILTERMODE, nShadowFilterMode );
  168. SET_STATIC_PIXEL_SHADER( eye_refract_ps30 );
  169. if ( bDrawFlashlightAdditivePass == true )
  170. {
  171. pShaderShadow->EnableTexture( SHADER_SAMPLER6, true ); // Shadow depth map
  172. pShaderShadow->EnableTexture( SHADER_SAMPLER7, true ); // Noise map
  173. }
  174. }
  175. #endif
  176. // On DX9, get the gamma read and write correct
  177. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER1, true ); // Iris
  178. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER2, true ); // Cube map reflection
  179. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER3, true ); // Ambient occlusion
  180. pShaderShadow->EnableSRGBWrite( true );
  181. if ( bDrawFlashlightAdditivePass == true )
  182. {
  183. pShaderShadow->EnableSRGBRead( SHADER_SAMPLER5, true ); // Flashlight cookie
  184. }
  185. // Fog
  186. if ( bDrawFlashlightAdditivePass == true )
  187. {
  188. pShader->FogToBlack();
  189. }
  190. else
  191. {
  192. pShader->FogToFogColor();
  193. }
  194. }
  195. DYNAMIC_STATE
  196. {
  197. VMatrix worldToTexture;
  198. ITexture *pFlashlightDepthTexture = NULL;
  199. FlashlightState_t flashlightState;
  200. bool bFlashlightShadows = false;
  201. if ( bDrawFlashlightAdditivePass == true )
  202. {
  203. flashlightState = pShaderAPI->GetFlashlightStateEx( worldToTexture, &pFlashlightDepthTexture );
  204. bFlashlightShadows = flashlightState.m_bEnableShadows && ( pFlashlightDepthTexture != NULL );
  205. }
  206. pShader->BindTexture( SHADER_SAMPLER0, info.m_nCorneaTexture ); // Cornea normal
  207. pShader->BindTexture( SHADER_SAMPLER1, info.m_nIris, info.m_nIrisFrame );
  208. pShader->BindTexture( SHADER_SAMPLER2, info.m_nEnvmap );
  209. pShader->BindTexture( SHADER_SAMPLER3, info.m_nAmbientOcclTexture );
  210. if ( bDiffuseWarp )
  211. {
  212. if ( r_lightwarpidentity.GetBool() )
  213. {
  214. pShaderAPI->BindStandardTexture( SHADER_SAMPLER4, TEXTURE_IDENTITY_LIGHTWARP );
  215. }
  216. else
  217. {
  218. pShader->BindTexture( SHADER_SAMPLER4, info.m_nDiffuseWarpTexture );
  219. }
  220. }
  221. if ( bDrawFlashlightAdditivePass == true )
  222. pShader->BindTexture( SHADER_SAMPLER5, flashlightState.m_pSpotlightTexture, flashlightState.m_nSpotlightTextureFrame );
  223. pShader->SetAmbientCubeDynamicStateVertexShader();
  224. pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_0, info.m_nEyeOrigin );
  225. pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, info.m_nIrisU );
  226. pShader->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_3, info.m_nIrisV );
  227. if ( bDrawFlashlightAdditivePass == true )
  228. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_4, flashlightState.m_vecLightOrigin.Base(), 1 );
  229. LightState_t lightState = { 0, false, false };
  230. if ( bDrawFlashlightAdditivePass == false )
  231. {
  232. pShaderAPI->GetDX9LightState( &lightState );
  233. }
  234. #ifndef _X360
  235. if ( !g_pHardwareConfig->HasFastVertexTextures() )
  236. #endif
  237. {
  238. DECLARE_DYNAMIC_VERTEX_SHADER( eye_refract_vs20 );
  239. SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  240. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
  241. SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, lightState.HasDynamicLight() );
  242. SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLightVertex ? 1 : 0 );
  243. SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights );
  244. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  245. SET_DYNAMIC_VERTEX_SHADER( eye_refract_vs20 );
  246. }
  247. #ifndef _X360
  248. else
  249. {
  250. pShader->SetHWMorphVertexShaderState( VERTEX_SHADER_SHADER_SPECIFIC_CONST_10, VERTEX_SHADER_SHADER_SPECIFIC_CONST_11, SHADER_VERTEXTEXTURE_SAMPLER0 );
  251. DECLARE_DYNAMIC_VERTEX_SHADER( eye_refract_vs30 );
  252. SET_DYNAMIC_VERTEX_SHADER_COMBO( DOWATERFOG, pShaderAPI->GetSceneFogMode() == MATERIAL_FOG_LINEAR_BELOW_FOG_Z );
  253. SET_DYNAMIC_VERTEX_SHADER_COMBO( SKINNING, pShaderAPI->GetCurrentNumBones() > 0 );
  254. SET_DYNAMIC_VERTEX_SHADER_COMBO( DYNAMIC_LIGHT, lightState.HasDynamicLight() );
  255. SET_DYNAMIC_VERTEX_SHADER_COMBO( STATIC_LIGHT, lightState.m_bStaticLightVertex ? 1 : 0 );
  256. SET_DYNAMIC_VERTEX_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights );
  257. SET_DYNAMIC_VERTEX_SHADER_COMBO( MORPHING, pShaderAPI->IsHWMorphingEnabled() );
  258. SET_DYNAMIC_VERTEX_SHADER_COMBO( COMPRESSED_VERTS, (int)vertexCompression );
  259. SET_DYNAMIC_VERTEX_SHADER( eye_refract_vs30 );
  260. }
  261. #endif
  262. // Get luminance of ambient cube and saturate it
  263. float fAverageAmbient = max(0.0f, min( pShaderAPI->GetAmbientLightCubeLuminance(), 1.0f ) );
  264. // Special constant for DX9 eyes: { Dilation, Glossiness, x, x };
  265. float vPSConst[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  266. vPSConst[0] = IS_PARAM_DEFINED( info.m_nDilation ) ? params[info.m_nDilation]->GetFloatValue() : kDefaultDilation;
  267. vPSConst[1] = IS_PARAM_DEFINED( info.m_nGlossiness ) ? params[info.m_nGlossiness]->GetFloatValue() : kDefaultGlossiness;
  268. vPSConst[2] = fAverageAmbient;
  269. vPSConst[3] = IS_PARAM_DEFINED( info.m_nCorneaBumpStrength ) ? params[info.m_nCorneaBumpStrength]->GetFloatValue() : kDefaultCorneaBumpStrength;
  270. pShaderAPI->SetPixelShaderConstant( 0, vPSConst, 1 );
  271. pShaderAPI->SetPixelShaderConstant( 1, IS_PARAM_DEFINED( info.m_nEyeOrigin ) ? params[info.m_nEyeOrigin]->GetVecValue() : kDefaultEyeOrigin, 1 );
  272. pShaderAPI->SetPixelShaderConstant( 2, IS_PARAM_DEFINED( info.m_nIrisU ) ? params[info.m_nIrisU]->GetVecValue() : kDefaultIrisU, 1 );
  273. pShaderAPI->SetPixelShaderConstant( 3, IS_PARAM_DEFINED( info.m_nIrisV ) ? params[info.m_nIrisV]->GetVecValue() : kDefaultIrisV, 1 );
  274. float vEyePos[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  275. pShaderAPI->GetWorldSpaceCameraPosition( vEyePos );
  276. pShaderAPI->SetPixelShaderConstant( 4, vEyePos, 1 );
  277. pShaderAPI->SetPixelShaderConstant( 5, IS_PARAM_DEFINED( info.m_nAmbientOcclColor ) ? params[info.m_nAmbientOcclColor]->GetVecValue() : kDefaultAmbientOcclColor, 1 );
  278. float vPackedConst6[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
  279. //vPackedConst6[0] Unused
  280. vPackedConst6[1] = IS_PARAM_DEFINED( info.m_nEyeballRadius ) ? params[info.m_nEyeballRadius]->GetFloatValue() : kDefaultEyeballRadius;
  281. //vPackedConst6[2] = IS_PARAM_DEFINED( info.m_nRaytraceSphere ) ? params[info.m_nRaytraceSphere]->GetFloatValue() : kDefaultRaytraceSphere;
  282. vPackedConst6[3] = IS_PARAM_DEFINED( info.m_nParallaxStrength ) ? params[info.m_nParallaxStrength]->GetFloatValue() : kDefaultParallaxStrength;
  283. pShaderAPI->SetPixelShaderConstant( 6, vPackedConst6, 1 );
  284. float fPixelFogType = pShaderAPI->GetPixelFogCombo() == 1 ? 1 : 0;
  285. // Controls for lerp-style paths through shader code
  286. float vShaderControls[4] = { fPixelFogType, 0, 0, 0 };
  287. pShaderAPI->SetPixelShaderConstant( 10, vShaderControls, 1 );
  288. if ( bDrawFlashlightAdditivePass == true )
  289. {
  290. SetFlashLightColorFromState( flashlightState, pShaderAPI );
  291. if ( pFlashlightDepthTexture && g_pConfig->ShadowDepthTexture() && flashlightState.m_bEnableShadows )
  292. {
  293. pShader->BindTexture( SHADER_SAMPLER6, pFlashlightDepthTexture, 0 );
  294. pShaderAPI->BindStandardTexture( SHADER_SAMPLER7, TEXTURE_SHADOW_NOISE_2D );
  295. }
  296. }
  297. // Flashlight tax
  298. #ifndef _X360
  299. if ( !g_pHardwareConfig->HasFastVertexTextures() )
  300. #endif
  301. {
  302. if ( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  303. {
  304. DECLARE_DYNAMIC_PIXEL_SHADER( eye_refract_ps20b );
  305. SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights );
  306. SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows );
  307. SET_DYNAMIC_PIXEL_SHADER( eye_refract_ps20b );
  308. }
  309. else // ps.2.0
  310. {
  311. DECLARE_DYNAMIC_PIXEL_SHADER( eye_refract_ps20 );
  312. SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights );
  313. SET_DYNAMIC_PIXEL_SHADER( eye_refract_ps20 );
  314. }
  315. }
  316. #ifndef _X360
  317. else
  318. {
  319. DECLARE_DYNAMIC_PIXEL_SHADER( eye_refract_ps30 );
  320. SET_DYNAMIC_PIXEL_SHADER_COMBO( NUM_LIGHTS, lightState.m_nNumLights );
  321. SET_DYNAMIC_PIXEL_SHADER_COMBO( FLASHLIGHTSHADOWS, bFlashlightShadows );
  322. SET_DYNAMIC_PIXEL_SHADER( eye_refract_ps30 );
  323. }
  324. #endif
  325. pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS );
  326. if ( bDrawFlashlightAdditivePass == true )
  327. {
  328. float atten[4], pos[4], tweaks[4];
  329. atten[0] = flashlightState.m_fConstantAtten; // Set the flashlight attenuation factors
  330. atten[1] = flashlightState.m_fLinearAtten;
  331. atten[2] = flashlightState.m_fQuadraticAtten;
  332. atten[3] = flashlightState.m_FarZ;
  333. pShaderAPI->SetPixelShaderConstant( 7, atten, 1 );
  334. pos[0] = flashlightState.m_vecLightOrigin[0]; // Set the flashlight origin
  335. pos[1] = flashlightState.m_vecLightOrigin[1];
  336. pos[2] = flashlightState.m_vecLightOrigin[2];
  337. pShaderAPI->SetPixelShaderConstant( 8, pos, 1 );
  338. //pShaderAPI->SetPixelShaderConstant( 9, worldToTexture.Base(), 4 );
  339. //10
  340. //11
  341. //12
  342. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, worldToTexture[0], 1 );
  343. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_7, worldToTexture[1], 1 );
  344. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_8, worldToTexture[2], 1 );
  345. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_9, worldToTexture[3], 1 );
  346. // Tweaks associated with a given flashlight
  347. tweaks[0] = flashlightState.m_flShadowFilterSize / flashlightState.m_flShadowMapResolution;
  348. tweaks[1] = ShadowAttenFromState( flashlightState );
  349. pShader->HashShadow2DJitter( flashlightState.m_flShadowJitterSeed, &tweaks[2], &tweaks[3] );
  350. pShaderAPI->SetPixelShaderConstant( 9, tweaks, 1 );
  351. // Dimensions of screen, used for screen-space noise map sampling
  352. float vScreenScale[4] = {1280.0f / 32.0f, 720.0f / 32.0f, 0, 0};
  353. int nWidth, nHeight;
  354. pShaderAPI->GetBackBufferDimensions( nWidth, nHeight );
  355. vScreenScale[0] = (float) nWidth / 32.0f;
  356. vScreenScale[1] = (float) nHeight / 32.0f;
  357. pShaderAPI->SetPixelShaderConstant( PSREG_FLASHLIGHT_SCREEN_SCALE, vScreenScale, 1 );
  358. }
  359. else // Lighting constants when not drawing flashlight
  360. {
  361. pShaderAPI->CommitPixelShaderLighting( PSREG_LIGHT_INFO_ARRAY );
  362. }
  363. // Intro tax
  364. if ( bIntro )
  365. {
  366. float curTime = params[info.m_nWarpParam]->GetFloatValue();
  367. float timeVec[4] = { 0.0f, 0.0f, 0.0f, curTime };
  368. if ( IS_PARAM_DEFINED( info.m_nEntityOrigin ) )
  369. {
  370. params[info.m_nEntityOrigin]->GetVecValue( timeVec, 3 );
  371. }
  372. pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_6, timeVec, 1 );
  373. }
  374. }
  375. pShader->Draw();
  376. }
  377. extern ConVar r_flashlight_version2;
  378. void Draw_Eyes_Refract( CBaseVSShader *pShader, IMaterialVar** params, IShaderDynamicAPI *pShaderAPI,
  379. IShaderShadow* pShaderShadow, Eye_Refract_Vars_t &info, VertexCompressionType_t vertexCompression )
  380. {
  381. bool bHasFlashlight = pShader->UsingFlashlight( params );
  382. if( bHasFlashlight && ( IsX360() || r_flashlight_version2.GetInt() ) )
  383. {
  384. Draw_Eyes_Refract_Internal( pShader, params, pShaderAPI, pShaderShadow, false, info, vertexCompression );
  385. if ( pShaderShadow )
  386. {
  387. pShader->SetInitialShadowState( );
  388. }
  389. }
  390. Draw_Eyes_Refract_Internal( pShader, params, pShaderAPI, pShaderShadow, bHasFlashlight, info, vertexCompression );
  391. }