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.

69 lines
2.8 KiB

  1. //========== Copyright (c) Valve Corporation, All rights reserved. ==========//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. // DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps20b] [PC]
  7. // DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..0" [ps20b] [CONSOLE]
  8. // DYNAMIC: "WRITE_DEPTH_TO_DESTALPHA" "0..1" [ps30]
  9. #include "common_fog_ps_fxc.h"
  10. #include "common_ps_fxc.h"
  11. #include "shader_constant_register_map.h"
  12. sampler BaseTextureSampler : register( s0 );
  13. sampler IrisSampler : register( s1 );
  14. sampler GlintSampler : register( s2 );
  15. const float4 cEyeScalars : register( c0 ); // { Dilation, x, x, x }
  16. const float4 cEyeScalars2 : register( c1 ); // { ambient, ambient, ambient, ambient }
  17. const float4 g_FogParams : register( PSREG_FOG_PARAMS );
  18. const float4 g_EyePos_SpecExponent : register( PSREG_EYEPOS_SPEC_EXPONENT );
  19. struct PS_INPUT
  20. {
  21. float2 baseTexCoord : TEXCOORD0;
  22. float2 irisTexCoord : TEXCOORD1;
  23. float2 glintTexCoord : TEXCOORD2;
  24. float3 vertAtten : TEXCOORD3;
  25. float4 worldPos_projPosZ : TEXCOORD7; // Necessary for pixel fog
  26. };
  27. #define fDilationFactor cEyeScalars.x
  28. #define fGlintDamping cEyeScalars2.x
  29. float4_color_return_type main( PS_INPUT i ) : COLOR
  30. {
  31. float4 baseSample = tex2D( BaseTextureSampler, i.baseTexCoord );
  32. float4 glintSample = tex2D( GlintSampler, i.glintTexCoord );
  33. /*
  34. // Dilate the pupil/iris texture (1 is max dilation, 0 is none)
  35. float2 biasedCoords = i.irisTexCoord * 2.0f - 1.0f; // -1 to +1 range
  36. float fDilatability = saturate(0.8f - sqrt(dot(biasedCoords, biasedCoords) )); // 1 in the center, fading out to 0 at 0.8 from center, since irises are inset into maps
  37. float2 scaledCoords = biasedCoords * (1 + fDilatability); // Maximal dilation
  38. // Blend undilated and maximally dilated based upon dilation factor
  39. float2 dilatedCoords = lerp( scaledCoords, biasedCoords, 1.0f-saturate(cDilationFactor.x));
  40. dilatedCoords = dilatedCoords * 0.5f + 0.5f; // Back to 0..1 range
  41. */
  42. float4 irisSample = tex2D( IrisSampler, i.irisTexCoord ); // Sample the iris map using dilated coordinates
  43. float4 result;
  44. result.rgb = lerp( baseSample.rgb, irisSample.rgb, irisSample.a );
  45. result.rgb *= i.vertAtten;
  46. result.rgb += glintSample.rgb * fGlintDamping;
  47. result.a = baseSample.a;
  48. bool bWriteDepthToAlpha = false;
  49. // ps_2_b and beyond
  50. #if !(defined(SHADER_MODEL_PS_1_1) || defined(SHADER_MODEL_PS_1_4) || defined(SHADER_MODEL_PS_2_0))
  51. bWriteDepthToAlpha = WRITE_DEPTH_TO_DESTALPHA != 0;
  52. #endif
  53. float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams, g_EyePos_SpecExponent.xyz, i.worldPos_projPosZ.xyz, i.worldPos_projPosZ.w );
  54. return FinalOutput( result, fogFactor, PIXELFOGTYPE, TONEMAP_SCALE_LINEAR, bWriteDepthToAlpha, i.worldPos_projPosZ.w );
  55. }