Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <renderer/RenderSetup.hlsl>
- struct VS_INPUT
- {
- float3 ssPosition : POSITION;
- float2 texCoord : TEXCOORD0;
- float4 color : COLOR0;
- };
- struct VS_OUTPUT
- {
- float2 texCoord : TEXCOORD0;
- float4 color : COLOR0;
- float4 ssPosition : SV_POSITION;
- };
- struct PS_INPUT
- {
- float2 texCoord : TEXCOORD0;
- float4 color : COLOR0;
- };
- sampler2D baseTexture;
- sampler2D depthTexture;
- sampler2D normalTexture;
- cbuffer LayerConstants
- {
- float startTime;
- float amount;
- };
- /**
- * Vertex shader.
- */
- VS_OUTPUT SFXBasicVS(VS_INPUT input)
- {
- VS_OUTPUT output;
- output.ssPosition = float4(input.ssPosition, 1);
- output.texCoord = input.texCoord + texelCenter;
- output.color = input.color;
- return output;
- }
- const float distantIntensity = 0.64; // Intensity for Colour2 - Distant background
- const float closeIntensity = 0.39; // Intensity for Colour1 - Close Area
- const float fogIntensity = 1.0;//const float fogIntensity = 0.72; // Value of ColourThree - Intensity of Model Highlighting
- const float edgeSizeAThird = 0.00025;//One Third of the EDGE Highlighting
- /// Value of NS2+: X/255 * Intensity
- /// Colour 1-3 have R, G, B Values
- const float colourOneRGB = 0.0168235294; // X/255 RGB Colour of Colour 1 (Close Area) already multiplied by Intensity Value
- const float colourTwoRGB = 0.0224; // X/255 RGB Colour of Colour 2 (Distant Area) already multiplied by Intensity Value
- const float desatIntensity = 0.6; // Intensity of the Greying / Fillingeffekt for example
- // const float avBlend = 1.5;
- //const float avBlendChange = avBlend * (avBlend/0.66);
- const float avBlendChange = 3.4090909090909090909090909090909; //Precalculated
- const float avDesatBlend = 0.25;
- const float avAspect = 4/3; // Aspect if you Aim at something the Edges get Smaller
- float4 SFXDarkVisionPS(PS_INPUT input) : COLOR0
- {
- float4 alienVision = float4(0,0,0,1);
- const float2 texCoord = input.texCoord;
- const float4 inputPixel = tex2D(baseTexture, texCoord);
- //AV OFF if amount < 1 // IF Branch costs time for Shader
- //if (amount < 1){
- //return inputPixel;
- //}
- const float red = inputPixel.r;
- const float green = inputPixel.g;
- const float blue = inputPixel.b;
- const float depth = tex2D(depthTexture, texCoord).r;
- const float model = max(0, tex2D(depthTexture, texCoord).g * 2 - 1);
- const float2 depth1 = tex2D(depthTexture, input.texCoord).rg;
- float x = (input.texCoord.x - 0.5) * 20;
- float y = (input.texCoord.y - 0.5) * 20;
- float distanceSq = (x * x + y * y)/100;
- float sineX = sin(-x * .1) * sin(-x * .1);
- float sineY = sin(-y * .1) * sin(-y * .1);
- // TODO: REMOVE THESE CALCULATIONS!
- float avAreaX = clamp(sineX * avAspect *1.5, 0, 1);
- float avAreaY = clamp(sineY , 0, 1);
- float edgeSetting = (edgeSizeAThird) + distanceSq * (edgeSizeAThird * 3) * (1 + depth1.g);
- const float offset = edgeSetting;
- float depth2 = tex2D(depthTexture, texCoord + float2( offset, 0)).r;
- float depth3 = tex2D(depthTexture, texCoord + float2(-offset, 0)).r;
- float depth4 = tex2D(depthTexture, texCoord + float2( 0, offset)).r;
- float depth5 = tex2D(depthTexture, texCoord + float2( 0, -offset)).r;
- float4 edge = abs(depth2 - depth) +
- abs(depth3 - depth) +
- abs(depth4 - depth) +
- abs(depth5 - depth);
- edge = min(1, pow(edge + 0.12, 2));
- // TODO: Cut these Calculations
- float fadedist = pow(2, -depth1.r * 0.23 + 0.23);
- float fadeDistBlend = pow(2, -depth1.r * 0.23 + 0.23);//float fadeDistBlend = pow(2.9272727272727272727272727272727 ,
- float colourThreeG = 0.21; // X/255 * fogIntensity
- float colourThreeB = 0.015;
- if ( depth1.g > 0.99) {colourThreeB = 0.00; } // Marines
- const float4 colourOne = float4(colourOneRGB , colourOneRGB,colourOneRGB , closeIntensity);
- const float4 colourTwo = float4(colourTwoRGB , colourTwoRGB,colourTwoRGB , distantIntensity) ;
- const float4 colourFog = float4(colourThreeB , colourThreeG,colourThreeB, fogIntensity);
- float4 modelColour =
- ((model * pow(edge,2)) * (colourFog )) +
- (model * pow(edge,2) * 10 +
- model * pow(edge,2) * 200) * (colourFog);
- // Skybox
- 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));
- float4 noSkybox = lerp(1,0,maskSkybox) * inputPixel;
- float4 desaturate = float4(max(0, max(green, blue) - red), max(0, max(red, blue) - green), max(0, max(green, red) - blue), 0);
- alienVision = (((max(inputPixel,edge) + desaturate * desatIntensity) * clamp(((colourOne * (fadeDistBlend * 10)) + (colourTwo * (.75-fadeDistBlend))),0,1) + modelColour) ) * maskSkybox + noSkybox;
- return alienVision;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement