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.

121 lines
3.3 KiB

  1. // STATIC: "MAXTEXTURESTAGES" "0..2"
  2. // STATIC: "HASALPHAMASK" "0..1"
  3. // STATIC: "HASSTATICTEXTURE" "0..1"
  4. // DYNAMIC: "ADDSTATIC" "0..1"
  5. // DYNAMIC: "PIXELFOGTYPE" "0..1"
  6. // When max texture stages is less than 2, we go into multipass mode, but without a static texture, we consolidate back to a single pass by using gray as static
  7. // SKIP: ($MAXTEXTURESTAGES < 2) && ($HASSTATICTEXTURE == 0) && ($ADDSTATIC == 1)
  8. #define TEXTURESTAGES (MAXTEXTURESTAGES + 1)
  9. #define USESTATICTEXTURE (((ADDSTATIC == 1) && (HASSTATICTEXTURE == 1))?(1):(0))
  10. #include "common_ps_fxc.h"
  11. const HALF3 g_StaticAmount : register( c0 ); //x is static, y is 1.0 - static
  12. sampler PrimarySampler : register( s0 );
  13. #if( TEXTURESTAGES == 3 )
  14. # if( (HASALPHAMASK == 1) || (USESTATICTEXTURE == 1) )
  15. sampler SecondarySampler : register( s1 );
  16. # if( (HASALPHAMASK == 1) && (USESTATICTEXTURE == 1) )
  17. sampler TertiarySampler : register( s2 );
  18. # endif
  19. # endif
  20. #elif( (TEXTURESTAGES > 1) && (HASALPHAMASK == 1) )
  21. sampler SecondarySampler : register( s1 );
  22. #endif
  23. struct PS_INPUT
  24. {
  25. float3 vPrimaryTexCoord : TEXCOORD0;
  26. # if( TEXTURESTAGES == 3 )
  27. # if( (HASALPHAMASK == 1) || (USESTATICTEXTURE == 1) )
  28. float2 vSecondaryTexCoord : TEXCOORD1;
  29. # if( (HASALPHAMASK == 1) && (USESTATICTEXTURE == 1) )
  30. float2 vTertiaryTexCoord : TEXCOORD2;
  31. # endif
  32. # endif
  33. # elif( TEXTURESTAGES > 1 && HASALPHAMASK == 1 )
  34. float2 vSecondaryTexCoord : TEXCOORD1;
  35. # endif
  36. };
  37. HALF4 main( PS_INPUT i ) : COLOR
  38. {
  39. HALF4 result;
  40. # if( TEXTURESTAGES == 3 ) //we can do everything in one pass
  41. {
  42. result.rgb = tex2D(PrimarySampler, i.vPrimaryTexCoord.xy ).rgb;
  43. //mix in static
  44. # if( ADDSTATIC == 1 )
  45. {
  46. result.rgb *= g_StaticAmount.y; //inverse static on original colors
  47. # if( HASSTATICTEXTURE == 1 )
  48. {
  49. # if( HASALPHAMASK == 1 )
  50. result.rgb += tex2D(TertiarySampler, i.vTertiaryTexCoord ).rgb * g_StaticAmount.x; //static
  51. # else
  52. result.rgb += tex2D(SecondarySampler, i.vSecondaryTexCoord ).rgb * g_StaticAmount.x; //static
  53. # endif
  54. }
  55. # else
  56. {
  57. result.rgb += g_StaticAmount.x * 0.25; //mix in gray
  58. }
  59. # endif
  60. }
  61. # endif
  62. # if( HASALPHAMASK == 1 )
  63. {
  64. //alpha mask
  65. result.a = tex2D(SecondarySampler, i.vSecondaryTexCoord ).a;
  66. }
  67. # else
  68. {
  69. result.a = 1;
  70. }
  71. # endif
  72. }
  73. # else //multiple pass configuration
  74. {
  75. # if( ADDSTATIC == 1 ) //in multipass configuration and adding static
  76. {
  77. # if( HASSTATICTEXTURE == 1 )
  78. result.rgb = tex2D(PrimarySampler, i.vPrimaryTexCoord.xy ).rgb;
  79. # endif
  80. result.a = g_StaticAmount.x; //in multipass, static is achieved by alpha blending the static onto an existing cutout pixel in the destination pixel
  81. }
  82. # else //in multipass config on the cutout pass
  83. {
  84. result.rgb = tex2D(PrimarySampler, i.vPrimaryTexCoord.xy ).rgb;
  85. # if( HASSTATICTEXTURE == 0 ) //there's no need to do another pass if there's no other texture to mix with, just mix in gray
  86. {
  87. result.rgb *= g_StaticAmount.y;
  88. result.rgb += g_StaticAmount.x * 0.25; //mix in gray
  89. }
  90. # endif
  91. result.a = 1;
  92. }
  93. # endif
  94. # if( (TEXTURESTAGES > 1) && (HASALPHAMASK == 1) )
  95. result.a *= tex2D(SecondarySampler, i.vSecondaryTexCoord ).a; //modulate in the alpha instead of setting it so we get blend as well as mask
  96. # endif
  97. }
  98. # endif
  99. return result;
  100. }