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.

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