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.

111 lines
3.6 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. // STATIC: "VERTEXALPHA" "0..1"
  3. #include "common_fog_ps_fxc.h"
  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. float2 baseTexCoord : TEXCOORD0;
  15. float4 worldPos_projPosZ : TEXCOORD1;
  16. float flAlpha : TEXCOORD2;
  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 ).x;
  60. cR = tex2D( cRTextureSampler, i.baseTexCoord.xy ).x;
  61. cB = tex2D( cBTextureSampler, i.baseTexCoord.xy ).x;
  62. // half a = tex2D( ATextureSampler, i.baseTexCoord.xy );
  63. #if defined( _X360 )
  64. {
  65. // Reduce the black level of videos on X360 - this is a workaround for our highly tweaked gamma ramp, which was optimized for 3D content and non-PWL textures.
  66. y = saturate( y - 6.0f / 255.0f );
  67. }
  68. #endif
  69. float4 c;
  70. c = float4( y, cR, cB, 1.0f );
  71. float4 tor = float4( 1.164123535f, 1.595794678f, 0.0f, -0.87065506f );
  72. float4 tog = float4( 1.164123535f, -0.813476563f, -0.391448975f, 0.529705048f );
  73. float4 tob = float4( 1.164123535f, 0.0f, 2.017822266f, -1.081668854f );
  74. float4 rgba;
  75. rgba.r = dot( c, tor );
  76. rgba.g = dot( c, tog );
  77. rgba.b = dot( c, tob );
  78. #if ( VERTEXALPHA )
  79. {
  80. rgba.a = i.flAlpha;
  81. }
  82. #else
  83. {
  84. rgba.a = 1.0f;
  85. }
  86. #endif
  87. float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.xyz, i.worldPos_projPosZ.xyz, i.worldPos_projPosZ.w );
  88. float4 result = FinalOutput( rgba, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_NONE );
  89. // The 360 will do an sRGB write to put the linear values into 360 gamma space, but the PC just outputs gamma values directly
  90. // Commenting this out because we're not using PWL textures on X360 for Portal2. Also see the disabled sRGB write in bik_dx9.cpp.
  91. // #if defined( _X360 )
  92. // result.rgb = SrgbGammaToLinear( result.rgb );
  93. // #endif
  94. return result.rgba;
  95. }