Advertisement
Aodh

DarkVision_Modified

Apr 18th, 2024
174
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. const float distantIntensity = 0.64; // Intensity for Colour2 - Distant background
  50. const float closeIntensity = 0.39;   // Intensity for Colour1 - Close Area
  51. const float fogIntensity = 1.0;//const float fogIntensity = 0.72; // Value of ColourThree - Intensity of Model Highlighting
  52. const float edgeSizeAThird = 0.00025;//One Third of the EDGE Highlighting
  53.     /// Value of NS2+:    X/255 * Intensity
  54.     /// Colour 1-3 have R, G, B Values
  55.  
  56. const float colourOneRGB = 0.0168235294;    // X/255 RGB Colour of Colour 1 (Close Area) already multiplied by Intensity Value
  57. const float colourTwoRGB = 0.0224;      // X/255 RGB Colour of Colour 2 (Distant Area) already multiplied by Intensity Value
  58. const float desatIntensity = 0.6;   // Intensity of the Greying / Fillingeffekt for example
  59.  
  60. //    const float avBlend = 1.5;
  61. //const float avBlendChange = avBlend * (avBlend/0.66);
  62.  const float avBlendChange = 3.4090909090909090909090909090909; //Precalculated
  63.  const float avDesatBlend = 0.25;
  64.  const float avAspect = 4/3; // Aspect if you Aim at something the Edges get Smaller
  65.  
  66.  
  67.  
  68.  
  69.    
  70. float4 SFXDarkVisionPS(PS_INPUT input) : COLOR0
  71. {
  72.     float4 alienVision = float4(0,0,0,1);
  73.     const float2 texCoord = input.texCoord;
  74.     const float4 inputPixel = tex2D(baseTexture, texCoord);
  75.    
  76.     //AV OFF if amount < 1 // IF Branch costs time for Shader
  77.     //if (amount < 1){
  78.         //return inputPixel;
  79.     //}
  80.  
  81.     const float red = inputPixel.r;
  82.     const float green = inputPixel.g;
  83.     const float blue = inputPixel.b;
  84.  
  85.     const float  depth = tex2D(depthTexture, texCoord).r;
  86.     const float  model = max(0, tex2D(depthTexture, texCoord).g * 2 - 1);
  87.     const float2 depth1 = tex2D(depthTexture, input.texCoord).rg;
  88.    
  89.     float x = (input.texCoord.x - 0.5) * 20;
  90.     float y = (input.texCoord.y - 0.5) * 20;
  91.     float distanceSq    = (x * x + y * y)/100; 
  92.     float sineX = sin(-x * .1) * sin(-x * .1);
  93.     float sineY = sin(-y * .1) * sin(-y * .1);
  94.  
  95.    
  96.    
  97.     // TODO: REMOVE THESE CALCULATIONS!
  98.     float avAreaX = clamp(sineX * avAspect *1.5, 0, 1);
  99.     float avAreaY = clamp(sineY , 0, 1);
  100.  
  101.  
  102.  
  103.     float edgeSetting = (edgeSizeAThird) + distanceSq * (edgeSizeAThird * 3) * (1 + depth1.g);
  104.    
  105.     const float offset = edgeSetting;
  106.     float  depth2 = tex2D(depthTexture, texCoord + float2( offset, 0)).r;
  107.     float  depth3 = tex2D(depthTexture, texCoord + float2(-offset, 0)).r;
  108.     float  depth4 = tex2D(depthTexture, texCoord + float2( 0,  offset)).r;
  109.     float  depth5 = tex2D(depthTexture, texCoord + float2( 0, -offset)).r;
  110.    
  111.     float4 edge = abs(depth2 - depth) +
  112.            abs(depth3 - depth) +
  113.            abs(depth4 - depth) +
  114.            abs(depth5 - depth);
  115.  
  116.     edge = min(1, pow(edge + 0.12, 2));
  117.  
  118.     // TODO: Cut these Calculations
  119.     float fadedist = pow(2, -depth1.r * 0.23 + 0.23);
  120.     float fadeDistBlend = pow(2, -depth1.r * 0.23 + 0.23);//float fadeDistBlend = pow(2.9272727272727272727272727272727 ,
  121.    
  122.     float   colourThreeG = 0.21;            //  X/255 * fogIntensity
  123.     float   colourThreeB = 0.015;
  124.  
  125.     if ( depth1.g > 0.99) {colourThreeB = 0.00; } // Marines   
  126.      const float4 colourOne = float4(colourOneRGB , colourOneRGB,colourOneRGB   , closeIntensity);
  127.      const float4 colourTwo = float4(colourTwoRGB , colourTwoRGB,colourTwoRGB   , distantIntensity) ;
  128.      const float4 colourFog = float4(colourThreeB            , colourThreeG,colourThreeB, fogIntensity);       
  129.    
  130.     float4 modelColour =
  131.     ((model * pow(edge,2)) * (colourFog )) +    
  132.     (model * pow(edge,2) * 10 +  
  133.     model * pow(edge,2) * 200) * (colourFog);
  134.  
  135.     // Skybox
  136.     float maskSkybox = lerp(step(depth1.r, 120), lerp(step(depth1.r, 90), step(depth1.r,70), clamp(avAreaX + avAreaY, 0, 1)), clamp((avAreaX + avAreaY) * 2,0,1));
  137.     float4 noSkybox = lerp(1,0,maskSkybox) * inputPixel;
  138.      
  139.  
  140.     float4 desaturate = float4(max(0, max(green, blue) - red), max(0, max(red, blue) - green), max(0, max(green, red) - blue), 0);
  141.  
  142.  
  143.     alienVision = (((max(inputPixel,edge) + desaturate * desatIntensity) * clamp(((colourOne * (fadeDistBlend * 10)) + (colourTwo * (.75-fadeDistBlend))),0,1) + modelColour) ) * maskSkybox + noSkybox;
  144.  
  145.     return alienVision;
  146.  
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement