mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-25 21:51:09 +00:00
Fix depth blur
This commit is contained in:
parent
63fb604e98
commit
03d0b09f29
2 changed files with 14 additions and 30 deletions
|
@ -118,11 +118,6 @@ CUSTOM_CVAR(Float, gl_ssao_blur_amount, 4.0f, 0)
|
||||||
{
|
{
|
||||||
if (self < 0.1f) self = 0.1f;
|
if (self < 0.1f) self = 0.1f;
|
||||||
}
|
}
|
||||||
CUSTOM_CVAR(Int, gl_ssao_blur_samples, 5, 0)
|
|
||||||
{
|
|
||||||
if (self < 3 || self > 15 || self % 2 == 0)
|
|
||||||
self = 9;
|
|
||||||
}
|
|
||||||
|
|
||||||
EXTERN_CVAR(Float, vid_brightness)
|
EXTERN_CVAR(Float, vid_brightness)
|
||||||
EXTERN_CVAR(Float, vid_contrast)
|
EXTERN_CVAR(Float, vid_contrast)
|
||||||
|
@ -163,7 +158,6 @@ void FGLRenderer::AmbientOccludeScene()
|
||||||
float bias = gl_ssao_bias;
|
float bias = gl_ssao_bias;
|
||||||
float aoRadius = gl_ssao_radius;
|
float aoRadius = gl_ssao_radius;
|
||||||
const float blurAmount = gl_ssao_blur_amount;
|
const float blurAmount = gl_ssao_blur_amount;
|
||||||
int blurSampleCount = gl_ssao_blur_samples;
|
|
||||||
float aoStrength = gl_ssao_strength;
|
float aoStrength = gl_ssao_strength;
|
||||||
bool multisample = gl_multisample > 1;
|
bool multisample = gl_multisample > 1;
|
||||||
|
|
||||||
|
@ -174,6 +168,8 @@ void FGLRenderer::AmbientOccludeScene()
|
||||||
float nDotVBias = clamp(bias, 0.0f, 1.0f);
|
float nDotVBias = clamp(bias, 0.0f, 1.0f);
|
||||||
float r2 = aoRadius * aoRadius;
|
float r2 = aoRadius * aoRadius;
|
||||||
|
|
||||||
|
float blurSharpness = 1.0f / blurAmount;
|
||||||
|
|
||||||
// Calculate linear depth values
|
// Calculate linear depth values
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, mBuffers->AmbientFB0);
|
glBindFramebuffer(GL_FRAMEBUFFER, mBuffers->AmbientFB0);
|
||||||
glViewport(0, 0, mBuffers->AmbientWidth, mBuffers->AmbientHeight);
|
glViewport(0, 0, mBuffers->AmbientWidth, mBuffers->AmbientHeight);
|
||||||
|
@ -225,14 +221,14 @@ void FGLRenderer::AmbientOccludeScene()
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
mDepthBlurShader->Bind(false);
|
mDepthBlurShader->Bind(false);
|
||||||
mDepthBlurShader->BlurSharpness[false].Set(blurAmount);
|
mDepthBlurShader->BlurSharpness[false].Set(blurSharpness);
|
||||||
mDepthBlurShader->InvFullResolution[false].Set(1.0f / mBuffers->AmbientWidth, 1.0f / mBuffers->AmbientHeight);
|
mDepthBlurShader->InvFullResolution[false].Set(1.0f / mBuffers->AmbientWidth, 1.0f / mBuffers->AmbientHeight);
|
||||||
RenderScreenQuad();
|
RenderScreenQuad();
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, mBuffers->AmbientFB1);
|
glBindFramebuffer(GL_FRAMEBUFFER, mBuffers->AmbientFB1);
|
||||||
glBindTexture(GL_TEXTURE_2D, mBuffers->AmbientTexture0);
|
glBindTexture(GL_TEXTURE_2D, mBuffers->AmbientTexture0);
|
||||||
mDepthBlurShader->Bind(true);
|
mDepthBlurShader->Bind(true);
|
||||||
mDepthBlurShader->BlurSharpness[true].Set(blurAmount);
|
mDepthBlurShader->BlurSharpness[true].Set(blurSharpness);
|
||||||
mDepthBlurShader->InvFullResolution[true].Set(1.0f / mBuffers->AmbientWidth, 1.0f / mBuffers->AmbientHeight);
|
mDepthBlurShader->InvFullResolution[true].Set(1.0f / mBuffers->AmbientWidth, 1.0f / mBuffers->AmbientHeight);
|
||||||
mDepthBlurShader->PowExponent[true].Set(1.8f);
|
mDepthBlurShader->PowExponent[true].Set(1.8f);
|
||||||
RenderScreenQuad();
|
RenderScreenQuad();
|
||||||
|
|
|
@ -7,39 +7,32 @@ uniform float BlurSharpness;
|
||||||
uniform vec2 InvFullResolution;
|
uniform vec2 InvFullResolution;
|
||||||
uniform float PowExponent;
|
uniform float PowExponent;
|
||||||
|
|
||||||
#define KERNEL_RADIUS 3.0
|
#define KERNEL_RADIUS 7.0
|
||||||
|
|
||||||
struct CenterPixelData
|
float CrossBilateralWeight(float r, float sampleDepth, float centerDepth)
|
||||||
{
|
|
||||||
vec2 UV;
|
|
||||||
float Depth;
|
|
||||||
float Sharpness;
|
|
||||||
};
|
|
||||||
|
|
||||||
float CrossBilateralWeight(float r, float sampleDepth, CenterPixelData center)
|
|
||||||
{
|
{
|
||||||
const float blurSigma = KERNEL_RADIUS * 0.5;
|
const float blurSigma = KERNEL_RADIUS * 0.5;
|
||||||
const float blurFalloff = 1.0 / (2.0 * blurSigma * blurSigma);
|
const float blurFalloff = 1.0 / (2.0 * blurSigma * blurSigma);
|
||||||
|
|
||||||
float deltaZ = (sampleDepth - center.Depth) * center.Sharpness;
|
float deltaZ = (sampleDepth - centerDepth) * BlurSharpness;
|
||||||
|
|
||||||
return exp2(-r * r * blurFalloff - deltaZ * deltaZ);
|
return exp2(-r * r * blurFalloff - deltaZ * deltaZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessSample(float ao, float z, float r, CenterPixelData center, inout float totalAO, inout float totalW)
|
void ProcessSample(float ao, float z, float r, float centerDepth, inout float totalAO, inout float totalW)
|
||||||
{
|
{
|
||||||
float w = CrossBilateralWeight(r, z, center);
|
float w = CrossBilateralWeight(r, z, centerDepth);
|
||||||
totalAO += w * ao;
|
totalAO += w * ao;
|
||||||
totalW += w;
|
totalW += w;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessRadius(vec2 deltaUV, CenterPixelData center, inout float totalAO, inout float totalW)
|
void ProcessRadius(vec2 deltaUV, float centerDepth, inout float totalAO, inout float totalW)
|
||||||
{
|
{
|
||||||
for (float r = 1; r <= KERNEL_RADIUS; r += 1.0)
|
for (float r = 1; r <= KERNEL_RADIUS; r += 1.0)
|
||||||
{
|
{
|
||||||
vec2 uv = r * deltaUV + center.UV;
|
vec2 uv = r * deltaUV + TexCoord;
|
||||||
vec2 aoZ = texture(AODepthTexture, uv).xy;
|
vec2 aoZ = texture(AODepthTexture, uv).xy;
|
||||||
ProcessSample(aoZ.x, aoZ.y, r, center, totalAO, totalW);
|
ProcessSample(aoZ.x, aoZ.y, r, centerDepth, totalAO, totalW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,16 +40,11 @@ vec2 ComputeBlur(vec2 deltaUV)
|
||||||
{
|
{
|
||||||
vec2 aoZ = texture(AODepthTexture, TexCoord).xy;
|
vec2 aoZ = texture(AODepthTexture, TexCoord).xy;
|
||||||
|
|
||||||
CenterPixelData center;
|
|
||||||
center.UV = TexCoord;
|
|
||||||
center.Depth = aoZ.y;
|
|
||||||
center.Sharpness = BlurSharpness;
|
|
||||||
|
|
||||||
float totalAO = aoZ.x;
|
float totalAO = aoZ.x;
|
||||||
float totalW = 1.0;
|
float totalW = 1.0;
|
||||||
|
|
||||||
ProcessRadius(deltaUV, center, totalAO, totalW);
|
ProcessRadius(deltaUV, aoZ.y, totalAO, totalW);
|
||||||
ProcessRadius(-deltaUV, center, totalAO, totalW);
|
ProcessRadius(-deltaUV, aoZ.y, totalAO, totalW);
|
||||||
|
|
||||||
return vec2(totalAO / totalW, aoZ.y);
|
return vec2(totalAO / totalW, aoZ.y);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue