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.

59 lines
1.5 KiB

  1. //======= Copyright � 1996-2006, Valve Corporation, All rights reserved. ======
  2. // STATIC: "CONSTANTBASEDMORPH" "0..1"
  3. #define HDRTYPE HDR_TYPE_NONE
  4. #include "common_ps_fxc.h"
  5. struct PS_INPUT
  6. {
  7. float2 vSrcCoord : TEXCOORD0;
  8. float2 vSideSpeedCoord : TEXCOORD1;
  9. #if CONSTANTBASEDMORPH
  10. float4 vMorphWeights : TEXCOORD2;
  11. #else
  12. float2 vMorphWeightCoord : TEXCOORD2;
  13. #endif
  14. };
  15. sampler MorphTarget : register( s0 );
  16. sampler SideSpeedMap : register( s1 );
  17. #if !CONSTANTBASEDMORPH
  18. sampler MorphWeights : register( s2 );
  19. #endif
  20. const float4 vMorphScale : register( c0 );
  21. HALF4 main( PS_INPUT i ) : COLOR
  22. {
  23. #if CONSTANTBASEDMORPH
  24. float4 vMorphWeights = i.vMorphWeights;
  25. #else
  26. float4 vMorphWeights = tex2D( MorphWeights, i.vMorphWeightCoord );
  27. #endif
  28. float4 delta = tex2D( MorphTarget, i.vSrcCoord );
  29. float4 sideSpeed = tex2D( SideSpeedMap, i.vSideSpeedCoord );
  30. // NOTE: This is necessary to fixup slight errors in the delta.
  31. // On the cpu, only the range 0-65534 is used so we can encode -1, 0, and 1 exactly.
  32. delta *= 65535.0f / 65534.0f;
  33. // Compute total weight, taking into account side + speed
  34. float flWeight = lerp( vMorphWeights.y, vMorphWeights.x, sideSpeed.y );
  35. float flStereoWeight = lerp( vMorphWeights.w, vMorphWeights.z, sideSpeed.y );
  36. float w = lerp( flWeight, flStereoWeight, sideSpeed.x );
  37. // Convert 0-1 -> -1 to 1
  38. delta *= 2.0f;
  39. delta -= float4( 1.0f, 1.0f, 1.0f, 1.0f );
  40. // Apply the morph scale
  41. delta *= vMorphScale;
  42. // Apply weight
  43. delta *= w;
  44. return delta;
  45. }