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.

96 lines
3.3 KiB

  1. // DYNAMIC: "PIXELFOGTYPE" "0..1"
  2. // STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC]
  3. // STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX]
  4. #include "common_ps_fxc.h"
  5. #include "shader_constant_register_map.h"
  6. const float4 g_FogParams : register( PSREG_FOG_PARAMS );
  7. const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT );
  8. sampler YTextureSampler : register( s0 );
  9. sampler cRTextureSampler : register( s1 );
  10. sampler cBTextureSampler : register( s2 );
  11. //sampler ATextureSampler : register( s3 );
  12. struct PS_INPUT
  13. {
  14. HALF2 baseTexCoord : TEXCOORD0;
  15. HALF4 worldPos_projPosZ : TEXCOORD1;
  16. float4 fogFactorW : COLOR1;
  17. };
  18. #if 0
  19. static float yuvtorgb[] =
  20. {
  21. 1.164123535f, 1.595794678f, 0.0f, -0.87065506f,
  22. 1.164123535f, -0.813476563f, -0.391448975f, 0.529705048f,
  23. 1.164123535f, 0.0f, 2.017822266f, -1.081668854f,
  24. 1.0f, 0.0f, 0.0f, 0.0f
  25. };
  26. " sampler tex0 : register( s0 ); "
  27. " sampler tex1 : register( s1 ); "
  28. " sampler tex2 : register( s2 ); "
  29. " sampler tex3 : register( s3 ); "
  30. " float4 tor : register( c0 ); "
  31. " float4 tog : register( c1 ); "
  32. " float4 tob : register( c2 ); "
  33. " float4 consts : register( c3 ); "
  34. " "
  35. " struct VS_OUT "
  36. " { "
  37. " float2 T0: TEXCOORD0; "
  38. " }; "
  39. " "
  40. " float4 main( VS_OUT In ) : COLOR "
  41. " { "
  42. " float4 c; "
  43. " float4 p; "
  44. " c.x = tex2D( tex0, In.T0 ).x; "
  45. " c.y = tex2D( tex1, In.T0 ).x; "
  46. " c.z = tex2D( tex2, In.T0 ).x; "
  47. " c.w = consts.x; "
  48. " p.w = tex2D( tex3, In.T0 ).x; "
  49. " p.x = dot( tor, c ); "
  50. " p.y = dot( tog, c ); "
  51. " p.z = dot( tob, c ); "
  52. " p.w *= consts.w; "
  53. " return p; "
  54. " } ";
  55. #endif
  56. float4 main( PS_INPUT i ) : COLOR
  57. {
  58. half y, cR, cB;
  59. y = tex2D( YTextureSampler, i.baseTexCoord.xy );
  60. cR = tex2D( cRTextureSampler, i.baseTexCoord.xy );
  61. cB = tex2D( cBTextureSampler, i.baseTexCoord.xy );
  62. // half a = tex2D( ATextureSampler, i.baseTexCoord.xy );
  63. HALF4 c;
  64. c = float4( y, cR, cB, 1.0f );
  65. float4 tor = float4( 1.164123535f, 1.595794678f, 0.0f, -0.87065506f );
  66. float4 tog = float4( 1.164123535f, -0.813476563f, -0.391448975f, 0.529705048f );
  67. float4 tob = float4( 1.164123535f, 0.0f, 2.017822266f, -1.081668854f );
  68. HALF4 rgba;
  69. rgba.r = dot( c, tor );
  70. rgba.g = dot( c, tog );
  71. rgba.b = dot( c, tob );
  72. rgba.a = 1.0f;
  73. float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w );
  74. float4 result = FinalOutput( rgba, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_NONE );
  75. // The 360 will do an sRGB write to put the linear values into 360 gamma space, but the PC just outputs gamma values directly
  76. #if defined( _X360 )
  77. result.r = SrgbGammaToLinear( result.r );
  78. result.g = SrgbGammaToLinear( result.g );
  79. result.b = SrgbGammaToLinear( result.b );
  80. #endif
  81. return result.rgba;
  82. }