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.

63 lines
2.1 KiB

  1. // DYNAMIC: "PIXELFOGTYPE" "0..1"
  2. // STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC]
  3. // STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX]
  4. #define HDRTYPE HDR_TYPE_NONE
  5. #include "common_ps_fxc.h"
  6. const HALF4 g_ShadowColor : register( c1 );
  7. const HALF3 g_EyePos : register( c2 );
  8. const HALF4 g_FogParams : register( c3 );
  9. sampler ShadowSampler : register( s0 );
  10. // CENTROID: TEXCOORD0
  11. // CENTROID: TEXCOORD1
  12. // CENTROID: TEXCOORD2
  13. // CENTROID: TEXCOORD3
  14. // CENTROID: TEXCOORD4
  15. struct PS_INPUT
  16. {
  17. float2 texCoord0 : TEXCOORD0;
  18. float2 texCoord1 : TEXCOORD1;
  19. float2 texCoord2 : TEXCOORD2;
  20. float2 texCoord3 : TEXCOORD3;
  21. float2 texCoord4 : TEXCOORD4;
  22. HALF4 worldPos_projPosZ : TEXCOORD5;
  23. HALF4 shadowColor : COLOR0;
  24. HALF4 fogFactorW : COLOR1;
  25. };
  26. float4 main( PS_INPUT i ) : COLOR
  27. {
  28. HALF4 samples[5];
  29. samples[0] = tex2D( ShadowSampler, i.texCoord0 );
  30. samples[1] = tex2D( ShadowSampler, i.texCoord1 );
  31. samples[2] = tex2D( ShadowSampler, i.texCoord2 );
  32. samples[3] = tex2D( ShadowSampler, i.texCoord3 );
  33. samples[4] = tex2D( ShadowSampler, i.texCoord4 );
  34. // Interpolate between a bunch of jittered shadow samples.
  35. HALF shadowCoverage = (samples[0].a + samples[1].a + samples[2].a + samples[3].a + samples[4].a) * 0.2;
  36. // To accomplish shadow fading, subtract vertex alpha from texture alpha
  37. shadowCoverage = saturate( shadowCoverage - i.shadowColor.a );
  38. // Blend between white and the constant color...
  39. // return lerp( 1.0-shadowCoverage, 1.0, g_ShadowColor );
  40. // this is equivalent, and saves an instruction
  41. HALF4 result = shadowCoverage*g_ShadowColor - shadowCoverage;
  42. result = 1.0 + result;
  43. float alpha = 1.0f;
  44. float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w );
  45. // Apply fog here to compensate for our srcColor*dstColor alpha blend into already fogged pixels
  46. result.rgb = 1.0f - ( ( 1.0f - result.rgb ) * pow( ( 1.0f - fogFactor ), 4.0f ) );
  47. // Call FinalOutput without fog!
  48. return FinalOutput( float4( result.rgb, alpha ), fogFactor, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
  49. }