diff --git a/src/rendering/hwrenderer/postprocessing/hw_postprocess.cpp b/src/rendering/hwrenderer/postprocessing/hw_postprocess.cpp index c692b9809..40102866e 100644 --- a/src/rendering/hwrenderer/postprocessing/hw_postprocess.cpp +++ b/src/rendering/hwrenderer/postprocessing/hw_postprocess.cpp @@ -697,6 +697,10 @@ void PPAmbientOcclusion::Render(PPRenderState *renderstate, float m5, int sceneW ssaoUniforms.Scale = sceneScale; ssaoUniforms.Offset = sceneOffset; + DepthBlurUniforms blurUniforms; + blurUniforms.BlurSharpness = blurSharpness; + blurUniforms.PowExponent = gl_ssao_exponent; + AmbientCombineUniforms combineUniforms; combineUniforms.SampleCount = gl_multisample; combineUniforms.Scale = screen->SceneScale(); @@ -735,11 +739,6 @@ void PPAmbientOcclusion::Render(PPRenderState *renderstate, float m5, int sceneW // Blur SSAO texture if (gl_ssao_debug < 2) { - DepthBlurUniforms blurUniforms; - blurUniforms.BlurSharpness = blurSharpness; - blurUniforms.PowExponent = gl_ssao_exponent; - blurUniforms.InvFullResolution = { 1.0f / AmbientWidth, 0.0f }; - renderstate->Clear(); renderstate->Shader = &BlurHorizontal; renderstate->Uniforms.Set(blurUniforms); @@ -749,8 +748,6 @@ void PPAmbientOcclusion::Render(PPRenderState *renderstate, float m5, int sceneW renderstate->SetNoBlend(); renderstate->Draw(); - blurUniforms.InvFullResolution = { 0.0f, 1.0f / AmbientHeight }; - renderstate->Clear(); renderstate->Shader = &BlurVertical; renderstate->Uniforms.Set(blurUniforms); diff --git a/src/rendering/hwrenderer/postprocessing/hw_postprocess.h b/src/rendering/hwrenderer/postprocessing/hw_postprocess.h index fca4ec77b..7a70ac484 100644 --- a/src/rendering/hwrenderer/postprocessing/hw_postprocess.h +++ b/src/rendering/hwrenderer/postprocessing/hw_postprocess.h @@ -634,7 +634,7 @@ struct DepthBlurUniforms { float BlurSharpness; float PowExponent; - FVector2 InvFullResolution; + float Padding0, Padding1; static std::vector Desc() { @@ -642,7 +642,8 @@ struct DepthBlurUniforms { { "BlurSharpness", UniformType::Float, offsetof(DepthBlurUniforms, BlurSharpness) }, { "PowExponent", UniformType::Float, offsetof(DepthBlurUniforms, PowExponent) }, - { "InvFullResolution", UniformType::Vec2, offsetof(DepthBlurUniforms, InvFullResolution) } + { "Padding0", UniformType::Float, offsetof(DepthBlurUniforms, Padding0) }, + { "Padding1", UniformType::Float, offsetof(DepthBlurUniforms, Padding1) } }; } }; diff --git a/wadsrc/static/shaders/glsl/depthblur.fp b/wadsrc/static/shaders/glsl/depthblur.fp index 299b63694..b337025bc 100644 --- a/wadsrc/static/shaders/glsl/depthblur.fp +++ b/wadsrc/static/shaders/glsl/depthblur.fp @@ -6,42 +6,43 @@ layout(binding=0) uniform sampler2D AODepthTexture; #define KERNEL_RADIUS 3.0 -void main() +void AddSample(vec2 blurSample, float r, float centerDepth, inout float totalAO, inout float totalW) { const float blurSigma = KERNEL_RADIUS * 0.5; const float blurFalloff = 1.0 / (2.0 * blurSigma * blurSigma); - vec2 centerSample = texture(AODepthTexture, TexCoord).xy; + float ao = blurSample.x; + float z = blurSample.y; + float deltaZ = (z - centerDepth) * BlurSharpness; + float w = exp2(-r * r * blurFalloff - deltaZ * deltaZ); + + totalAO += w * ao; + totalW += w; +} + +void main() +{ + vec2 centerSample = textureOffset(AODepthTexture, TexCoord, ivec2( 0, 0)).xy; float centerDepth = centerSample.y; float totalAO = centerSample.x; float totalW = 1.0; - for (float r = 1.0; r <= KERNEL_RADIUS; r += 1.0) - { - vec4 blurSample = texture(AODepthTexture, TexCoord - InvFullResolution * r); - float ao = blurSample.x; - float z = blurSample.y; - - float deltaZ = (z - centerDepth) * BlurSharpness; - float w = exp2(-r * r * blurFalloff - deltaZ * deltaZ); - - totalAO += w * ao; - totalW += w; - } - - 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; - - float deltaZ = (z - centerDepth) * BlurSharpness; - float w = exp2(-r * r * blurFalloff - deltaZ * deltaZ); - - totalAO += w * ao; - totalW += w; - } +#if defined(BLUR_HORIZONTAL) + AddSample(textureOffset(AODepthTexture, TexCoord, ivec2(-3, 0)).xy, 3.0, centerDepth, totalAO, totalW); + AddSample(textureOffset(AODepthTexture, TexCoord, ivec2(-2, 0)).xy, 2.0, centerDepth, totalAO, totalW); + AddSample(textureOffset(AODepthTexture, TexCoord, ivec2(-1, 0)).xy, 1.0, centerDepth, totalAO, totalW); + AddSample(textureOffset(AODepthTexture, TexCoord, ivec2( 1, 0)).xy, 1.0, centerDepth, totalAO, totalW); + AddSample(textureOffset(AODepthTexture, TexCoord, ivec2( 2, 0)).xy, 2.0, centerDepth, totalAO, totalW); + AddSample(textureOffset(AODepthTexture, TexCoord, ivec2( 3, 0)).xy, 3.0, centerDepth, totalAO, totalW); +#else + AddSample(textureOffset(AODepthTexture, TexCoord, ivec2(0, -3)).xy, 3.0, centerDepth, totalAO, totalW); + AddSample(textureOffset(AODepthTexture, TexCoord, ivec2(0, -2)).xy, 2.0, centerDepth, totalAO, totalW); + AddSample(textureOffset(AODepthTexture, TexCoord, ivec2(0, -1)).xy, 1.0, centerDepth, totalAO, totalW); + AddSample(textureOffset(AODepthTexture, TexCoord, ivec2(0, 1)).xy, 1.0, centerDepth, totalAO, totalW); + AddSample(textureOffset(AODepthTexture, TexCoord, ivec2(0, 2)).xy, 2.0, centerDepth, totalAO, totalW); + AddSample(textureOffset(AODepthTexture, TexCoord, ivec2(0, 3)).xy, 3.0, centerDepth, totalAO, totalW); +#endif float fragAO = totalAO / totalW;