diff --git a/src/gl/renderer/gl_postprocess.cpp b/src/gl/renderer/gl_postprocess.cpp index e00ca7305..9b791a3f1 100644 --- a/src/gl/renderer/gl_postprocess.cpp +++ b/src/gl/renderer/gl_postprocess.cpp @@ -118,11 +118,6 @@ CUSTOM_CVAR(Float, gl_ssao_blur_amount, 4.0f, 0) { 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_contrast) @@ -163,7 +158,6 @@ void FGLRenderer::AmbientOccludeScene() float bias = gl_ssao_bias; float aoRadius = gl_ssao_radius; const float blurAmount = gl_ssao_blur_amount; - int blurSampleCount = gl_ssao_blur_samples; float aoStrength = gl_ssao_strength; bool multisample = gl_multisample > 1; @@ -174,6 +168,8 @@ void FGLRenderer::AmbientOccludeScene() float nDotVBias = clamp(bias, 0.0f, 1.0f); float r2 = aoRadius * aoRadius; + float blurSharpness = 1.0f / blurAmount; + // Calculate linear depth values glBindFramebuffer(GL_FRAMEBUFFER, mBuffers->AmbientFB0); 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_MAG_FILTER, GL_NEAREST); 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); RenderScreenQuad(); glBindFramebuffer(GL_FRAMEBUFFER, mBuffers->AmbientFB1); glBindTexture(GL_TEXTURE_2D, mBuffers->AmbientTexture0); 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->PowExponent[true].Set(1.8f); RenderScreenQuad(); diff --git a/wadsrc/static/shaders/glsl/depthblur.fp b/wadsrc/static/shaders/glsl/depthblur.fp index bd464d03d..c4f4438d3 100644 --- a/wadsrc/static/shaders/glsl/depthblur.fp +++ b/wadsrc/static/shaders/glsl/depthblur.fp @@ -7,39 +7,32 @@ uniform float BlurSharpness; uniform vec2 InvFullResolution; uniform float PowExponent; -#define KERNEL_RADIUS 3.0 +#define KERNEL_RADIUS 7.0 -struct CenterPixelData -{ - vec2 UV; - float Depth; - float Sharpness; -}; - -float CrossBilateralWeight(float r, float sampleDepth, CenterPixelData center) +float CrossBilateralWeight(float r, float sampleDepth, float centerDepth) { const float blurSigma = KERNEL_RADIUS * 0.5; 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); } -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; 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) { - vec2 uv = r * deltaUV + center.UV; + vec2 uv = r * deltaUV + TexCoord; 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; - CenterPixelData center; - center.UV = TexCoord; - center.Depth = aoZ.y; - center.Sharpness = BlurSharpness; - float totalAO = aoZ.x; float totalW = 1.0; - ProcessRadius(deltaUV, center, totalAO, totalW); - ProcessRadius(-deltaUV, center, totalAO, totalW); + ProcessRadius(deltaUV, aoZ.y, totalAO, totalW); + ProcessRadius(-deltaUV, aoZ.y, totalAO, totalW); return vec2(totalAO / totalW, aoZ.y); }