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.

69 lines
2.0 KiB

  1. //====== Copyright � 1996-2004, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. // STATIC: "NORMALMAP" "0..1"
  7. // STATIC: "NOCULL" "0..1"
  8. #include "common_ps_fxc.h"
  9. sampler SpotSampler : register( s0 );
  10. sampler BaseTextureSampler : register( s1 );
  11. sampler NormalizingCubemapSampler : register( s2 );
  12. // use a normalizing cube map here if we aren't normal mapping
  13. #if NORMALMAP
  14. sampler NormalMapSampler : register( s3 );
  15. #else
  16. sampler NormalizingCubemapSampler2 : register( s3 );
  17. #endif
  18. static const HALF g_OverbrightFactor = 2.0f;
  19. struct PS_INPUT
  20. {
  21. float4 spotTexCoord : TEXCOORD0;
  22. float2 baseTexCoord : TEXCOORD1;
  23. #if NORMALMAP
  24. float3 tangentPosToLightVector : TEXCOORD2;
  25. float2 normalMapTexCoord : TEXCOORD3;
  26. #else
  27. float3 worldPosToLightVector : TEXCOORD2;
  28. float3 normal : TEXCOORD3;
  29. #endif
  30. float4 vertAtten : COLOR0;
  31. };
  32. float4 main( PS_INPUT i ) : COLOR
  33. {
  34. #if NORMALMAP
  35. float3 normal = tex2D( NormalMapSampler, i.normalMapTexCoord ) * 2.0f - 1.0f;
  36. #else
  37. float3 normal = texCUBE( NormalizingCubemapSampler2, i.normal ) * 2.0f - 1.0f;
  38. #endif
  39. float3 spotColor = tex2D( SpotSampler, i.spotTexCoord );
  40. float4 baseSample = tex2D( BaseTextureSampler, i.baseTexCoord );
  41. float3 baseColor = baseSample.xyz;
  42. #if NORMALMAP
  43. // wrap this!
  44. float3 tangentPosToLightVector = texCUBE( NormalizingCubemapSampler, i.tangentPosToLightVector ) * 2.0f - 1.0f;
  45. float nDotL = saturate( dot( tangentPosToLightVector, normal ) );
  46. #else
  47. float3 worldPosToLightVector = texCUBE( NormalizingCubemapSampler, i.worldPosToLightVector ) * 2.0f - 1.0f;
  48. float nDotL = saturate( dot( worldPosToLightVector, normal ) );
  49. #endif
  50. float3 outcolor;
  51. outcolor = spotColor * baseColor * g_OverbrightFactor;
  52. #if !NOCULL
  53. outcolor *= nDotL;
  54. #endif
  55. // NOTE!! This has to be last to avoid loss of range.
  56. outcolor *= i.vertAtten;
  57. return float4( outcolor.xyz, baseSample.a * i.vertAtten.a );
  58. }