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.

118 lines
3.9 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. // STATIC: "TRANSLUCENT" "0..1"
  3. // STATIC: "LIGHTING_PREVIEW" "0..3" [PC]
  4. // STATIC: "LIGHTING_PREVIEW" "0..0" [CONSOLE]
  5. // STATIC: "CROSSHAIR_MODE" "0..1"
  6. #include "common_fog_ps_fxc.h"
  7. // DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps20b] [PC]
  8. // DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..0" [ps20b] [CONSOLE]
  9. // SKIP: ( CROSSHAIR_MODE == 1 ) && ( LIGHTING_PREVIEW > 0 )
  10. #if defined( SHADER_MODEL_PS_2_0 )
  11. #define WRITE_DEPTH_TO_DESTALPHA 0
  12. #endif
  13. #include "common_ps_fxc.h"
  14. #include "shader_constant_register_map.h"
  15. const float4 g_DiffuseModulation : register( c1 );
  16. #if !FLASHLIGHT
  17. // we don't use these with HDR.
  18. const float3 g_EnvmapContrast : register( c2 );
  19. const float3 g_EnvmapSaturation : register( c3 );
  20. #endif
  21. #if CROSSHAIR_MODE == 1
  22. const float4 g_fvConstRegister4 : register( c4 );
  23. #define g_flXHairColorTint g_fvConstRegister4.xyz
  24. #define g_flXHairColorAdapt g_fvConstRegister4.w
  25. #endif
  26. const float4 g_FogParams : register( PSREG_FOG_PARAMS );
  27. const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT );
  28. const float4 g_FlashlightAttenuationFactors : register( c22 );
  29. const float3 g_FlashlightPos : register( c23 );
  30. const float4x4 g_FlashlightWorldToTexture : register( c24 ); // through c27
  31. sampler BaseTextureSampler : register( s0 );
  32. sampler BaseTextureSampler2 : register( s1 );
  33. struct PS_INPUT
  34. {
  35. float4 projPos : POSITION; // Projection-space position
  36. float2 baseTexCoord : TEXCOORD0; // Base texture coordinate
  37. float2 baseTexCoord2 : TEXCOORD1; // Base texture coordinate
  38. float4 worldPos_projPosZ : TEXCOORD7; // Necessary for water fog dest alpha
  39. #if defined( _X360 ) //matching pixel shader inputs to vertex shader outputs to avoid shader patches
  40. float4 vColor : COLOR0;
  41. #endif
  42. };
  43. #if LIGHTING_PREVIEW == 2
  44. LPREVIEW_PS_OUT main( PS_INPUT i ) : COLOR
  45. #else
  46. float4_color_return_type main( PS_INPUT i ) : COLOR
  47. #endif
  48. {
  49. #if CROSSHAIR_MODE == 1 && LIGHTING_PREVIEW == 0
  50. //crosshair mode samples the secondary texture (the power-of-two framebuffer is intended)
  51. //and lerps the result based on a multi-tap average of the luminance
  52. float flAverageLum = 0.0f;
  53. float2 offsets[5] = {
  54. float2( 0.5f, 0.5f ),
  55. float2( 0.51f, 0.51f ),
  56. float2( 0.51f, 0.49f ),
  57. float2( 0.49f, 0.51f ),
  58. float2( 0.49f, 0.49f )
  59. };
  60. for ( int k = 0; k < 5; k++ )
  61. {
  62. flAverageLum += dot( tex2D( BaseTextureSampler2, float2( 0.5f, 0.5f ) ).rgb, float3(0.299,0.587,0.114) );
  63. }
  64. flAverageLum *= 0.2f;
  65. float4 cOut = tex2D( BaseTextureSampler, i.baseTexCoord.xy );
  66. cOut.rgb = lerp( cOut.rgb + g_flXHairColorTint, cOut.rgb * g_flXHairColorTint, flAverageLum * g_flXHairColorAdapt );
  67. return FinalOutput( cOut * g_DiffuseModulation, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
  68. #else
  69. #if LIGHTING_PREVIEW == 1
  70. return FinalOutput( float4( 0.0f, 0.0f, 0.0f, 1.0f ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_LINEAR );
  71. #endif
  72. #if LIGHTING_PREVIEW == 2
  73. LPREVIEW_PS_OUT ret;
  74. ret.flags=float4(1,1,1,1);
  75. ret.color=float4( 0.0f, 0.0f, 0.0f, 1.0f );
  76. ret.normal=float4( 0.0f, 0.0f, 1.0f, 1.0f );
  77. ret.position=float4( i.worldPos_projPosZ.xyz, 1.0f );
  78. return FinalOutput( ret, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
  79. #endif
  80. #if (LIGHTING_PREVIEW == 0) || ( LIGHTING_PREVIEW == 3 )
  81. float4 baseColor = tex2D( BaseTextureSampler, i.baseTexCoord.xy );
  82. float4 baseColor2 = tex2D( BaseTextureSampler2, i.baseTexCoord2.xy );
  83. float4 result = baseColor * baseColor2 * g_DiffuseModulation;
  84. // This material can only get a non-opaque alpha if the material is marked as translucent
  85. # if ( TRANSLUCENT == 0 )
  86. result.a = 1.0f;
  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_LINEAR, (WRITE_DEPTH_TO_DESTALPHA != 0), i.worldPos_projPosZ.w );
  90. #endif
  91. #endif
  92. }