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.

68 lines
2.4 KiB

  1. //======= Copyright � 1996-2006, Valve Corporation, All rights reserved. ======
  2. // STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC]
  3. // STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX]
  4. // STATIC: "DIFFUSELIGHTING" "0..1"
  5. // STATIC: "HALFLAMBERT" "0..1"
  6. // DYNAMIC: "AMBIENT_LIGHT" "0..1"
  7. // DYNAMIC: "NUM_LIGHTS" "0..2" [ps20]
  8. // DYNAMIC: "NUM_LIGHTS" "0..4" [ps20b]
  9. #define HDRTYPE HDR_TYPE_NONE
  10. #include "common_vertexlitgeneric_dx9.h"
  11. const float4 g_OverbrightFactor : register( c4 );
  12. const float3 cAmbientCube[6] : register( c6 );
  13. PixelShaderLightInfo cLightInfo[3] : register(c13);
  14. sampler BumpmapSampler : register( s0 );
  15. sampler NormalizeSampler : register( s1 );
  16. struct PS_INPUT
  17. {
  18. float2 baseTexCoord : TEXCOORD0;
  19. // detail textures and bumpmaps are mutually exclusive so that we have enough texcoords.
  20. float2 detailOrBumpTexCoord : TEXCOORD1;
  21. // bump mapping and a separate envmap mask texture are mutually exclusive.
  22. float2 envmapMaskTexCoord : TEXCOORD2;
  23. float3 worldVertToEyeVector : TEXCOORD3;
  24. float3x3 tangentSpaceTranspose : TEXCOORD4;
  25. float4 worldPos_projPosZ : TEXCOORD5;
  26. float2 lightAtten01 : TEXCOORD6;
  27. float2 lightAtten23 : TEXCOORD7;
  28. };
  29. float4 main( PS_INPUT i ) : COLOR
  30. {
  31. bool bDiffuseLighting = DIFFUSELIGHTING ? true : false;
  32. bool bHalfLambert = HALFLAMBERT ? true : false;
  33. bool bAmbientLight = AMBIENT_LIGHT ? true : false;
  34. int nNumLights = NUM_LIGHTS;
  35. float4 vLightAtten = float4( i.lightAtten01, i.lightAtten23 );
  36. float3 tangentSpaceNormal = float3( 0.0f, 0.0f, 1.0f );
  37. float4 normalTexel = 1.0f;
  38. float4 baseColor = float4( 1.0f, 1.0f, 1.0f, 1.0f );
  39. normalTexel = tex2D( BumpmapSampler, i.detailOrBumpTexCoord );
  40. tangentSpaceNormal = 2.0f * normalTexel - 1.0f;
  41. float3 diffuseLighting = float3( 1.0f, 1.0f, 1.0f );
  42. if( bDiffuseLighting )
  43. {
  44. float3 worldSpaceNormal = mul( i.tangentSpaceTranspose, tangentSpaceNormal );
  45. float3 staticLightingColor = float3( 0.0f, 0.0f, 0.0f );
  46. diffuseLighting = PixelShaderDoLighting( i.worldPos_projPosZ.xyz, worldSpaceNormal,
  47. float3( 0.0f, 0.0f, 0.0f ), false, bAmbientLight,
  48. vLightAtten, cAmbientCube, NormalizeSampler, nNumLights, cLightInfo, bHalfLambert,
  49. false, 0, false, NormalizeSampler );
  50. // multiply by .5 since we want a 50% (in gamma space) reflective surface)
  51. diffuseLighting *= pow( 0.5f, 2.2f );
  52. }
  53. return FinalOutput( float4( diffuseLighting, 1.0f ), 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_NONE );
  54. }