Skip to content

Commit

Permalink
Fix hit point a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
godlikepanos committed Nov 10, 2024
1 parent 97572d6 commit cce380d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
2 changes: 1 addition & 1 deletion AnKi/Gr/RenderGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/// @}
Expand Down
42 changes: 24 additions & 18 deletions AnKi/Renderer/RtReflections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions AnKi/Renderer/RtReflections.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class RtReflections : public RendererObject
RenderTargetDesc m_transientRtDesc1;
RenderTargetDesc m_transientRtDesc2;
RenderTargetDesc m_hitPosAndDepthRtDesc;
RenderTargetDesc m_hitPosRtDesc;

BufferPtr m_raygenIndirectArgsBuff;

Expand Down
11 changes: 9 additions & 2 deletions AnKi/Shaders/RtReflections.ankiprog
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ Texture2D<Vec4> g_gbufferRt1 : register(t3);
Texture2D<Vec4> g_gbufferRt2 : register(t4);

RWTexture2D<Vec4> g_denoisedTex : register(u0);
RWTexture2D<Vec4> g_hitPosTex : register(u1);

ConstantBuffer<GlobalRendererConstants> g_globalRendererConstants : register(b0);

Expand Down Expand Up @@ -394,10 +395,12 @@ ConstantBuffer<GlobalRendererConstants> 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
{
Expand Down Expand Up @@ -442,10 +445,13 @@ ConstantBuffer<GlobalRendererConstants> 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);
Expand All @@ -455,7 +461,8 @@ ConstantBuffer<GlobalRendererConstants> 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

Expand Down

0 comments on commit cce380d

Please sign in to comment.