Team Fortress 2 Source Code as on 22/4/2020
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.

67 lines
2.2 KiB

  1. // DYNAMIC: "PIXELFOGTYPE" "0..1"
  2. // STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC]
  3. // STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX]
  4. // STATIC: "DEPTHBLEND" "0..1" [ps20b]
  5. #include "shader_constant_register_map.h"
  6. const float4 g_FogParams : register( PSREG_FOG_PARAMS );
  7. const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT );
  8. const float4 g_DepthFeatheringConstants : register( c0 );
  9. sampler BumpmapSampler : register( s0 );
  10. sampler DepthSampler : register( s1 );
  11. struct PS_INPUT
  12. {
  13. float2 vBumpTexCoord : TEXCOORD0;
  14. float3 vTangentSpaceLightDir : TEXCOORD1;
  15. float3 vAmbientColor : TEXCOORD2;
  16. #if defined( _X360 )
  17. float4 vScreenPos_ReverseZ : TEXCOORD3;
  18. #else
  19. float4 vScreenPos : TEXCOORD3;
  20. #endif
  21. float4 vDirLightScale : COLOR0;
  22. float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog
  23. };
  24. float4 main( PS_INPUT i ) : COLOR
  25. {
  26. float4 baseColor = tex2D( BumpmapSampler, i.vBumpTexCoord );
  27. // Dot the bump normal and the light vector.
  28. float4 vBumpMapNormal = (baseColor - 0.5); // The format of the sphere map is 0 to 1,
  29. // so this is now -0.5 to 0.5.
  30. float3 vTangentSpaceLightDir = (i.vTangentSpaceLightDir - 0.5) * 2; // This is -1 to 1
  31. float4 vOutput = dot( vBumpMapNormal, vTangentSpaceLightDir ) + 0.5;
  32. // Scale by the light color outputted by the vertex shader (ie: based on distance).
  33. vOutput *= i.vDirLightScale;
  34. // Add ambient.
  35. vOutput += float4( i.vAmbientColor.x, i.vAmbientColor.y, i.vAmbientColor.z, 0 );
  36. // Alpha = normal map alpha * vertex alpha
  37. vOutput.a = baseColor.a * i.vDirLightScale.a;
  38. //Soft Particles FTW
  39. # if (DEPTHBLEND == 1)
  40. # if defined( _X360 )
  41. vOutput.a *= DepthFeathering( DepthSampler, i.vScreenPos_ReverseZ.xy / i.vScreenPos_ReverseZ.w, i.vScreenPos_ReverseZ.z, i.vScreenPos_ReverseZ.w, g_DepthFeatheringConstants );
  42. # else
  43. vOutput.a *= DepthFeathering( DepthSampler, i.vScreenPos.xy / i.vScreenPos.w, i.vScreenPos.z, i.vScreenPos.w, g_DepthFeatheringConstants );
  44. # endif
  45. # endif
  46. float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.z, i.worldPos_projPosZ.z, i.worldPos_projPosZ.w );
  47. return FinalOutput( vOutput, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR );
  48. }