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.

78 lines
2.2 KiB

  1. // DYNAMIC: "CMBO_HUDUNDISTORT" "0..1"
  2. #include "shader_constant_register_map.h"
  3. #include "common_ps_fxc.h"
  4. sampler BaseTextureSampler : register( s0 );
  5. sampler DistortMapTextureSampler : register( s1 );
  6. const float4 DistortBounds : register( c0 );
  7. const int bHudTranslucent : register( c1 );
  8. struct PS_INPUT
  9. {
  10. float2 vBaseTexCoord : TEXCOORD0;
  11. };
  12. float4 main( PS_INPUT i ) : COLOR
  13. {
  14. float2 vOriginal = i.vBaseTexCoord.xy;
  15. // The full uv 0->1 range of the base texture here is shifted/scaled so that it maps
  16. // to the region that would be minUV->maxUV of the base texture in the regular undistort
  17. // code. This lets us overlay a higher-resolution inset rectangle directly onto the
  18. // render target with undistort, which results in a much higher-quality HUD.
  19. float2 minUV = DistortBounds.xy;
  20. float2 maxUV = DistortBounds.zw;
  21. float2 scaleUV = 1.0 / ( maxUV - minUV );
  22. float2 vGreen;
  23. float4 vFinal;
  24. #if ( CMBO_HUDUNDISTORT )
  25. {
  26. float4 vRead = tex2D( DistortMapTextureSampler, vOriginal );
  27. float2 vRed = vRead.xy;
  28. float2 vBlue = vRead.zw;
  29. vGreen = ( vRed + vBlue ) / 2.0;
  30. vRed = ( vRed - minUV ) * scaleUV;
  31. vGreen = ( vGreen - minUV ) * scaleUV;
  32. vBlue = ( vBlue - minUV ) * scaleUV;
  33. vFinal.r = tex2D( BaseTextureSampler, vRed ).r;
  34. vFinal.ga = tex2D( BaseTextureSampler, vGreen ).ga;
  35. vFinal.b = tex2D( BaseTextureSampler, vBlue ).b;
  36. }
  37. #else
  38. {
  39. vGreen = ( vOriginal - minUV ) * scaleUV;
  40. vFinal = tex2D( BaseTextureSampler, vGreen );
  41. }
  42. #endif
  43. // When the HUD isn't supposed to be rendered as translucent, some of its elements do occasionally have non-unit alpha.
  44. // We always have blending and alphatest enabled here, so if the hud itself is not supposed to be translucent we need
  45. // to fix up the alphas.
  46. vFinal.a = lerp( 1, vFinal.a, bHudTranslucent );
  47. // Smooth off the edges of the quad. This also gives (0,0,0,0) in the outer areas, for alpha test and for blackout.
  48. const float edgeRampFrac = 0.005;
  49. float2 uvEdgeRamp = smoothstep( float2(-edgeRampFrac,-edgeRampFrac), float2(edgeRampFrac,edgeRampFrac), vGreen ) *
  50. ( 1 - smoothstep( float2(1-edgeRampFrac,1-edgeRampFrac), float2(1+edgeRampFrac,1+edgeRampFrac), vGreen ) );
  51. float edgeRamp = uvEdgeRamp.x * uvEdgeRamp.y;
  52. vFinal *= edgeRamp;
  53. return vFinal;
  54. }