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.

89 lines
2.4 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. // STATIC: "BLOOMTYPE" "0..1"
  3. // STATIC: "PS3REGCOUNT48" "0..0"
  4. // STATIC: "SRGB_INPUT_ADAPTER" "0..1" [ps20b] [PC]
  5. // STATIC: "SRGB_INPUT_ADAPTER" "0..0" [CONSOLE]
  6. // DYNAMIC: "FLOAT_BACK_BUFFER" "0..1" [ps20b] [ps30] [PC]
  7. // DYNAMIC: "FLOAT_BACK_BUFFER" "0..0" [ps20b] [CONSOLE]
  8. // SKIP: ( $FLOAT_BACK_BUFFER == 1 ) && ( $SRGB_INPUT_ADAPTER == 1 )
  9. #include "common_ps_fxc.h"
  10. sampler TexSampler : register( s0 );
  11. float4 params : register( c0 );
  12. float4 params2 : register( c1 );
  13. #define g_flBloomExp params2.x
  14. #define g_flBloomSaturation params2.y
  15. struct PS_INPUT
  16. {
  17. float2 coordTap0 : TEXCOORD0;
  18. float2 coordTap1 : TEXCOORD1;
  19. float2 coordTap2 : TEXCOORD2;
  20. float2 coordTap3 : TEXCOORD3;
  21. };
  22. float4 Shape( float4 cColor )
  23. {
  24. #if ( BLOOMTYPE == 0 )
  25. {
  26. float flLum = dot( cColor.xyz, params.xyz );
  27. cColor.rgb = pow( cColor.xyz, params.w ) * flLum;
  28. }
  29. #endif
  30. #if ( BLOOMTYPE == 1 )
  31. {
  32. float flScale = 1.55f; // Color scale
  33. float flBias = -0.09f; // Color bias
  34. float flBrightnessClamp = 0.59f; // After scale and bias, clamp RGB values brighter than this
  35. float flExp = g_flBloomExp;
  36. cColor.rgb = pow( saturate( min( flBrightnessClamp, ( cColor.rgb * flScale ) + flBias ) ), flExp );
  37. }
  38. #endif
  39. return cColor;
  40. }
  41. float4_color_return_type main( PS_INPUT i ) : COLOR
  42. {
  43. // Sample 4 taps
  44. float4 s0 = tex2D( TexSampler, i.coordTap0 );
  45. float4 s1 = tex2D( TexSampler, i.coordTap1 );
  46. float4 s2 = tex2D( TexSampler, i.coordTap2 );
  47. float4 s3 = tex2D( TexSampler, i.coordTap3 );
  48. #if ( ( SRGB_INPUT_ADAPTER == 1 ) || ( FLOAT_BACK_BUFFER == 1 ) )
  49. {
  50. s0.rgb = SrgbLinearToGamma( saturate( s0.rgb ) );
  51. s1.rgb = SrgbLinearToGamma( saturate( s1.rgb ) );
  52. s2.rgb = SrgbLinearToGamma( saturate( s2.rgb ) );
  53. s3.rgb = SrgbLinearToGamma( saturate( s3.rgb ) );
  54. }
  55. #endif
  56. float4 avgColor = ( s0 + s1 + s2 + s3 ) * 0.25f;
  57. float fAvgLuminance = dot( avgColor.rgb, float3( 0.299, 0.587, 0.114 ) );
  58. avgColor = Shape( avgColor );
  59. // Saturation
  60. #if ( BLOOMTYPE == 1 )
  61. {
  62. avgColor.rgb = lerp( dot( params.rgb, avgColor.rgb ), avgColor.rgb, g_flBloomSaturation );
  63. }
  64. #endif
  65. avgColor.a = fAvgLuminance;
  66. #if ( SRGB_INPUT_ADAPTER == 1 )
  67. {
  68. avgColor.rgb = SrgbGammaToLinear( saturate( avgColor.rgb ) );
  69. }
  70. #endif
  71. return FinalOutput( avgColor, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
  72. }