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.

68 lines
2.7 KiB

  1. //====== Copyright � 1996-2006, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. // DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps20b] [PC]
  7. // DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..0" [ps20b] [XBOX]
  8. // DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps30]
  9. // DYNAMIC: "PIXELFOGTYPE" "0..1"
  10. #include "common_ps_fxc.h"
  11. #include "shader_constant_register_map.h"
  12. sampler BaseTextureSampler : register( s0 );
  13. sampler IrisSampler : register( s1 );
  14. sampler GlintSampler : register( s2 );
  15. const float4 cEyeScalars : register( c0 ); // { Dilation, ambient, x, x }
  16. const float4 g_FogParams : register( PSREG_FOG_PARAMS );
  17. const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT );
  18. struct PS_INPUT
  19. {
  20. float2 baseTexCoord : TEXCOORD0;
  21. float2 irisTexCoord : TEXCOORD1;
  22. float2 glintTexCoord : TEXCOORD2;
  23. float3 vertAtten : TEXCOORD3;
  24. float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog
  25. };
  26. #define fDilationFactor cEyeScalars.x
  27. #define fGlintDamping cEyeScalars.y
  28. float4 main( PS_INPUT i ) : COLOR
  29. {
  30. float4 baseSample = tex2D( BaseTextureSampler, i.baseTexCoord );
  31. float4 glintSample = tex2D( GlintSampler, i.glintTexCoord );
  32. /*
  33. // Dilate the pupil/iris texture (1 is max dilation, 0 is none)
  34. float2 biasedCoords = i.irisTexCoord * 2.0f - 1.0f; // -1 to +1 range
  35. float fDilatability = saturate(0.8f - sqrt(dot(biasedCoords, biasedCoords) )); // 1 in the center, fading out to 0 at 0.8 from center, since irises are inset into maps
  36. float2 scaledCoords = biasedCoords * (1 + fDilatability); // Maximal dilation
  37. // Blend undilated and maximally dilated based upon dilation factor
  38. float2 dilatedCoords = lerp( scaledCoords, biasedCoords, 1.0f-saturate(cDilationFactor.x));
  39. dilatedCoords = dilatedCoords * 0.5f + 0.5f; // Back to 0..1 range
  40. */
  41. float4 irisSample = tex2D( IrisSampler, i.irisTexCoord ); // Sample the iris map using dilated coordinates
  42. float4 result;
  43. result.rgb = lerp( baseSample.rgb, irisSample.rgb, irisSample.a );
  44. result.rgb *= i.vertAtten;
  45. result.rgb += glintSample.rgb * fGlintDamping;
  46. result.a = baseSample.a;
  47. bool bWriteDepthToAlpha = false;
  48. // ps_2_b and beyond
  49. #if !(defined(SHADER_MODEL_PS_1_1) || defined(SHADER_MODEL_PS_1_4) || defined(SHADER_MODEL_PS_2_0))
  50. bWriteDepthToAlpha = WRITE_DEPTH_TO_DESTALPHA != 0;
  51. #endif
  52. float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w );
  53. return FinalOutput( result, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR, bWriteDepthToAlpha, i.worldPos_projPosZ.w );
  54. }