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.

51 lines
1.5 KiB

  1. // STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC]
  2. // STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX]
  3. #define HDRTYPE HDR_TYPE_NONE
  4. #include "common_ps_fxc.h"
  5. // This pixel shader compares the luminance against a constant value and retruns all 1's when greater
  6. sampler TexSampler : register( s0 );
  7. struct PS_INPUT
  8. {
  9. float2 uv0 : TEXCOORD0;
  10. #if defined( _X360 ) //matching pixel shader inputs to vertex shader outputs to avoid shader patches
  11. float2 ZeroTexCoord : TEXCOORD1;
  12. float2 bloomTexCoord : TEXCOORD2;
  13. #endif
  14. };
  15. float3 g_vComparisonMinMaxScale : register( c0 );
  16. #define g_flComparisonMin g_vComparisonMinMaxScale.x
  17. #define g_flComparisonMax g_vComparisonMinMaxScale.y
  18. #define g_flComparisonScale g_vComparisonMinMaxScale.z
  19. struct PS_OUTPUT
  20. {
  21. float4 color : COLOR0;
  22. float depth : DEPTH;
  23. };
  24. PS_OUTPUT main( PS_INPUT i )
  25. {
  26. float3 color = tex2D( TexSampler, i.uv0 ) * g_flComparisonScale;
  27. // Formula for calculating luminance based on NTSC standard
  28. float3 tmpv = { 0.2125f, 0.7154f, 0.0721f };
  29. float flLuminance = dot( color.rgb, tmpv.rgb );
  30. // Alternate formula for calculating luminance for linear RGB space (Widely used in color hue and saturation computations)
  31. //float3 tmpv = { 0.3086f, 0.6094f, 0.0820f };
  32. //float flLuminance = dot( color.rgb, tmpv.rgb );
  33. // Simple average
  34. //float flLuminance = ( color.r + color.g + color.b ) * 0.33333f;
  35. PS_OUTPUT o;
  36. o.color.rgba = step( g_flComparisonMin, flLuminance ) * step( flLuminance, g_flComparisonMax );
  37. o.depth = 0.0f;
  38. return o;
  39. }