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.

61 lines
1.7 KiB

  1. // STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC]
  2. // STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX]
  3. // STATIC: "VERTEXCOLOR" "0..1"
  4. // STATIC: "CONSTANTCOLOR" "0..1"
  5. // STATIC: "HDRTYPE" "0..2"
  6. // STATIC: "SRGB" "0..1"
  7. // STATIC: "SRGB_OUTPUT_ADAPTER" "0..1" [ps20b]
  8. // DYNAMIC: "HDRENABLED" "0..1"
  9. // DYNAMIC: "PIXELFOGTYPE" "0..1"
  10. #include "common_ps_fxc.h"
  11. #include "shader_constant_register_map.h"
  12. const HALF4 g_Color : register( c0 );
  13. const float g_HDRColorScale : register( c1 );
  14. const float4 g_FogParams : register( PSREG_FOG_PARAMS );
  15. const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT );
  16. sampler TexSampler : register( s0 );
  17. struct PS_INPUT
  18. {
  19. HALF2 baseTexCoord : TEXCOORD0; // Base texture coordinate
  20. float4 color : TEXCOORD2; // Vertex color (from lighting or unlit)
  21. float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog
  22. };
  23. float4 main( PS_INPUT i ) : COLOR
  24. {
  25. float4 result, sample = tex2D( TexSampler, i.baseTexCoord );
  26. #if VERTEXCOLOR
  27. sample *= i.color;
  28. #endif
  29. #if CONSTANTCOLOR
  30. sample *= g_Color;
  31. #endif
  32. #if HDRTYPE && HDRENABLED
  33. sample.xyz *= g_HDRColorScale;
  34. #endif
  35. float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w );
  36. #if SRGB
  37. result = FinalOutput( sample, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR );
  38. #else
  39. result = FinalOutput( sample, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_GAMMA );
  40. #endif
  41. // On Posix, we're being forced through a linear-to-gamma curve but don't want it, so we do the opposite here first
  42. #if SRGB_OUTPUT_ADAPTER
  43. result = GammaToLinear( result );
  44. #endif
  45. return result;
  46. }