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.

66 lines
2.8 KiB

  1. //====== Copyright � 1996-2004, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. // STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC]
  7. // STATIC: "CONVERT_TO_SRGB" "0..1" [ps30][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC]
  8. // STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX]
  9. // STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..2" [ps20b] [PC]
  10. // STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..2" [ps30] [PC]
  11. // STATIC: "FLASHLIGHTDEPTHFILTERMODE" "0..0" [ps20b] [XBOX]
  12. // DYNAMIC: "PIXELFOGTYPE" "0..1"
  13. // DYNAMIC: "FLASHLIGHTSHADOWS" "0..1" [ps20b]
  14. // DYNAMIC: "FLASHLIGHTSHADOWS" "0..1" [ps30]
  15. #include "common_flashlight_fxc.h"
  16. #include "shader_constant_register_map.h"
  17. sampler BaseTextureSampler : register( s0 );
  18. sampler SpotSampler : register( s1 );
  19. sampler FlashlightDepthSampler : register( s2 );
  20. sampler RandomRotationSampler : register( s3 );
  21. const float4 g_FogParams : register( PSREG_FOG_PARAMS );
  22. const float3 g_EyePos : register( PSREG_EYEPOS_SPEC_EXPONENT );
  23. const float3 g_FlashlightPos : register( PSREG_FLASHLIGHT_POSITION_RIM_BOOST );
  24. const float4 g_FlashlightAtten : register( PSREG_FLASHLIGHT_ATTENUATION );
  25. const float4x4 g_FlashlightWorldToTexture : register( PSREG_FLASHLIGHT_TO_WORLD_TEXTURE );
  26. const float4 g_ShadowTweaks : register( PSREG_ENVMAP_TINT__SHADOW_TWEAKS );
  27. struct PS_INPUT
  28. {
  29. float2 baseTexCoord : TEXCOORD0; // Base texture coordinates
  30. float4 spotTexCoord : TEXCOORD1; // Spotlight texture coordinates
  31. float3 vertAtten : TEXCOORD2; // Distance/spot attenuation
  32. float4 projPos : TEXCOORD3; // Projective space position
  33. float3 worldPos : TEXCOORD4; // Necessary for pixel fog
  34. };
  35. float4 main( PS_INPUT i ) : COLOR
  36. {
  37. #if defined( SHADER_MODEL_PS_2_0 )
  38. float3 result = tex2Dproj( SpotSampler, i.spotTexCoord.xyzw );
  39. #else
  40. float3 vProjCoords = i.spotTexCoord.xyz / i.spotTexCoord.w;
  41. float3 result = tex2D( SpotSampler, vProjCoords );
  42. #endif
  43. result *= cFlashlightColor.rgb;
  44. #if FLASHLIGHTSHADOWS && ( defined( SHADER_MODEL_PS_2_B ) || defined( SHADER_MODEL_PS_3_0 ) )
  45. result *= DoFlashlightShadow( FlashlightDepthSampler, RandomRotationSampler, vProjCoords, i.projPos.xy / i.projPos.z, FLASHLIGHTDEPTHFILTERMODE, g_ShadowTweaks, true );
  46. #endif
  47. result *= 0.35f; // Without this, unshadowed teeth always seem to glow
  48. result *= i.vertAtten; // Distance atten, NdotL and forward vector
  49. float4 baseSample = tex2D( BaseTextureSampler, i.baseTexCoord );
  50. result *= baseSample.rgb; // Multiply by base map and diffuse
  51. float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos.z, i.worldPos.z, i.projPos.z );
  52. return FinalOutput( float4( result, baseSample.a ), fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR );
  53. }