From cce380d17abdabb471a2e9e9a08be2864da57d71 Mon Sep 17 00:00:00 2001 From: Panagiotis Christopoulos Charitos Date: Sun, 10 Nov 2024 15:26:11 +0100 Subject: [PATCH] Fix hit point a bit --- AnKi/Gr/RenderGraph.h | 2 +- AnKi/Renderer/RtReflections.cpp | 42 ++++++++++++++++------------- AnKi/Renderer/RtReflections.h | 1 + AnKi/Shaders/RtReflections.ankiprog | 11 ++++++-- 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/AnKi/Gr/RenderGraph.h b/AnKi/Gr/RenderGraph.h index 353262a3d..c7b008b5c 100644 --- a/AnKi/Gr/RenderGraph.h +++ b/AnKi/Gr/RenderGraph.h @@ -28,7 +28,7 @@ class RenderGraphBuilder; /// @name RenderGraph constants /// @{ constexpr U32 kMaxRenderGraphPasses = 512; -constexpr U32 kMaxRenderGraphRenderTargets = 64; ///< Max imported or not render targets in RenderGraph. +constexpr U32 kMaxRenderGraphRenderTargets = 128; ///< Max imported or not render targets in RenderGraph. constexpr U32 kMaxRenderGraphBuffers = 256; constexpr U32 kMaxRenderGraphAccelerationStructures = 32; /// @} diff --git a/AnKi/Renderer/RtReflections.cpp b/AnKi/Renderer/RtReflections.cpp index b8de789d3..9c9eead49 100644 --- a/AnKi/Renderer/RtReflections.cpp +++ b/AnKi/Renderer/RtReflections.cpp @@ -64,6 +64,10 @@ Error RtReflections::init() getRenderer().getInternalResolution().x(), getRenderer().getInternalResolution().y(), Format::kR16G16B16A16_Sfloat, "HitPosAndDepth"); m_hitPosAndDepthRtDesc.bake(); + m_hitPosRtDesc = getRenderer().create2DRenderTargetDescription(getRenderer().getInternalResolution().x(), + getRenderer().getInternalResolution().y(), Format::kR16G16B16A16_Sfloat, "HitPos"); + m_hitPosRtDesc.bake(); + TextureInitInfo texInit = getRenderer().create2DRenderTargetDescription( getRenderer().getInternalResolution().x(), getRenderer().getInternalResolution().y(), getRenderer().getHdrFormat(), "RtReflectionsMain"); texInit.m_usage = TextureUsageBit::kAllShaderResource | TextureUsageBit::kAllUav; @@ -125,6 +129,7 @@ void RtReflections::populateRenderGraph(RenderingContext& ctx) const RenderTargetHandle transientRt1 = rgraph.newRenderTarget(m_transientRtDesc1); const RenderTargetHandle transientRt2 = rgraph.newRenderTarget(m_transientRtDesc2); const RenderTargetHandle hitPosAndDepthRt = rgraph.newRenderTarget(m_hitPosAndDepthRtDesc); + const RenderTargetHandle hitPosRt = rgraph.newRenderTarget(m_hitPosRtDesc); BufferHandle visibilityDep; BufferView visibleRenderableIndicesBuff, buildSbtIndirectArgsBuff; @@ -304,8 +309,9 @@ void RtReflections::populateRenderGraph(RenderingContext& ctx) rpass.newTextureDependency(getRenderer().getGBuffer().getColorRt(2), TextureUsageBit::kSrvCompute); rpass.newTextureDependency(transientRt2, TextureUsageBit::kUavCompute); + rpass.newTextureDependency(hitPosRt, TextureUsageBit::kUavCompute); - rpass.setWork([this, &ctx, transientRt1, transientRt2, hitPosAndDepthRt](RenderPassWorkContext& rgraphCtx) { + rpass.setWork([this, &ctx, transientRt1, transientRt2, hitPosAndDepthRt, hitPosRt](RenderPassWorkContext& rgraphCtx) { ANKI_TRACE_SCOPED_EVENT(RtShadows); CommandBuffer& cmdb = *rgraphCtx.m_commandBuffer; @@ -319,6 +325,7 @@ void RtReflections::populateRenderGraph(RenderingContext& ctx) rgraphCtx.bindSrv(4, 0, getRenderer().getGBuffer().getColorRt(2)); rgraphCtx.bindUav(0, 0, transientRt2); + rgraphCtx.bindUav(1, 0, hitPosRt); cmdb.bindConstantBuffer(0, 0, ctx.m_globalRenderingConstantsBuffer); @@ -334,34 +341,33 @@ void RtReflections::populateRenderGraph(RenderingContext& ctx) rpass.newTextureDependency(mainRt, TextureUsageBit::kSrvCompute); rpass.newTextureDependency(readMomentsRt, TextureUsageBit::kSrvCompute); rpass.newTextureDependency(getRenderer().getMotionVectors().getMotionVectorsRt(), TextureUsageBit::kSrvCompute); - rpass.newTextureDependency(hitPosAndDepthRt, TextureUsageBit::kSrvCompute); + rpass.newTextureDependency(hitPosRt, TextureUsageBit::kSrvCompute); rpass.newTextureDependency(transientRt1, TextureUsageBit::kUavCompute); rpass.newTextureDependency(writeMomentsRt, TextureUsageBit::kUavCompute); - rpass.setWork( - [this, &ctx, transientRt1, transientRt2, mainRt, readMomentsRt, writeMomentsRt, hitPosAndDepthRt](RenderPassWorkContext& rgraphCtx) { - ANKI_TRACE_SCOPED_EVENT(RtShadows); + rpass.setWork([this, &ctx, transientRt1, transientRt2, mainRt, readMomentsRt, writeMomentsRt, hitPosRt](RenderPassWorkContext& rgraphCtx) { + ANKI_TRACE_SCOPED_EVENT(RtShadows); - CommandBuffer& cmdb = *rgraphCtx.m_commandBuffer; + CommandBuffer& cmdb = *rgraphCtx.m_commandBuffer; - cmdb.bindShaderProgram(m_temporalDenoisingGrProg.get()); + cmdb.bindShaderProgram(m_temporalDenoisingGrProg.get()); - cmdb.bindSampler(0, 0, getRenderer().getSamplers().m_trilinearClamp.get()); + cmdb.bindSampler(0, 0, getRenderer().getSamplers().m_trilinearClamp.get()); - rgraphCtx.bindSrv(0, 0, transientRt2); - rgraphCtx.bindSrv(1, 0, mainRt); - rgraphCtx.bindSrv(2, 0, readMomentsRt); - rgraphCtx.bindSrv(3, 0, getRenderer().getMotionVectors().getMotionVectorsRt()); - rgraphCtx.bindSrv(4, 0, hitPosAndDepthRt); + rgraphCtx.bindSrv(0, 0, transientRt2); + rgraphCtx.bindSrv(1, 0, mainRt); + rgraphCtx.bindSrv(2, 0, readMomentsRt); + rgraphCtx.bindSrv(3, 0, getRenderer().getMotionVectors().getMotionVectorsRt()); + rgraphCtx.bindSrv(4, 0, hitPosRt); - rgraphCtx.bindUav(0, 0, transientRt1); - rgraphCtx.bindUav(1, 0, writeMomentsRt); + rgraphCtx.bindUav(0, 0, transientRt1); + rgraphCtx.bindUav(1, 0, writeMomentsRt); - cmdb.bindConstantBuffer(0, 0, ctx.m_globalRenderingConstantsBuffer); + cmdb.bindConstantBuffer(0, 0, ctx.m_globalRenderingConstantsBuffer); - dispatchPPCompute(cmdb, 8, 8, getRenderer().getInternalResolution().x(), getRenderer().getInternalResolution().y()); - }); + dispatchPPCompute(cmdb, 8, 8, getRenderer().getInternalResolution().x(), getRenderer().getInternalResolution().y()); + }); } // Hotizontal bilateral filter diff --git a/AnKi/Renderer/RtReflections.h b/AnKi/Renderer/RtReflections.h index 9c82dc2fb..7d06186b9 100644 --- a/AnKi/Renderer/RtReflections.h +++ b/AnKi/Renderer/RtReflections.h @@ -53,6 +53,7 @@ class RtReflections : public RendererObject RenderTargetDesc m_transientRtDesc1; RenderTargetDesc m_transientRtDesc2; RenderTargetDesc m_hitPosAndDepthRtDesc; + RenderTargetDesc m_hitPosRtDesc; BufferPtr m_raygenIndirectArgsBuff; diff --git a/AnKi/Shaders/RtReflections.ankiprog b/AnKi/Shaders/RtReflections.ankiprog index 3f3404078..c22c21426 100644 --- a/AnKi/Shaders/RtReflections.ankiprog +++ b/AnKi/Shaders/RtReflections.ankiprog @@ -359,6 +359,7 @@ Texture2D g_gbufferRt1 : register(t3); Texture2D g_gbufferRt2 : register(t4); RWTexture2D g_denoisedTex : register(u0); +RWTexture2D g_hitPosTex : register(u1); ConstantBuffer g_globalRendererConstants : register(b0); @@ -394,10 +395,12 @@ ConstantBuffer g_globalRendererConstants : register(b0) const F32 alpha = pow2(roughness); Vec3 outColor = 0.0; + Vec3 newHitPos = 0.0; if(roughness <= kMinRoughness + kEpsilonF32) { outColor = color; + newHitPos = g_hitPosAndDepthTex[coord].xyz + g_globalRendererConstants.m_cameraPosition; } else { @@ -442,10 +445,13 @@ ConstantBuffer g_globalRendererConstants : register(b0) outColor += sampleColor * weight; weightSum += weight; avgLuma += computeLuminance(sampleColor) / sampleCount; + + newHitPos += hitPos * weight; } } - outColor = outColor / weightSum; + outColor /= weightSum; + newHitPos /= weightSum; // Remove fireflies const F32 luma = computeLuminance(outColor); @@ -455,7 +461,8 @@ ConstantBuffer g_globalRendererConstants : register(b0) } } - g_denoisedTex[svDispatchThreadId] = Vec4(outColor, 1.0 - depth); // Store depth in reverse for better precision + g_denoisedTex[coord] = Vec4(outColor, 1.0 - depth); // Store depth in reverse for better precision + g_hitPosTex[coord] = Vec4(newHitPos - g_globalRendererConstants.m_cameraPosition, 0.0); } #endif // ANKI_COMPUTE_SHADER && ANKI_TECHNIQUE_SpatialDenoise