twiliteblue

av red

Dec 26th, 2020 (edited)
805
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.     //old colors
  55. //const float4 edgeColorBlue = float4(-0.02, 0.5, 1, 0) * 3.0;
  56. //const float4 edgeColorDarkBlue = float4(0.07, 0.05, 1, 0) * 1.5;
  57. //const float4 edgeColorOrange = float4(1.0, 0.25, 0.0, 0);
  58. //const float4 edgeColorDarkOrange = float4(1.0, 0.1, 0, 0);
  59. //const float4 edgeColorDarkRed = float4(1.0, 0.01, 0, 0);
  60. //const float4 edgeColorGreen = float4(0.2, 0.7, 0.00, 0);
  61. //const float4 edgeColorDarkGreen = float4(0.07, 0.7, 0.00, 0);
  62. const float4 edgeColorDark = float4 (0.01, 0.01, 0.01, 0);
  63.     // my colors
  64. const float4 edgeColorMarines = float4 (0.0, 1, 0, 0) * 10;
  65. const float4 edgeColorMarineStructures = float4 (1, 0, 0, 0) * 10;
  66. const float4 edgeColorAliens = float4 (0, 1, 3, 0) * 10;
  67. const float4 edgeColorGorges = float4 (0, 0.7, 0, 0) * 10;
  68. const float4 edgeColorAlienStructures = float4 (0, 1, 0.5, 0) * 3;
  69. const float4 edgeColorBorder = float4 (0.3, 0, 0, 0) * 0.1;
  70.  
  71. float4 SFXDarkVisionPS(PS_INPUT input) : COLOR0
  72. {
  73.     float2 texCoord = input.texCoord;
  74.     float4 inputPixel = tex2D(baseTexture, texCoord);
  75.    
  76.     if (amount == 0)
  77.     {
  78.         return inputPixel;
  79.     }
  80.    
  81.     float2 depth1 = tex2D(depthTexture, input.texCoord).rg;
  82.    
  83.     float fadeout = min(1, pow(2.0, 0.5 - depth1.r*.4));
  84.    
  85.     // Flashlight on
  86.     float offset = 0.0002 * (0.5 + depth1.g) * max(fadeout, 0.33); // thicker edge around entities, especially nearby
  87.     float depth2 = clamp_tex2D(depthTexture, texCoord + float2(-offset, -offset)).r;
  88.     float depth3 = clamp_tex2D(depthTexture, texCoord + float2(-offset,  offset)).r;
  89.     float depth4 = clamp_tex2D(depthTexture, texCoord + float2( offset, -offset)).r;
  90.     float depth5 = clamp_tex2D(depthTexture, texCoord + float2( offset,  offset)).r;
  91.    
  92.     float4 baseColor=float4(.9,0.9,.9,0);
  93.  
  94.     float edge =
  95.             abs(depth2 - depth1.r) +
  96.             abs(depth3 - depth1.r) +
  97.             abs(depth4 - depth1.r) +
  98.             abs(depth5 - depth1.r);
  99.     edge = min(1.2, edge);
  100.    
  101.     if (depth1.g > 0.5) // entities
  102.     {
  103.  
  104.         float min_intensity = 0.5; // entity colouring base intensity
  105.        
  106.         edge = (edge + min_intensity);
  107.        
  108.         if ( depth1.g > 0.99 ) // marines 1
  109.         {
  110.            return lerp(inputPixel, edgeColorMarines * edge, amount * (0.1 + edge) * 0.3);
  111.         }
  112.         else if ( depth1.g > 0.97 ) // marine structures 0.98
  113.         {
  114.             return lerp(inputPixel, edgeColorMarineStructures * edge, amount * (0.1 + edge) * 0.3);
  115.         }
  116.         else if ( depth1.g > 0.95 ) // alien players 0.96
  117.         {
  118.             return lerp( inputPixel, edgeColorAliens * edge, amount * (0.1 + edge) * 0.1);
  119.         }
  120.         else if ( depth1.g > 0.93 ) // gorges 0.94
  121.         {
  122.             return lerp( inputPixel, edgeColorAliens * edge, amount * (0.1 + edge) * 0.1);
  123.         }
  124.         else { // targets and world ents 0.9
  125.             return lerp( inputPixel, edgeColorAlienStructures * edge, amount * (0.1 + edge) * 0.15);
  126.         }
  127.  
  128.     } else // world geometry
  129.     {
  130.        
  131.         float fog = 0.04 * pow(3, depth1.r * 0.1);
  132.         edge = pow(edge, 0.5) * step( depth1.r, 100 ); // no edges for skyboxes
  133.         float maxStrength = 0.95;
  134.         float brightness = inputPixel.r + inputPixel.g * 1.5 + inputPixel.b;
  135.         float4 edgeColor2 = float4(0.3 - depth1.r * 0.005 + brightness * 0.1, fog * 0.02, brightness * 0.3 + fog, 0);
  136.        
  137.         return lerp(inputPixel * (5 - 4 * amount), edgeColor2 * (edge + brightness * 0.15) * max(1, fog), min(maxStrength, amount));
  138.        
  139.         //return saturate (inputPixel + edgeColorDark * 0.1 * amount * edge );
  140.         //return lerp(inputPixel, (edgeColor2 * edge), 0.01 * amount);
  141.     }
  142. }
Add Comment
Please, Sign In to add comment