From 7e316a130593b3f8080488bb4448ab9ebfb7c4c5 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 31 May 2024 11:35:38 +0200 Subject: [PATCH] Fix SSAO flickering artifacts in cooked game (disable depth mips usage) --- Content/Shaders/SSAO.flax | 4 ++-- Source/Engine/Renderer/AmbientOcclusionPass.cpp | 9 +++++++-- Source/Engine/Renderer/AmbientOcclusionPass.h | 1 + Source/Shaders/SSAO.shader | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Content/Shaders/SSAO.flax b/Content/Shaders/SSAO.flax index 632ee01e3..10eb267c4 100644 --- a/Content/Shaders/SSAO.flax +++ b/Content/Shaders/SSAO.flax @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f2c81b8a794402bd456de39ad3322b21377190a346ba601ce3ba10c762259542 -size 36841 +oid sha256:dc490e550c1aa601647b2caf46a77043ba806f0ced7566777edac2dba1d3a247 +size 36842 diff --git a/Source/Engine/Renderer/AmbientOcclusionPass.cpp b/Source/Engine/Renderer/AmbientOcclusionPass.cpp index 06c4f73f2..f176b2ac2 100644 --- a/Source/Engine/Renderer/AmbientOcclusionPass.cpp +++ b/Source/Engine/Renderer/AmbientOcclusionPass.cpp @@ -214,6 +214,7 @@ void AmbientOcclusionPass::Render(RenderContext& renderContext) return; PROFILE_GPU_CPU("Ambient Occlusion"); + settings = ASSAO_Settings(); settings.Radius = aoSettings.Radius * 0.006f; settings.ShadowMultiplier = aoSettings.Intensity; settings.ShadowPower = aoSettings.Power; @@ -296,8 +297,11 @@ void AmbientOcclusionPass::InitRTs(const RenderContext& renderContext) GPUTextureDescription tempDesc; for (int i = 0; i < 4; i++) { - // TODO: maybe instead of using whole mip chain request only SSAO_DEPTH_MIP_LEVELS? +#if SSAO_DEPTH_MIPS_ENABLE_AT_QUALITY_PRESET < 99 tempDesc = GPUTextureDescription::New2D((int32)m_halfSizeX, (int32)m_halfSizeY, 0, SSAO_DEPTH_FORMAT, GPUTextureFlags::ShaderResource | GPUTextureFlags::RenderTarget | GPUTextureFlags::PerMipViews); +#else + tempDesc = GPUTextureDescription::New2D((int32)m_halfSizeX, (int32)m_halfSizeY, SSAO_DEPTH_FORMAT, GPUTextureFlags::ShaderResource | GPUTextureFlags::RenderTarget); +#endif m_halfDepths[i] = RenderTargetPool::Get(tempDesc); RENDER_TARGET_POOL_SET_NAME(m_halfDepths[i], "SSAO.HalfDepth"); } @@ -334,6 +338,7 @@ void AmbientOcclusionPass::UpdateCB(const RenderContext& renderContext, GPUConte const float farPlane = view.Far; const Matrix& proj = view.Projection; + Platform::MemoryClear(&_constantsBufferData, sizeof(_constantsBufferData)); GBufferPass::SetInputs(view, _constantsBufferData.GBuffer); Matrix::Transpose(view.View, _constantsBufferData.ViewMatrix); @@ -447,7 +452,7 @@ void AmbientOcclusionPass::PrepareDepths(const RenderContext& renderContext) } // Only do mipmaps for higher quality levels (not beneficial on quality level 1, and detrimental on quality level 0) - if (settings.QualityLevel > 1) + if (settings.QualityLevel > 1 && SSAO_DEPTH_MIPS_ENABLE_AT_QUALITY_PRESET < 99) { for (int i = 1; i < SSAO_DEPTH_MIP_LEVELS; i++) { diff --git a/Source/Engine/Renderer/AmbientOcclusionPass.h b/Source/Engine/Renderer/AmbientOcclusionPass.h index d89ad38b4..69fcd211c 100644 --- a/Source/Engine/Renderer/AmbientOcclusionPass.h +++ b/Source/Engine/Renderer/AmbientOcclusionPass.h @@ -6,6 +6,7 @@ // Config #define SSAO_DEPTH_MIP_LEVELS 4 // <- must match shader define +#define SSAO_DEPTH_MIPS_ENABLE_AT_QUALITY_PRESET (99) // <- must match shader define #define SSAO_DEPTH_FORMAT PixelFormat::R16_Float #define SSAO_AO_RESULT_FORMAT PixelFormat::R8G8_UNorm #define SSAO_MAX_BLUR_PASS_COUNT 6 diff --git a/Source/Shaders/SSAO.shader b/Source/Shaders/SSAO.shader index e72d9a30c..206da2bff 100644 --- a/Source/Shaders/SSAO.shader +++ b/Source/Shaders/SSAO.shader @@ -58,7 +58,7 @@ static const uint g_numTaps[4] = { 3, 5, 8, 12 }; // #define SSAO_DETAIL_AO_ENABLE_AT_QUALITY_PRESET (1) // whether to use DetailAOStrength; to disable simply set to 99 or similar // -#define SSAO_DEPTH_MIPS_ENABLE_AT_QUALITY_PRESET (2) // !!warning!! the MIP generation on the C++ side will be enabled on quality preset 2 regardless of this value, so if changing here, change the C++ side too +#define SSAO_DEPTH_MIPS_ENABLE_AT_QUALITY_PRESET (99) // !!warning!! the MIP generation on the C++ side will be enabled on quality preset 2 regardless of this value, so if changing here, change the C++ side too #define SSAO_DEPTH_MIPS_GLOBAL_OFFSET (-4.3) // best noise/quality/performance tradeoff, found empirically // // !!warning!! the edge handling is hard-coded to 'disabled' on quality level 0, and enabled above, on the C++ side; while toggling it here will work for