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.

194 lines
5.5 KiB

  1. // STATIC: "CONVERT_TO_SRGB" "0..1" [ps20b][= g_pHardwareConfig->NeedsShaderSRGBConversion()] [PC]
  2. // STATIC: "CONVERT_TO_SRGB" "0..0" [= 0] [XBOX]
  3. // STATIC: "DUALSEQUENCE" "0..1"
  4. // STATIC: "SEQUENCE_BLEND_MODE" "0..2"
  5. // STATIC: "ADDBASETEXTURE2" "0..1"
  6. // STATIC: "MAXLUMFRAMEBLEND1" "0..1"
  7. // STATIC: "MAXLUMFRAMEBLEND2" "0..1"
  8. // STATIC: "EXTRACTGREENALPHA" "0..1"
  9. // STATIC: "COLORRAMP" "0..1"
  10. // STATIC: "ANIMBLEND" "0..1"
  11. // STATIC: "ADDSELF" "0..1"
  12. // STATIC: "DEPTHBLEND" "0..1" [ps20b]
  13. #define COMBINE_MODE_AVERAGE 0
  14. #define COMBINE_MODE_USE_FIRST_AS_ALPHA_MASK_ON_SECOND 1
  15. #define COMBINE_MODE_USE_FIRST_OVER_SECOND 2
  16. #define HDRTYPE HDR_TYPE_NONE
  17. #include "common_ps_fxc.h"
  18. const float4 g_Parameters : register( c0 );
  19. const float4 g_DepthFeatheringConstants : register( c2 );
  20. #define fAdditiveBlendWeight g_Parameters.x
  21. #define fOverbrightFactor g_Parameters.y
  22. #define fAdditiveSelfBlendWeight g_Parameters.z
  23. struct PS_INPUT
  24. {
  25. float2 texCoord0 : TEXCOORD0;
  26. float2 texCoord1 : TEXCOORD1;
  27. float4 argbcolor : COLOR;
  28. float4 blendfactor0 : TEXCOORD2;
  29. #if ADDBASETEXTURE2
  30. float2 texCoord2 : TEXCOORD3;
  31. #endif
  32. #if EXTRACTGREENALPHA
  33. float4 blendfactor1 : TEXCOORD4;
  34. #endif
  35. #if DUALSEQUENCE
  36. float2 vSeq2TexCoord0 : TEXCOORD5;
  37. float2 vSeq2TexCoord1 : TEXCOORD6;
  38. #endif
  39. #if defined( REVERSE_DEPTH_ON_X360 )
  40. float4 vScreenPos_ReverseZ : TEXCOORD7;
  41. #else
  42. float4 vScreenPos : TEXCOORD7;
  43. #endif
  44. };
  45. sampler BaseTextureSampler : register( s0 );
  46. sampler ColorRampSampler : register( s1 );
  47. sampler DepthSampler : register( s2 );
  48. float4 main( PS_INPUT i ) : COLOR
  49. {
  50. bool bMaxLumFrameBlend1 = MAXLUMFRAMEBLEND1 ? true : false;
  51. bool bMaxLumFrameBlend2 = MAXLUMFRAMEBLEND2 ? true : false;
  52. bool bExtractGreenAlpha = EXTRACTGREENALPHA ? true : false;
  53. bool bAddBaseTexture2 = ADDBASETEXTURE2 ? true : false;
  54. bool bDualSequence = DUALSEQUENCE ? true : false;
  55. bool bColorRamp = COLORRAMP ? true : false;
  56. #ifdef DEPTHBLEND
  57. bool bDepthBlend = DEPTHBLEND ? true : false;
  58. #endif
  59. int nSequenceBlendMode = SEQUENCE_BLEND_MODE;
  60. // Sample frames from texture 0
  61. float4 baseTex0 = tex2D( BaseTextureSampler, i.texCoord0 );
  62. float4 baseTex1 = tex2D( BaseTextureSampler, i.texCoord1 );
  63. // Blend by default (may override with bMaxLumFrameBlend1 or bExtractGreenAlpha)
  64. #if ANIMBLEND
  65. float4 blended_rgb = lerp( baseTex0, baseTex1, i.blendfactor0.x );
  66. #else
  67. float4 blended_rgb = baseTex0;
  68. #endif
  69. if ( bMaxLumFrameBlend1 )
  70. {
  71. // Blend between animation frames based upon max luminance
  72. float lum0 = dot( float3(.3, .59, .11), baseTex0.rgb * (1-i.blendfactor0.x));
  73. float lum1 = dot( float3(.3, .59, .11), baseTex1.rgb * i.blendfactor0.x);
  74. if ( lum0 > lum1 )
  75. blended_rgb = baseTex0;
  76. else
  77. blended_rgb = baseTex1;
  78. }
  79. else if( bExtractGreenAlpha )
  80. {
  81. #if EXTRACTGREENALPHA
  82. // Weight Green/Alphas from the two frames for a scalar result
  83. blended_rgb = dot( baseTex0, i.blendfactor0 ) + dot( baseTex1, i.blendfactor1 );
  84. #endif
  85. }
  86. #if DUALSEQUENCE
  87. if ( bDualSequence )
  88. {
  89. baseTex0 = tex2D( BaseTextureSampler, i.vSeq2TexCoord0 );
  90. baseTex1 = tex2D( BaseTextureSampler, i.vSeq2TexCoord1 );
  91. // Blend by default (may override with bMaxLumFrameBlend2)
  92. float4 rgb2 = lerp( baseTex0, baseTex1, i.blendfactor0.z );
  93. if ( bMaxLumFrameBlend2 )
  94. {
  95. // blend between animation frames based upon max luminance
  96. float tlum0 = dot( float3(.3, .59, .11), baseTex0.rgb * (1-i.blendfactor0.x));
  97. float tlum1 = dot( float3(.3, .59, .11), baseTex1.rgb * i.blendfactor0.x);
  98. if ( tlum0 > tlum1 )
  99. rgb2 = baseTex0;
  100. else
  101. rgb2 = baseTex1;
  102. }
  103. if ( nSequenceBlendMode == COMBINE_MODE_AVERAGE )
  104. {
  105. blended_rgb = 0.5 * ( blended_rgb + rgb2 );
  106. }
  107. else if ( nSequenceBlendMode == COMBINE_MODE_USE_FIRST_AS_ALPHA_MASK_ON_SECOND )
  108. {
  109. blended_rgb.rgb = rgb2.rgb;
  110. }
  111. else if ( nSequenceBlendMode == COMBINE_MODE_USE_FIRST_OVER_SECOND )
  112. {
  113. blended_rgb.rgb = lerp( blended_rgb.rgb, rgb2.rgb, rgb2.a );
  114. }
  115. } // bDualSequence
  116. #endif
  117. // Optional color ramp
  118. if ( bColorRamp )
  119. {
  120. blended_rgb.rgb = tex2D( ColorRampSampler, float2( blended_rgb.r, blended_rgb.g ) );
  121. }
  122. // Overbright
  123. blended_rgb.rgb *= fOverbrightFactor;
  124. //Soft Particles FTW
  125. # if (DEPTHBLEND == 1)
  126. # if defined( _X360 )
  127. float fDepthBlend = DepthFeathering( DepthSampler, i.vScreenPos_ReverseZ.xy / i.vScreenPos_ReverseZ.w, i.vScreenPos_ReverseZ.z, i.vScreenPos_ReverseZ.w, g_DepthFeatheringConstants );
  128. # else
  129. float fDepthBlend = DepthFeathering( DepthSampler, i.vScreenPos.xy / i.vScreenPos.w, i.vScreenPos.z, i.vScreenPos.w, g_DepthFeatheringConstants );
  130. # endif
  131. i.argbcolor.a *= fDepthBlend;
  132. # endif
  133. // Premultiply the alpha for a ONE:INVALPHA blend
  134. #if ADDBASETEXTURE2
  135. if ( bAddBaseTexture2 )
  136. {
  137. blended_rgb.a *= i.argbcolor.a;
  138. // In this case, we don't really want to pre-multiply by alpha
  139. if ( !bColorRamp )
  140. {
  141. blended_rgb.rgb *= blended_rgb.a;
  142. }
  143. if ( bExtractGreenAlpha )
  144. {
  145. blended_rgb.rgb += fAdditiveBlendWeight * i.argbcolor.a * blended_rgb.rgb;
  146. }
  147. else
  148. {
  149. blended_rgb.rgb += fOverbrightFactor * fAdditiveBlendWeight * i.argbcolor.a * tex2D( BaseTextureSampler, i.texCoord2 );
  150. }
  151. blended_rgb.rgb *= i.argbcolor.rgb;
  152. }
  153. else
  154. #endif
  155. {
  156. #if ADDSELF
  157. blended_rgb.a *= i.argbcolor.a;
  158. blended_rgb.rgb *= blended_rgb.a;
  159. blended_rgb.rgb += fOverbrightFactor * fAdditiveSelfBlendWeight * i.argbcolor.a * blended_rgb;
  160. blended_rgb.rgb *= i.argbcolor.rgb;
  161. #else
  162. blended_rgb *= i.argbcolor;
  163. #endif
  164. }
  165. return FinalOutput( blended_rgb, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_LINEAR );
  166. }