Counter Strike : Global Offensive Source Code
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.

63 lines
2.6 KiB

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