Advertisement
Aodh

DarkVision_Original

Apr 18th, 2024
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <renderer/RenderSetup.hlsl>
  2.  
  3. struct VS_INPUT
  4. {
  5.    float3 ssPosition   : POSITION;
  6.    float2 texCoord     : TEXCOORD0;
  7.    float4 color        : COLOR0;
  8. };
  9.  
  10. struct VS_OUTPUT
  11. {
  12.    float2 texCoord     : TEXCOORD0;
  13.    float4 color        : COLOR0;
  14.    float4 ssPosition   : SV_POSITION;
  15. };
  16.  
  17. struct PS_INPUT
  18. {
  19.    float2 texCoord     : TEXCOORD0;
  20.    float4 color        : COLOR0;
  21. };
  22.  
  23. sampler2D       baseTexture;
  24. sampler2D       depthTexture;
  25. sampler2D       normalTexture;
  26.  
  27. cbuffer LayerConstants
  28. {
  29.     float        startTime;
  30.     float        amount;
  31. };
  32.  
  33. /**
  34. * Vertex shader.
  35. */  
  36. VS_OUTPUT SFXBasicVS(VS_INPUT input)
  37. {
  38.  
  39.    VS_OUTPUT output;
  40.  
  41.    output.ssPosition = float4(input.ssPosition, 1);
  42.    output.texCoord   = input.texCoord + texelCenter;
  43.    output.color      = input.color;
  44.  
  45.    return output;
  46.  
  47. }
  48.  
  49. float2 clamp_tex2D( sampler2D tex, float2 coord )
  50. {
  51.     // TODO: remove this and fix sampler using wrapped instead of clamped addressing for depthTexture
  52.     return tex2D( tex, clamp( coord, float2( 0.001, 0.001 ), float2( 0.999, 0.999 ) ) );
  53. }
  54.  
  55. const float4 edgeColorBlue = float4(0.0, 0.35, 1, 0) * 6.0;
  56. const float4 edgeColorDarkBlue = float4(0, 0.5, 1, 0) * 6.0;
  57. const float4 edgeColorOrange = float4(1.0, 0.05, 0.0, 0) * 8.0;
  58. const float4 edgeColorDarkOrange = float4(0.8, 0.2, 0, 0) * 6.0;
  59. const float4 edgeColorGreen = float4(0.2, 0.7, 0.00, 0) * 4.0;
  60.  
  61. const float4 edgeColor2 = float4(1.0, 1.0, 1.0, 0) * 0.25;
  62.  
  63. float4 SFXDarkVisionPS(PS_INPUT input) : COLOR0
  64. {
  65.     float2 texCoord = input.texCoord;
  66.     float4 inputPixel = tex2D(baseTexture, texCoord);
  67.    
  68.     if (amount == 0)
  69.     {
  70.         return inputPixel;
  71.     }
  72.    
  73.     float2 depth1 = tex2D(depthTexture, input.texCoord).rg;
  74.    
  75.     // Flashlight on
  76.     float offset = 0.0005;
  77.     float depth2 = clamp_tex2D(depthTexture, texCoord + float2(-offset, -offset)).r;
  78.     float depth3 = clamp_tex2D(depthTexture, texCoord + float2(-offset,  offset)).r;
  79.     float depth4 = clamp_tex2D(depthTexture, texCoord + float2( offset, -offset)).r;
  80.     float depth5 = clamp_tex2D(depthTexture, texCoord + float2( offset,  offset)).r;
  81.    
  82.     float fadeout = pow(2.0,-depth1.r*.5);
  83.     float4 baseColor=float4(.9,.9,.9,0);
  84.  
  85.     float edge =
  86.             abs(depth2 - depth1.r) +
  87.             abs(depth3 - depth1.r) +
  88.             abs(depth4 - depth1.r) +
  89.             abs(depth5 - depth1.r);
  90.    
  91.     if (depth1.g > 0.5) // entities
  92.     {
  93.    
  94.         if (depth1.r < 0.4) // view model
  95.         {
  96.             return inputPixel;
  97.         }
  98.  
  99.         float4 edgeColor;
  100.        
  101.             if ( depth1.g > 0.99 ) // marines 1
  102.             {
  103.                return saturate(lerp(inputPixel, edgeColorOrange * edge, (0.45 + edge) * amount));
  104.             }
  105.             else if ( depth1.g > 0.97 ) // marine structures 0.98
  106.             {
  107.                 return saturate( inputPixel + edgeColorDarkBlue * 0.075 * amount * edge );
  108.             }
  109.             else if ( depth1.g > 0.95 ) // alien players 0.96
  110.             {
  111.                 float4 edgeColor=edgeColorGreen*clamp((fadeout*5),0.05, 0.02);
  112.                 return saturate(lerp(inputPixel, max(inputPixel*baseColor,edge*edgeColor), 0.4));
  113.             }
  114.             else if ( depth1.g > 0.93 ) // gorges 0.94
  115.             {
  116.                 return saturate( inputPixel + edgeColorGreen * 0.035 * amount * edge );
  117.             }
  118.             else { // targets and world ents 0.9
  119.                 return saturate( inputPixel + edgeColorGreen * 0.1 * amount * edge );
  120.             }
  121.  
  122.     } else // world geometry
  123.     {
  124.         edge = edge * step( depth1.r, 100 ); // no edges for skyboxes
  125.         return lerp(inputPixel, (edgeColor2 * edge), 0.01 * amount);
  126.     }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement