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
3.7 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. #include "common_fog_ps_fxc.h"
  3. // DYNAMIC: "NUM_LIGHTS" "0..2" [ps20]
  4. // DYNAMIC: "NUM_LIGHTS" "0..4" [ps20b]
  5. // DYNAMIC: "NUM_LIGHTS" "0..4" [ps30]
  6. // DYNAMIC: "AMBIENT_LIGHT" "0..1"
  7. // DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps20b] [PC]
  8. // DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..0" [ps20b] [CONSOLE]
  9. // DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps30]
  10. #if defined( SHADER_MODEL_PS_2_0 )
  11. # define WRITE_DEPTH_TO_DESTALPHA 0
  12. #endif
  13. #include "shader_constant_register_map.h"
  14. const float3 cAmbientCube[6] : register( PSREG_AMBIENT_CUBE );
  15. const float4 g_FogParams : register( PSREG_FOG_PARAMS );
  16. const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT );
  17. PixelShaderLightInfo cLightInfo[3] : register( PSREG_LIGHT_INFO_ARRAY ); // 2 registers each - 6 registers total
  18. sampler BaseTextureSampler : register( s0 );
  19. sampler BumpTextureSampler : register( s1 );
  20. samplerCUBE NormalizeSampler : register( s2 );
  21. struct PS_INPUT
  22. {
  23. float2 baseTexCoord : TEXCOORD0;
  24. float4 worldVertToEyeVector_Darkening : TEXCOORD1;
  25. float3x3 tangentSpaceTranspose : TEXCOORD2;
  26. // second row : TEXCOORD3;
  27. // third row : TEXCOORD4;
  28. float4 worldPos_projPosZ : TEXCOORD5;
  29. float4 lightAtten0123 : TEXCOORD6;
  30. };
  31. #if ((defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0)))
  32. #define worldVertToEyeVector i.worldVertToEyeVector_Darkening.xyz
  33. #define fDarkening i.worldVertToEyeVector_Darkening.w
  34. #endif
  35. float4_color_return_type main( PS_INPUT i ) : COLOR
  36. {
  37. bool bAmbientLight = AMBIENT_LIGHT ? true : false;
  38. int nNumLights = NUM_LIGHTS;
  39. float4 vLightAtten = i.lightAtten0123;
  40. float4 baseSample = tex2D( BaseTextureSampler, i.baseTexCoord );
  41. float3 worldSpaceNormal, tangentSpaceNormal = float3(0, 0, 1);
  42. float fSpecExp = g_EyePos_SpecExponent.w;
  43. float4 normalTexel = tex2D( BumpTextureSampler, i.baseTexCoord );
  44. tangentSpaceNormal = 2.0f * normalTexel.xyz - 1.0f;
  45. worldSpaceNormal = normalize( mul( i.tangentSpaceTranspose, tangentSpaceNormal ) );
  46. // If the exponent passed in as a constant is zero, use the value from the map as the exponent
  47. if ( fSpecExp == 0 )
  48. fSpecExp = 1.0f * ( 1.0f - normalTexel.w ) + 150.0f * normalTexel.w;
  49. // Summation of diffuse illumination from all local lights
  50. float3 diffuseLighting = PixelShaderDoLighting( i.worldPos_projPosZ.xyz, worldSpaceNormal,
  51. float3( 0.0f, 0.0f, 0.0f ), false,
  52. bAmbientLight, vLightAtten,
  53. cAmbientCube, NormalizeSampler, nNumLights, cLightInfo, true,
  54. false, BaseTextureSampler ); // this last sampler is unused, we just need to pass in a value
  55. #if ((defined(SHADER_MODEL_PS_2_B) || defined(SHADER_MODEL_PS_3_0)))
  56. float3 vDummy, specularLighting;
  57. // Summation of specular from all local lights
  58. PixelShaderDoSpecularLighting( i.worldPos_projPosZ.xyz, worldSpaceNormal, fSpecExp, normalize(worldVertToEyeVector),
  59. vLightAtten, nNumLights, cLightInfo,
  60. false, BaseTextureSampler, // this sampler is not used, we just need to pass a value in
  61. 1.0f, false, 1.0f, 1.0f,
  62. // Outputs
  63. specularLighting, vDummy );
  64. // Specular plus diffuse, all darkened as a function of mouth openness
  65. float3 result = (specularLighting * baseSample.a + baseSample.rgb * diffuseLighting) * fDarkening;
  66. #else
  67. float3 result = baseSample.rgb * diffuseLighting * i.worldVertToEyeVector_Darkening.w;
  68. #endif
  69. float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.xyz, i.worldPos_projPosZ.xyz, i.worldPos_projPosZ.w );
  70. return FinalOutput( float4(result, 1.0f), fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR, (WRITE_DEPTH_TO_DESTALPHA != 0), i.worldPos_projPosZ.w );
  71. }