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.

110 lines
3.1 KiB

  1. //===================== Copyright (c) Valve Corporation. All Rights Reserved. ======================
  2. // STATIC: "HASALPHAMASK" "0..1"
  3. // STATIC: "HASSTATICTEXTURE" "0..1"
  4. // DYNAMIC: "ADDSTATIC" "0..1"
  5. // DYNAMIC: "D_NVIDIA_STEREO" "0..1" [ps20b] [PC]
  6. // DYNAMIC: "D_NVIDIA_STEREO" "0..0" [ps20b] [CONSOLE]
  7. #include "common_fog_ps_fxc.h"
  8. #define USESTATICTEXTURE ( ( ( ADDSTATIC == 1 ) && ( HASSTATICTEXTURE == 1 ) ) )
  9. #include "common_ps_fxc.h"
  10. #include "shader_constant_register_map.h"
  11. const float4 g_StaticAmount : register( c0 ); //x is static, y is 1.0 - static
  12. const float4 g_FogParams : register( PSREG_FOG_PARAMS );
  13. const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT );
  14. sampler PortalSampler : register( s0 );
  15. #if ( ( HASALPHAMASK == 1 ) || ( USESTATICTEXTURE ) )
  16. sampler SecondarySampler : register( s1 );
  17. #if ( ( HASALPHAMASK == 1 ) && ( USESTATICTEXTURE ) )
  18. sampler TertiarySampler : register( s2 );
  19. #endif
  20. #endif
  21. #if D_NVIDIA_STEREO
  22. sampler StereoParamSampler : register( s3 );
  23. #endif
  24. struct PS_INPUT
  25. {
  26. float3 vPortalTexCoord : TEXCOORD0;
  27. #if ( ( HASALPHAMASK == 1 ) || ( USESTATICTEXTURE ) )
  28. float2 vSecondaryTexCoord : TEXCOORD1;
  29. #if ( ( HASALPHAMASK == 1 ) && ( USESTATICTEXTURE ) )
  30. float2 vTertiaryTexCoord : TEXCOORD2;
  31. #endif
  32. #endif
  33. float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog
  34. };
  35. // NVIDIA's function to convert mono refract UV to the correct stereo UV for each eye
  36. float2 MonoTostereoClipPosXY( float3 vMonoClipPos ) // .z is actually .w
  37. {
  38. #if ( !D_NVIDIA_STEREO )
  39. {
  40. return vMonoClipPos.xy;
  41. }
  42. #else
  43. {
  44. // 0th pixel = 1/16 == 1/16 + 1/8 * 0
  45. float flEyeSep = tex2D( StereoParamSampler, float2( 0.0625f, 0 ) ).x; // 0.19 * 0.1316;
  46. // 1st pixel = 3/16 == 1/16 + 1/8 * 1
  47. float flConvergence = tex2D( StereoParamSampler, float2( 0.1875, 0 ) ).x; // 4;
  48. float3 vStereoClipPos = vMonoClipPos.xyz;
  49. // Undo the stereo transform
  50. vStereoClipPos.x += flEyeSep * ( vMonoClipPos.z - flConvergence );
  51. return vStereoClipPos.xy;
  52. }
  53. #endif
  54. }
  55. float4_color_return_type main( PS_INPUT i ) : COLOR
  56. {
  57. float4 result;
  58. result.rgb = tex2D( PortalSampler, MonoTostereoClipPosXY( i.vPortalTexCoord.xyz ) / i.vPortalTexCoord.z ).rgb;
  59. //mix in static
  60. #if ( ADDSTATIC == 1 )
  61. {
  62. result.rgb *= g_StaticAmount.y; //inverse static on original colors
  63. #if ( HASSTATICTEXTURE == 1 )
  64. {
  65. #if ( HASALPHAMASK == 1 )
  66. result.rgb += tex2D( TertiarySampler, i.vTertiaryTexCoord ).rgb * g_StaticAmount.x; //static
  67. #else
  68. result.rgb += tex2D( SecondarySampler, i.vSecondaryTexCoord ).rgb * g_StaticAmount.x; //static
  69. #endif
  70. }
  71. #else
  72. {
  73. result.rgb += g_StaticAmount.x * 0.25; //mix in gray
  74. }
  75. #endif
  76. }
  77. #endif
  78. #if ( HASALPHAMASK == 1 )
  79. {
  80. //alpha mask
  81. result.a = tex2D( SecondarySampler, i.vSecondaryTexCoord ).a;
  82. }
  83. #else
  84. {
  85. result.a = 1;
  86. }
  87. #endif
  88. float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.xyz, i.worldPos_projPosZ.xyz, i.worldPos_projPosZ.w );
  89. return FinalOutput( result, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_NONE );
  90. }