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.7 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..0" [= 0] [XBOX]
  4. // Includes =======================================================================================
  5. #include "common_vertexlitgeneric_dx9.h"
  6. // Texture Samplers ===============================================================================
  7. sampler g_tInnerSampler : register( s0 );
  8. sampler g_tMiddleSampler : register( s1 );
  9. sampler g_tOuterSampler : register( s2 );
  10. // Shaders Constants and Globals ==================================================================
  11. //const float4 g_vPackedConst6 : register( c6 );
  12. //#define g_flTime g_vPackedConst6.w
  13. // Interpolated values ============================================================================
  14. struct PS_INPUT
  15. {
  16. float4 v2DTangentViewVector01 : TEXCOORD0;
  17. float4 vUv01 : TEXCOORD1;
  18. float4 v2DTangentViewVector2_vUv2 : TEXCOORD2;
  19. };
  20. // Main ===========================================================================================
  21. float4 main( PS_INPUT i ) : COLOR
  22. {
  23. float4 vFinalColor = float4( 0.0f, 0.0f, 0.0f, 1.0f );
  24. #if defined(SHADER_MODEL_PS_2_0)
  25. float flNumLayers = 2.0f;
  26. #else
  27. float flNumLayers = 10.0f;
  28. #endif
  29. //float flColorDim = 1.0f;
  30. for ( float j=flNumLayers-1.0f; j>=0.0f; j-=1.0f ) // From hightest to lowest layer
  31. {
  32. float4 vInnerTexel = tex2D( g_tInnerSampler, saturate( i.vUv01.xy + i.v2DTangentViewVector01.xy * 0.005 * j ) );
  33. float4 vMiddleTexel = tex2D( g_tMiddleSampler, saturate( i.vUv01.wz + i.v2DTangentViewVector01.wz * 0.005 * j ) );
  34. float4 vOuterTexel = tex2D( g_tOuterSampler, saturate( i.v2DTangentViewVector2_vUv2.wz + i.v2DTangentViewVector2_vUv2.xy * 0.005 * j ) );
  35. float4 vThisTexel;
  36. vThisTexel.rgb = ( vInnerTexel.rgb * vInnerTexel.a ) + ( vMiddleTexel.rgb * vMiddleTexel.a ) + ( vOuterTexel.rgb * vOuterTexel.a );
  37. vThisTexel.a = 1.0f - ( ( 1.0f - vOuterTexel.a ) * ( 1.0f - vMiddleTexel.a ) * ( 1.0f - vInnerTexel.a ) );
  38. //vThisTexel.rgb *= flColorDim;
  39. //flColorDim *= 0.95f;
  40. // 5.0 and 0.8625 are magic numbers that look good with the current textures
  41. float flBlendValue = saturate( pow( vThisTexel.a, lerp( 5.0f, 0.8625f, saturate( j/(flNumLayers-1.0f) ) ) ) );
  42. vFinalColor.rgb = vThisTexel.rgb + ( vFinalColor.rgb * ( 1.0f - flBlendValue ) );
  43. vFinalColor.a *= 1.0f - flBlendValue; // Dest alpha scalar
  44. }
  45. //===============//
  46. // Combine terms //
  47. //===============//
  48. float4 result;
  49. result.rgb = vFinalColor.rgb;
  50. result.a = 1.0f - vFinalColor.a;
  51. return FinalOutput( result, 0, PIXEL_FOG_TYPE_NONE, TONEMAP_SCALE_LINEAR ); //go back to final output when it'll fit.
  52. }