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.

179 lines
5.6 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. // STATIC: "LIGHTING_PREVIEW" "0..1" [PC]
  3. // STATIC: "LIGHTING_PREVIEW" "0..0" [XBOX]
  4. #include "shader_constant_register_map.h"
  5. #include "common_fog_ps_fxc.h"
  6. sampler BaseSampler1 : register( s1 ); // Base map 1
  7. sampler BaseSampler2 : register( s2 ); // Base map 2
  8. sampler BaseSampler3 : register( s3 ); // Base map 3
  9. sampler BaseSampler4 : register( s4 ); // Base map 4
  10. sampler LightmapSampler : register( s5 );
  11. const float4 g_FogParams : register( PSREG_FOG_PARAMS );
  12. const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT );
  13. #if ((defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0)))
  14. static const float3 cSpecularColor = float3( 1.0, 1.0, 1.0 );
  15. #endif
  16. #if LIGHTING_PREVIEW == 0
  17. static const float3 g_cAmbientColor = float3( 0.0, 0.0, 0.0 );
  18. const float4 g_TintValuesTimesLightmapScale : register( PSREG_CONSTANT_02 );
  19. #endif
  20. struct PS_INPUT
  21. {
  22. float4 vBaseTexCoord : TEXCOORD0; // xy = blend 1 coord, zw = lightmap cord
  23. float4 worldPos_projPosZ : TEXCOORD1;
  24. // float3 vWorldNormal : TEXCOORD2;
  25. float flSpecPower : TEXCOORD2;
  26. float4 vFowCoord : TEXCOORD3; // xy = fow, zw = blend4 coord
  27. float4 vAlphaBlend : TEXCOORD4;
  28. // float3 worldVertToEyeVector : TEXCOORD5;
  29. float4 vBlendCoords23 : TEXCOORD5; // xy = blend2 coord, zw = blend3 coord
  30. float4 vColorBlend1 : COLOR0;
  31. float4 vColorBlend2 : COLOR1;
  32. float4 vColorBlend3 : TEXCOORD6;
  33. float4 vColorBlend4 : TEXCOORD7;
  34. };
  35. #if ( defined( SHADER_MODEL_PS_2_0 ) )
  36. float ComputeMultiBlendFactor( const float BlendEnd, const float BlendAmount, inout float Remaining )
  37. {
  38. float Result = 0.0;
  39. Result = smoothstep( 0.0, BlendEnd, BlendAmount );
  40. Result = clamp( Result, 0.0, Remaining );
  41. Remaining -= Result;
  42. return Result;
  43. }
  44. #else
  45. sampler SpecSampler1 : register( s6 ); // Spec map 1
  46. sampler SpecSampler2 : register( s7 ); // Spec map 2
  47. sampler SpecSampler3 : register( s8 ); // Spec map 3
  48. sampler SpecSampler4 : register( s9 ); // Spec map 4
  49. float ComputeMultiBlendFactor( const float BlendStart, const float BlendEnd, const float BlendAmount, const float AlphaBlend, inout float Remaining )
  50. {
  51. float Result = 0.0;
  52. if ( Remaining > 0.0 && BlendAmount > 0.0 )
  53. {
  54. float minb = max( 0.0, BlendEnd - BlendStart );
  55. float maxb = min( 1.0, BlendEnd + BlendStart );
  56. if ( minb != maxb )
  57. {
  58. Result = smoothstep( minb, maxb, BlendAmount );
  59. }
  60. else if ( BlendAmount >= minb )
  61. {
  62. Result = 1.0;
  63. }
  64. if ( BlendEnd < AlphaBlend )
  65. {
  66. float alpha = 2.0 - AlphaBlend - BlendEnd;
  67. Result *= clamp( alpha, 0.0, 1.0 );
  68. }
  69. }
  70. Result = clamp( Result, 0.0, Remaining );
  71. Remaining -= Result;
  72. return Result;
  73. }
  74. #endif
  75. float4 main( PS_INPUT i ) : COLOR
  76. {
  77. float blendfactor1 = 0.0;
  78. float blendfactor2 = 0.0;
  79. float blendfactor3 = 0.0;
  80. float blendfactor4 = 0.0;
  81. float remaining = 1.0;
  82. float4 color1 = tex2D( BaseSampler1, i.vBaseTexCoord.xy ) * float4( i.vColorBlend1.rgb, 1.0 );
  83. float4 color2 = tex2D( BaseSampler2, i.vBlendCoords23.xy ) * float4( i.vColorBlend2.rgb, 1.0 );
  84. float4 color3 = tex2D( BaseSampler3, i.vBlendCoords23.zw ) * float4( i.vColorBlend3.rgb, 1.0 );
  85. float4 color4 = tex2D( BaseSampler4, i.vFowCoord.zw ) * float4( i.vColorBlend4.rgb, 1.0 );
  86. #if ( defined( SHADER_MODEL_PS_2_0 ) )
  87. blendfactor1 = ComputeMultiBlendFactor( color1.a, i.vColorBlend1.a, remaining );
  88. blendfactor2 = ComputeMultiBlendFactor( color2.a, i.vColorBlend2.a, remaining );
  89. blendfactor3 = ComputeMultiBlendFactor( color3.a, i.vColorBlend3.a, remaining );
  90. // blendfactor4 = ComputeMultiBlendFactor( color4.a, i.vColorBlend4.a, remaining );
  91. blendfactor4 = remaining;
  92. #else
  93. float4 spec1 = tex2D( SpecSampler1, i.vBaseTexCoord.xy );
  94. float4 spec2 = tex2D( SpecSampler2, i.vBlendCoords23.xy );
  95. float4 spec3 = tex2D( SpecSampler3, i.vBlendCoords23.zw );
  96. float4 spec4 = tex2D( SpecSampler4, i.vFowCoord.zw );
  97. blendfactor1 = ComputeMultiBlendFactor( spec1.a, color1.a, i.vColorBlend1.a, i.vAlphaBlend.r, remaining );
  98. blendfactor2 = ComputeMultiBlendFactor( spec2.a, color2.a, i.vColorBlend2.a, i.vAlphaBlend.g, remaining );
  99. blendfactor3 = ComputeMultiBlendFactor( spec3.a, color3.a, i.vColorBlend3.a, i.vAlphaBlend.b, remaining );
  100. // blendfactor4 = ComputeMultiBlendFactor( spec4.a, color4.a, i.vColorBlend4.a, i.vAlphaBlend.a, remaining );
  101. blendfactor4 = remaining;
  102. #endif
  103. float3 vResult = ( color1.rgb * blendfactor1 ) + ( color2.rgb * blendfactor2 ) + ( color3.rgb * blendfactor3 ) + ( color4.rgb * blendfactor4 );
  104. #if ( ( defined( SHADER_MODEL_PS_2_B ) || defined( SHADER_MODEL_PS_3_0 ) ) )
  105. float3 fSpecular = i.flSpecPower * cSpecularColor;
  106. float3 fSpecFinal = float3( 0.0, 0.0, 0.0 );
  107. if ( blendfactor1 > 0.0 )
  108. {
  109. fSpecFinal += spec1.rgb * i.vColorBlend1.rgb * blendfactor1;
  110. }
  111. if ( blendfactor2 > 0.0 )
  112. {
  113. fSpecFinal += spec2.rgb * i.vColorBlend2.rgb * blendfactor2;
  114. }
  115. if ( blendfactor3 > 0.0 )
  116. {
  117. fSpecFinal += spec3.rgb * i.vColorBlend3.rgb * blendfactor3;
  118. }
  119. if ( blendfactor4 > 0.0 )
  120. {
  121. fSpecFinal += spec4.rgb * i.vColorBlend4.rgb * blendfactor4;
  122. }
  123. vResult.rgb += fSpecFinal * fSpecular;
  124. #endif
  125. #if LIGHTING_PREVIEW == 0
  126. float3 lightmapColor = tex2D( LightmapSampler, i.vBaseTexCoord.zw );
  127. float3 diffuseLighting = lightmapColor * g_TintValuesTimesLightmapScale.rgb;
  128. diffuseLighting += g_cAmbientColor;
  129. vResult.rgb *= diffuseLighting;
  130. #endif
  131. float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.xyz, i.worldPos_projPosZ.xyz, i.worldPos_projPosZ.w );
  132. return FinalOutput( float4( vResult, fogFactor ), fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR );
  133. }