Counter Strike : Global Offensive Source Code
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.

54 lines
1.4 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. // STATIC: "PS3REGCOUNT12" "0..0"
  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. };
  11. float3 g_vComparisonMinMaxScale : register( c0 );
  12. #define g_flComparisonMin g_vComparisonMinMaxScale.x
  13. #define g_flComparisonMax g_vComparisonMinMaxScale.y
  14. struct PS_OUTPUT
  15. {
  16. float4 color : COLOR0;
  17. #ifndef _X360
  18. float depth : DEPTH; // Workaround for ATI driver bug
  19. #endif
  20. };
  21. PS_OUTPUT main( PS_INPUT i )
  22. {
  23. float3 color = tex2D( TexSampler, i.uv0 ).xyz;
  24. // Formula for calculating luminance based on NTSC standard
  25. float3 tmpv = { 0.2125f, 0.7154f, 0.0721f };
  26. float flLuminance = dot( color.rgb, tmpv.rgb );
  27. // Alternate formula for calculating luminance for linear RGB space (Widely used in color hue and saturation computations)
  28. //float3 tmpv = { 0.3086f, 0.6094f, 0.0820f };
  29. //float flLuminance = dot( color.rgb, tmpv.rgb );
  30. // Simple average
  31. //float flLuminance = ( color.r + color.g + color.b ) * 0.33333f;
  32. PS_OUTPUT o;
  33. o.color.a = step( g_flComparisonMin, flLuminance ) * step( flLuminance, g_flComparisonMax );
  34. o.color.rgb = 1.0f;
  35. #ifndef _X360
  36. {
  37. o.depth = 0.0f; // Workaround for ATI driver bug
  38. }
  39. #endif
  40. return o;
  41. }