gzdoom-gles/wadsrc/static/shaders/glsl/depthblur.fp

54 lines
1.3 KiB
Text
Raw Normal View History

2016-09-02 03:45:00 +00:00
layout(location=0) in vec2 TexCoord;
layout(location=0) out vec4 FragColor;
2016-09-02 03:45:00 +00:00
layout(binding=0) uniform sampler2D AODepthTexture;
2016-09-02 03:45:00 +00:00
2016-10-06 05:36:49 +00:00
#define KERNEL_RADIUS 3.0
2016-09-02 03:45:00 +00:00
void main()
2016-09-02 03:45:00 +00:00
{
const float blurSigma = KERNEL_RADIUS * 0.5;
const float blurFalloff = 1.0 / (2.0 * blurSigma * blurSigma);
vec2 centerSample = texture(AODepthTexture, TexCoord).xy;
2016-09-02 03:45:00 +00:00
float centerDepth = centerSample.y;
float totalAO = centerSample.x;
float totalW = 1.0;
2016-09-02 03:45:00 +00:00
for (float r = 1.0; r <= KERNEL_RADIUS; r += 1.0)
2016-09-02 03:45:00 +00:00
{
vec4 blurSample = texture(AODepthTexture, TexCoord - InvFullResolution * r);
float ao = blurSample.x;
float z = blurSample.y;
2016-09-02 03:45:00 +00:00
float deltaZ = (z - centerDepth) * BlurSharpness;
float w = exp2(-r * r * blurFalloff - deltaZ * deltaZ);
2016-09-02 03:45:00 +00:00
totalAO += w * ao;
totalW += w;
}
2016-09-02 03:45:00 +00:00
for (float r = 1.0; r <= KERNEL_RADIUS; r += 1.0)
{
vec4 blurSample = texture(AODepthTexture, InvFullResolution * r + TexCoord);
float ao = blurSample.x;
float z = blurSample.y;
2016-09-02 03:45:00 +00:00
float deltaZ = (z - centerDepth) * BlurSharpness;
float w = exp2(-r * r * blurFalloff - deltaZ * deltaZ);
2016-09-02 03:45:00 +00:00
totalAO += w * ao;
totalW += w;
}
2016-09-02 03:45:00 +00:00
float fragAO = totalAO / totalW;
2016-09-02 03:45:00 +00:00
#if defined(BLUR_HORIZONTAL)
FragColor = vec4(fragAO, centerDepth, 0.0, 1.0);
2016-09-02 03:45:00 +00:00
#else
FragColor = vec4(pow(clamp(fragAO, 0.0, 1.0), PowExponent), 0.0, 0.0, 1.0);
2016-09-02 03:45:00 +00:00
#endif
}