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

67 lines
1.5 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
2016-09-10 20:39:09 +00:00
float CrossBilateralWeight(float r, float sampleDepth, float centerDepth)
2016-09-02 03:45:00 +00:00
{
const float blurSigma = KERNEL_RADIUS * 0.5;
const float blurFalloff = 1.0 / (2.0 * blurSigma * blurSigma);
2016-09-10 20:39:09 +00:00
float deltaZ = (sampleDepth - centerDepth) * BlurSharpness;
2016-09-02 03:45:00 +00:00
return exp2(-r * r * blurFalloff - deltaZ * deltaZ);
}
2016-09-10 20:39:09 +00:00
void ProcessSample(float ao, float z, float r, float centerDepth, inout float totalAO, inout float totalW)
2016-09-02 03:45:00 +00:00
{
2016-09-10 20:39:09 +00:00
float w = CrossBilateralWeight(r, z, centerDepth);
2016-09-02 03:45:00 +00:00
totalAO += w * ao;
totalW += w;
}
2016-09-10 20:39:09 +00:00
void ProcessRadius(vec2 deltaUV, float centerDepth, inout float totalAO, inout float totalW)
2016-09-02 03:45:00 +00:00
{
for (float r = 1; r <= KERNEL_RADIUS; r += 1.0)
{
2016-09-10 20:39:09 +00:00
vec2 uv = r * deltaUV + TexCoord;
2016-09-02 03:45:00 +00:00
vec2 aoZ = texture(AODepthTexture, uv).xy;
2016-09-10 20:39:09 +00:00
ProcessSample(aoZ.x, aoZ.y, r, centerDepth, totalAO, totalW);
2016-09-02 03:45:00 +00:00
}
}
vec2 ComputeBlur(vec2 deltaUV)
{
vec2 aoZ = texture(AODepthTexture, TexCoord).xy;
float totalAO = aoZ.x;
float totalW = 1.0;
2016-09-10 20:39:09 +00:00
ProcessRadius(deltaUV, aoZ.y, totalAO, totalW);
ProcessRadius(-deltaUV, aoZ.y, totalAO, totalW);
2016-09-02 03:45:00 +00:00
return vec2(totalAO / totalW, aoZ.y);
}
vec2 BlurX()
{
return ComputeBlur(vec2(InvFullResolution.x, 0.0));
}
float BlurY()
{
return pow(clamp(ComputeBlur(vec2(0.0, InvFullResolution.y)).x, 0.0, 1.0), PowExponent);
}
void main()
{
#if defined(BLUR_HORIZONTAL)
FragColor = vec4(BlurX(), 0.0, 1.0);
#else
FragColor = vec4(BlurY(), 0.0, 0.0, 1.0);
#endif
}