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.

59 lines
2.0 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. // paired with "vertexlit_and_unlit_generic_vs##"
  3. // STATIC: "VERTEXALPHA" "0..1"
  4. // STATIC: "FOGFADE" "0..1"
  5. #include "common_fog_ps_fxc.h"
  6. #include "common_ps_fxc.h"
  7. #include "shader_constant_register_map.h"
  8. sampler TexSampler : register( s0 );
  9. const float4 g_FogParams : register( PSREG_FOG_PARAMS );
  10. const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT );
  11. const float4 g_FogTweakParams : register( c0 );
  12. #define g_fFogExponentTweak g_FogTweakParams.x
  13. #define g_fFogScaleTweak g_FogTweakParams.y
  14. #define FOG_START_FADE ( g_FogTweakParams.z ) //0.1
  15. #define FOG_END_FADE ( g_FogTweakParams.w ) //0.30
  16. struct PS_INPUT
  17. {
  18. float2 baseTexCoord : TEXCOORD0; // Base texture coordinate
  19. float4 worldPos_projPosZ : TEXCOORD1; // Necessary for pixel fog
  20. float4 color : COLOR1;
  21. };
  22. float4_color_return_type main( PS_INPUT i ) : COLOR
  23. {
  24. float4 result = tex2D( TexSampler, i.baseTexCoord );
  25. // Blend towards grey based on alpha
  26. float flFactor = 1.0;
  27. #if VERTEXALPHA
  28. flFactor *= i.color.w;
  29. #endif
  30. result.xyz = lerp( float3( 0.5, 0.5, 0.5 ), result.xyz, flFactor );
  31. // Since we're blending with a mod2x, we need to compensate with this hack
  32. // NOTE: If the fog color (not fog density) is extremely dark, this can makes some decals seem
  33. // a little transparent, but it's better than not doing this
  34. float flFogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.xyz, i.worldPos_projPosZ.xyz, i.worldPos_projPosZ.w );
  35. float flAdjustedFogFactor = pow( saturate( g_fFogScaleTweak * flFogFactor ), g_fFogExponentTweak );
  36. if ( FOGFADE )
  37. {
  38. float flFogFadeAmount = clamp( ( flFogFactor - FOG_START_FADE ) / ( FOG_END_FADE - FOG_START_FADE ), 0.0, 1.0 );
  39. result.xyz = lerp( result.xyz, float3( 0.5, 0.5, 0.5 ), flFogFadeAmount );
  40. return FinalOutput( result, flAdjustedFogFactor, PIXEL_FOG_TYPE_RANGE, TONEMAP_SCALE_NONE );
  41. }
  42. else
  43. {
  44. return FinalOutput( result, flAdjustedFogFactor, PIXELFOGTYPE, TONEMAP_SCALE_NONE );
  45. }
  46. }