#version 410 uniform sampler2D textureColor; uniform sampler2D textureDepth; in vec2 uvV; out vec4 fragColor; uniform float opacity = 1.0; uniform vec2 meScreenSize; uniform float time; uniform float blurDirection = 0.0; // 0 horizontal, 1 vertical uniform float enableFxaa = 1.0; uniform float worldBrightness = 1.0; #include "commonPostprocessHelpers.glsl" void main (void) { vec2 pixelGap = 1.0 / meScreenSize.xy; vec2 co = gl_FragCoord.xy / vec2(meScreenSize.x, meScreenSize.y); bool blurDirectionHorizontal = blurDirection < 0.5; pixelGap *= (blurDirectionHorizontal) ? vec2(1,0) : vec2(0,1); pixelGap *= 2.0;//1.73; const float s0 = 252; const float s1 = 210; const float s2 = 120; const float s3 = 45; const float s4 = 10; const float sum = s0 + 2 * (s1 + s2 + s3 + s4); vec4 pixel0 = texture(textureColor, co); float depthSample; float depth0; { // TODO: pass near and far as uniforms, like eyePos, to all shaders who want them. depthSample = texture(textureDepth, co).r; depth0 = linearDepth(depthSample); // float n = 0.1; // float f = 500.0; // float z_n = 2.0 * depthSample - 1.0; // float z_e = 2 * n * f / (f + n - z_n * (f - n)); // depth0 = z_e; } if(enableFxaa == 0) { fragColor.xyz = pixel0.xyz; fragColor.a = 1.0; return; } vec4 pixel = pixel0 * s0; pixel += texture(textureColor, co - 1 * pixelGap) * s1; pixel += texture(textureColor, co + 1 * pixelGap) * s1; pixel += texture(textureColor, co - 2 * pixelGap) * s2; pixel += texture(textureColor, co + 2 * pixelGap) * s2; pixel += texture(textureColor, co - 3 * pixelGap) * s3; pixel += texture(textureColor, co + 3 * pixelGap) * s3; // pixel += texture(textureColor, co - 4 * pixelGap) * s4; // pixel += texture(textureColor, co + 4 * pixelGap) * s4; pixel /= sum; const float blurBeginRange = 30; const float blurFullRange = 170; float m = mapRange(depth0, blurBeginRange, blurFullRange, 0, 1); fragColor = mix(pixel0, pixel, m); if(blurDirectionHorizontal) { float bIn = 0.15; bIn = mapRange(depth0, 30, 3, 0.1, 0.15); float bOut = 0.1; float b2In = 0.6; b2In = mapRange(depth0, 30, 10, 0.6, 0.8); float b2Out = 0.8; float b = (fragColor.r + fragColor.g + fragColor.b) / 3.0; float b2; if(b < bIn) b2 = mapRange(b, 0, bIn, 0, bOut); else if(b > b2In) b2 = mapRange(b, b2In, 1.0, b2Out, 1.0); else b2 = mapRange(b, bIn, b2In, bOut, b2Out); if(b != 0) b2 = b2 / b; b2 *= worldBrightness; fragColor *= vec4(b2,b2,b2,1); } // pass-through the depth, even though now it is blurry. gl_FragDepth = depthSample; }