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.

92 lines
3.3 KiB

  1. //====== Copyright � 1996-2006, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "common_flashlight_fxc.h"
  7. #include "shader_constant_register_map.h"
  8. const float4 g_vShadowTweaks : register( PSREG_ENVMAP_TINT__SHADOW_TWEAKS );
  9. sampler SpotSampler : register( s0 );
  10. sampler BaseTextureSampler : register( s1 );
  11. sampler IrisSampler : register( s3 );
  12. #if FLASHLIGHTSHADOWS && (!SHADER_MODEL_PS_1_1) && (!SHADER_MODEL_PS_1_4) && (!SHADER_MODEL_PS_2_0)
  13. sampler FlashlightDepthSampler : register( s4 );
  14. sampler RandomRotationSampler : register( s5 );
  15. #endif
  16. #if defined( SHADER_MODEL_PS_1_1 ) || defined ( SHADER_MODEL_PS_1_4 )
  17. #else
  18. const float4 g_FogParams : register( PSREG_FOG_PARAMS );
  19. const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT );
  20. #endif
  21. struct PS_INPUT
  22. {
  23. float4 spotTexCoord : TEXCOORD0;
  24. float2 baseTexCoord : TEXCOORD1;
  25. float2 irisTexCoord : TEXCOORD3;
  26. #if defined( SHADER_MODEL_PS_1_1 ) || defined ( SHADER_MODEL_PS_1_4 )
  27. float3 vertAtten : COLOR0;
  28. #else
  29. float3 vertAtten : TEXCOORD4;
  30. float3 worldPos : TEXCOORD5;
  31. float3 projPos : TEXCOORD7;
  32. #endif
  33. };
  34. float4 main( PS_INPUT i ) : COLOR
  35. {
  36. #if defined(SHADER_MODEL_PS_2_0)
  37. float3 spotColor = tex2Dproj( SpotSampler, i.spotTexCoord.xyzw ) * cFlashlightColor;
  38. #elif ( defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0) )
  39. float3 vProjCoords = i.spotTexCoord.xyz / i.spotTexCoord.w;
  40. float3 spotColor = tex2D( SpotSampler, vProjCoords ) * cFlashlightColor;
  41. #else
  42. float3 spotColor = tex2D( SpotSampler, i.spotTexCoord );
  43. #endif
  44. float4 baseSample = tex2D( BaseTextureSampler, i.baseTexCoord );
  45. float4 irisSample = tex2D( IrisSampler, i.irisTexCoord );
  46. float3 outcolor = float3(1,1,1);
  47. #if !defined( SHADER_MODEL_PS_1_1 ) && !defined( SHADER_MODEL_PS_1_4 )
  48. if( i.spotTexCoord.w <= 0.0f )
  49. {
  50. outcolor = float3(0,0,0);
  51. }
  52. #endif
  53. // Composite the iris and sclera together
  54. #if defined( SHADER_MODEL_PS_1_1 ) || defined ( SHADER_MODEL_PS_1_4 )
  55. float3 albedo = lerp( baseSample.xyz, irisSample.xyz, irisSample.a );
  56. #else
  57. float3 albedo = lerp( baseSample.xyz, irisSample.xyz * 0.5f, irisSample.a ); // dim down the iris in HDR
  58. #endif
  59. // Do shadow depth mapping...
  60. #if FLASHLIGHTSHADOWS && ( defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0) )
  61. float flShadow = DoFlashlightShadow( FlashlightDepthSampler, RandomRotationSampler, vProjCoords, i.projPos.xy / i.projPos.z, FLASHLIGHTDEPTHFILTERMODE, g_vShadowTweaks, true );
  62. float flAttenuated = lerp( flShadow, 1.0f, g_vShadowTweaks.y ); // Blend between fully attenuated and not attenuated
  63. flShadow = lerp( flAttenuated, flShadow, dot(i.vertAtten, float3(0.30f, 0.59f, 0.11f) ) ); // Blend between shadow and above, according to light attenuation
  64. outcolor *= flShadow * spotColor * albedo;
  65. #else
  66. outcolor *= spotColor * albedo;
  67. #endif
  68. // NOTE!! This has to be last to avoid loss of range.
  69. outcolor *= i.vertAtten;
  70. #if defined( SHADER_MODEL_PS_1_1 ) || defined ( SHADER_MODEL_PS_1_4 )
  71. return float4( outcolor, baseSample.a );
  72. #else
  73. float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.z, i.worldPos.z, i.projPos.z );
  74. return FinalOutput( float4( outcolor, 1.0f ), fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR );
  75. #endif
  76. }