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.

97 lines
2.7 KiB

  1. //===================== Copyright (c) Valve Corporation. All Rights Reserved. ======================
  2. // STATIC: "HASALPHAMASK" "0..1"
  3. // STATIC: "HASSTATICTEXTURE" "0..1"
  4. // STATIC: "PORTALGHOSTOVERLAY" "0..1"
  5. #include "common_fog_ps_fxc.h"
  6. #include "common_ps_fxc.h"
  7. #include "shader_constant_register_map.h"
  8. #if defined( _X360 )
  9. #undef SHADER_SRGB_READ
  10. #define SHADER_SRGB_READ 1
  11. #endif
  12. const float3 g_StaticAmount : register( c0 ); //x is static, y is 1.0 - static
  13. const float4 g_FogParams : register( PSREG_FOG_PARAMS );
  14. const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT );
  15. #if ( HASSTATICTEXTURE )
  16. sampler StaticTextureSampler : register( s0 );
  17. #if ( HASALPHAMASK )
  18. sampler AlphaMaskSampler : register( s1 );
  19. #endif
  20. #else
  21. #if ( HASALPHAMASK )
  22. sampler AlphaMaskSampler : register( s0 );
  23. #endif
  24. #endif
  25. struct PS_INPUT
  26. {
  27. float4 vProjPos : POSITION;
  28. float4 vVertexColor : COLOR;
  29. //vStaticTexCoord and vAlphaMaskTexCoord are the same numbers, but we need to map TEXCOORD0 to sampler 0, and TEXCOORD1 to sampler1. ps11 compatibility issue
  30. #if ( HASSTATICTEXTURE )
  31. float2 vStaticTexCoord : TEXCOORD0;
  32. #if ( HASALPHAMASK )
  33. float2 vAlphaMaskTexCoord : TEXCOORD1;
  34. #endif
  35. #else
  36. #if ( HASALPHAMASK )
  37. float2 vAlphaMaskTexCoord : TEXCOORD0;
  38. #else
  39. float2 vUnusedTexCoord1 : TEXCOORD0;
  40. #endif
  41. float2 vUnusedTexCoord2 : TEXCOORD1;
  42. #endif
  43. float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog
  44. };
  45. float4_color_return_type main( PS_INPUT i ) : COLOR
  46. {
  47. float4 result;
  48. #if ( HASSTATICTEXTURE )
  49. {
  50. result.rgba = tex2Dsrgb( StaticTextureSampler, i.vStaticTexCoord );
  51. }
  52. #else
  53. {
  54. result.rgba = 0.25; // Without a static texture, just be gray
  55. }
  56. #endif
  57. #if ( PORTALGHOSTOVERLAY )
  58. {
  59. result.rgb *= i.vVertexColor.rgb;
  60. result.rgb *= i.vVertexColor.a * g_StaticAmount.x; // Doing a one/invSrcAlpha blend so dim color here
  61. result.a *= i.vVertexColor.a;
  62. // Limit tonemap scalar to 0.0-1.0 so the colors don't oversaturate, but let it drop down to 0 to allow fading
  63. float flTonemapScalar = saturate( LINEAR_LIGHT_SCALE );
  64. return FinalOutput( result, 0.0f, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE ) * flTonemapScalar;
  65. }
  66. #else
  67. {
  68. #if ( HASALPHAMASK )
  69. {
  70. result.a = min( g_StaticAmount.x, tex2D( AlphaMaskSampler, i.vAlphaMaskTexCoord ).a ); // When static reaches 0, fades away completely, also never exceeds the mask's alpha
  71. }
  72. #else
  73. {
  74. result.a = g_StaticAmount.x; // When static reaches 0, fades away completely
  75. }
  76. #endif
  77. float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.xyz, i.worldPos_projPosZ.xyz, i.worldPos_projPosZ.w );
  78. return FinalOutput( result, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR );
  79. }
  80. #endif
  81. }