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.

52 lines
2.0 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. #include "common_fog_ps_fxc.h"
  3. // DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps20b] [PC]
  4. // DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..0" [ps20b] [XBOX]
  5. #if defined( SHADER_MODEL_PS_2_0 )
  6. # define WRITE_DEPTH_TO_DESTALPHA 0
  7. #endif
  8. #include "common_ps_fxc.h"
  9. #include "shader_constant_register_map.h"
  10. sampler NormalSampler : register( s0 );
  11. sampler BaseTextureSampler : register( s1 );
  12. const float4 g_FogParams : register( PSREG_FOG_PARAMS );
  13. const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT );
  14. struct PS_INPUT
  15. {
  16. float2 vTexCoord0 : TEXCOORD0;
  17. float2 vTexCoord1 : TEXCOORD1;
  18. float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog
  19. float4 directionalLightColor : COLOR0;
  20. };
  21. float4 main( PS_INPUT i ) : COLOR
  22. {
  23. float3 vNormalMapDir = tex2D( NormalSampler, i.vTexCoord0 ); // Get the 3-vector from the normal map
  24. float4 textureColor = tex2D( BaseTextureSampler, i.vTexCoord1 ); // Interpret tcoord t1 as color data.
  25. //Expand compacted vectors
  26. //TODO: find if there's a better way to expand a color normal to a full vector ( _bx2 was used in the assembly code )
  27. vNormalMapDir = (vNormalMapDir - 0.5) * 2.0;
  28. float3 vLightDir = float3( 0.0f, 0.0f, 1.0f );
  29. float lightDirDotNormalMap = dot( vNormalMapDir, vLightDir ); //normalMap dot dirLightDir
  30. // do half-lambert on the dot
  31. lightDirDotNormalMap = lightDirDotNormalMap * 0.5 + 0.5;
  32. lightDirDotNormalMap = lightDirDotNormalMap * lightDirDotNormalMap;
  33. float4 resultColor;
  34. resultColor.xyz = lightDirDotNormalMap * ( textureColor.rgb * i.directionalLightColor.rgb );
  35. resultColor.a = textureColor.a * i.directionalLightColor.a;
  36. float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.xyz, i.worldPos_projPosZ.xyz, i.worldPos_projPosZ.w );
  37. return FinalOutput( resultColor, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR, (WRITE_DEPTH_TO_DESTALPHA != 0), i.worldPos_projPosZ.w );
  38. }