-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95d96da
commit 21d6557
Showing
80 changed files
with
543 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
// Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors. | ||
// All rights reserved. | ||
// Code licensed under the BSD License. | ||
// http://www.anki3d.org/LICENSE | ||
|
||
#include <AnKi/Renderer/MotionBlur.h> | ||
#include <AnKi/Renderer/Renderer.h> | ||
#include <AnKi/Renderer/MotionVectors.h> | ||
#include <AnKi/Renderer/TemporalAA.h> | ||
#include <AnKi/Renderer/GBuffer.h> | ||
#include <AnKi/Util/Tracer.h> | ||
|
||
namespace anki { | ||
|
||
Error MotionBlur::init() | ||
{ | ||
ANKI_CHECK(loadShaderProgram("ShaderBinaries/MotionBlur.ankiprogbin", | ||
{{"TILE_SIZE", MutatorValue(g_motionBlurTileSizeCVar)}, {"SAMPLE_COUNT", MutatorValue(g_motionBlurSampleCountCVar)}}, | ||
m_prog, m_maxVelocityGrProg, "MaxTileVelocity")); | ||
ANKI_CHECK(loadShaderProgram("ShaderBinaries/MotionBlur.ankiprogbin", | ||
{{"TILE_SIZE", MutatorValue(g_motionBlurTileSizeCVar)}, {"SAMPLE_COUNT", MutatorValue(g_motionBlurSampleCountCVar)}}, | ||
m_prog, m_maxNeightbourVelocityGrProg, "MaxNeighbourTileVelocity")); | ||
ANKI_CHECK(loadShaderProgram("ShaderBinaries/MotionBlur.ankiprogbin", | ||
{{"TILE_SIZE", MutatorValue(g_motionBlurTileSizeCVar)}, {"SAMPLE_COUNT", MutatorValue(g_motionBlurSampleCountCVar)}}, | ||
m_prog, m_reconstructGrProg, "Reconstruct")); | ||
|
||
const UVec2 tiledTexSize = (getRenderer().getPostProcessResolution() + g_motionBlurTileSizeCVar - 1) / g_motionBlurTileSizeCVar; | ||
m_maxVelocityRtDesc = | ||
getRenderer().create2DRenderTargetDescription(tiledTexSize.x(), tiledTexSize.y(), Format::kR16G16_Sfloat, "MaxTileVelocity"); | ||
m_maxVelocityRtDesc.bake(); | ||
|
||
m_maxNeighbourVelocityRtDesc = | ||
getRenderer().create2DRenderTargetDescription(tiledTexSize.x(), tiledTexSize.y(), Format::kR16G16_Sfloat, "MaxNeighbourTileVelocity"); | ||
m_maxNeighbourVelocityRtDesc.bake(); | ||
|
||
m_finalRtDesc = getRenderer().create2DRenderTargetDescription( | ||
getRenderer().getPostProcessResolution().x(), getRenderer().getPostProcessResolution().y(), | ||
(GrManager::getSingleton().getDeviceCapabilities().m_unalignedBbpTextureFormats) ? Format::kR8G8B8_Unorm : Format::kR8G8B8A8_Unorm, | ||
"MotionBlur"); | ||
m_finalRtDesc.bake(); | ||
|
||
return Error::kNone; | ||
} | ||
|
||
void MotionBlur::populateRenderGraph(RenderingContext& ctx) | ||
{ | ||
ANKI_TRACE_SCOPED_EVENT(MotionBlur); | ||
if(g_motionBlurSampleCountCVar == 0) | ||
{ | ||
m_runCtx.m_rt = {}; | ||
return; | ||
} | ||
|
||
RenderGraphBuilder& rgraph = ctx.m_renderGraphDescr; | ||
|
||
// MaxTileVelocity | ||
const RenderTargetHandle maxVelRt = rgraph.newRenderTarget(m_maxVelocityRtDesc); | ||
{ | ||
NonGraphicsRenderPass& pass = rgraph.newNonGraphicsRenderPass("Motion blur min velocity"); | ||
|
||
pass.newTextureDependency(getRenderer().getMotionVectors().getMotionVectorsRt(), TextureUsageBit::kSrvCompute); | ||
pass.newTextureDependency(maxVelRt, TextureUsageBit::kUavCompute); | ||
|
||
pass.setWork([this, maxVelRt](RenderPassWorkContext& rgraphCtx) { | ||
CommandBuffer& cmdb = *rgraphCtx.m_commandBuffer; | ||
|
||
cmdb.bindShaderProgram(m_maxVelocityGrProg.get()); | ||
|
||
rgraphCtx.bindSrv(0, 0, getRenderer().getMotionVectors().getMotionVectorsRt()); | ||
rgraphCtx.bindUav(0, 0, maxVelRt); | ||
|
||
const UVec2 tiledTexSize = (getRenderer().getPostProcessResolution() + g_motionBlurTileSizeCVar - 1) / g_motionBlurTileSizeCVar; | ||
cmdb.dispatchCompute(tiledTexSize.x(), tiledTexSize.y(), 1); | ||
}); | ||
} | ||
|
||
// MaxNeighbourTileVelocity | ||
const RenderTargetHandle maxNeighbourVelRt = rgraph.newRenderTarget(m_maxNeighbourVelocityRtDesc); | ||
{ | ||
NonGraphicsRenderPass& pass = rgraph.newNonGraphicsRenderPass("Motion blur min neighbour vel"); | ||
|
||
pass.newTextureDependency(maxVelRt, TextureUsageBit::kSrvCompute); | ||
pass.newTextureDependency(maxNeighbourVelRt, TextureUsageBit::kUavCompute); | ||
|
||
pass.setWork([this, maxVelRt, maxNeighbourVelRt](RenderPassWorkContext& rgraphCtx) { | ||
CommandBuffer& cmdb = *rgraphCtx.m_commandBuffer; | ||
|
||
cmdb.bindShaderProgram(m_maxNeightbourVelocityGrProg.get()); | ||
|
||
rgraphCtx.bindSrv(0, 0, maxVelRt); | ||
rgraphCtx.bindUav(0, 0, maxNeighbourVelRt); | ||
|
||
const UVec2 tiledTexSize = (getRenderer().getPostProcessResolution() + g_motionBlurTileSizeCVar - 1) / g_motionBlurTileSizeCVar; | ||
cmdb.dispatchCompute(tiledTexSize.x(), tiledTexSize.y(), 1); | ||
}); | ||
} | ||
|
||
// Recustruct | ||
{ | ||
m_runCtx.m_rt = rgraph.newRenderTarget(m_finalRtDesc); | ||
|
||
TextureUsageBit readUsage, writeUsage; | ||
RenderPassBase* ppass; | ||
if(g_preferComputeCVar) | ||
{ | ||
NonGraphicsRenderPass& pass = rgraph.newNonGraphicsRenderPass("Motion blur reconstruct"); | ||
ppass = &pass; | ||
readUsage = TextureUsageBit::kSrvCompute; | ||
writeUsage = TextureUsageBit::kUavCompute; | ||
} | ||
else | ||
{ | ||
GraphicsRenderPass& pass = rgraph.newGraphicsRenderPass("Motion blur reconstruct"); | ||
pass.setRenderpassInfo({m_runCtx.m_rt}); | ||
ppass = &pass; | ||
readUsage = TextureUsageBit::kSrvPixel; | ||
writeUsage = TextureUsageBit::kRtvDsvWrite; | ||
} | ||
|
||
ppass->newTextureDependency(getRenderer().getTemporalAA().getTonemappedRt(), readUsage); | ||
ppass->newTextureDependency(getRenderer().getGBuffer().getDepthRt(), readUsage); | ||
ppass->newTextureDependency(maxNeighbourVelRt, readUsage); | ||
ppass->newTextureDependency(getRenderer().getMotionVectors().getMotionVectorsRt(), readUsage); | ||
ppass->newTextureDependency(m_runCtx.m_rt, writeUsage); | ||
|
||
ppass->setWork([this, maxNeighbourVelRt, &ctx](RenderPassWorkContext& rgraphCtx) { | ||
CommandBuffer& cmdb = *rgraphCtx.m_commandBuffer; | ||
|
||
cmdb.bindShaderProgram(m_reconstructGrProg.get()); | ||
|
||
rgraphCtx.bindSrv(0, 0, getRenderer().getTemporalAA().getTonemappedRt()); | ||
rgraphCtx.bindSrv(1, 0, getRenderer().getGBuffer().getDepthRt()); | ||
rgraphCtx.bindSrv(2, 0, maxNeighbourVelRt); | ||
rgraphCtx.bindSrv(3, 0, getRenderer().getMotionVectors().getMotionVectorsRt()); | ||
|
||
cmdb.bindSampler(0, 0, getRenderer().getSamplers().m_trilinearClamp.get()); | ||
|
||
class Constants | ||
{ | ||
public: | ||
Vec2 m_depthLinearizationParams; | ||
U32 m_frame; | ||
F32 m_far; | ||
} consts; | ||
consts.m_depthLinearizationParams.x() = (ctx.m_cameraNear - ctx.m_cameraFar) / ctx.m_cameraNear; | ||
consts.m_depthLinearizationParams.y() = ctx.m_cameraFar / ctx.m_cameraNear; | ||
consts.m_frame = getRenderer().getFrameCount() % 32; | ||
consts.m_far = ctx.m_cameraFar; | ||
cmdb.setFastConstants(&consts, sizeof(consts)); | ||
|
||
if(g_preferComputeCVar) | ||
{ | ||
rgraphCtx.bindUav(0, 0, m_runCtx.m_rt); | ||
dispatchPPCompute(cmdb, 8, 8, getRenderer().getPostProcessResolution().x(), getRenderer().getPostProcessResolution().y()); | ||
} | ||
else | ||
{ | ||
cmdb.setViewport(0, 0, getRenderer().getPostProcessResolution().x(), getRenderer().getPostProcessResolution().y()); | ||
drawQuad(cmdb); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
} // end namespace anki |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors. | ||
// All rights reserved. | ||
// Code licensed under the BSD License. | ||
// http://www.anki3d.org/LICENSE | ||
|
||
#pragma once | ||
|
||
#include <AnKi/Renderer/RendererObject.h> | ||
|
||
namespace anki { | ||
|
||
/// @addtogroup renderer | ||
/// @{ | ||
|
||
inline NumericCVar<U32> g_motionBlurTileSizeCVar("R", "MotionBlurTileSize", 32, 8, 64, "Motion blur tile size"); | ||
inline NumericCVar<U32> g_motionBlurSampleCountCVar("R", "MotionBlurSampleCount", 16, 0, 64, "Motion blur sample count"); | ||
|
||
/// Motion blur. | ||
class MotionBlur : public RendererObject | ||
{ | ||
public: | ||
MotionBlur() | ||
{ | ||
registerDebugRenderTarget("MotionBlur"); | ||
} | ||
|
||
Error init(); | ||
|
||
void populateRenderGraph(RenderingContext& ctx); | ||
|
||
void getDebugRenderTarget([[maybe_unused]] CString rtName, Array<RenderTargetHandle, kMaxDebugRenderTargets>& handles, | ||
[[maybe_unused]] ShaderProgramPtr& optionalShaderProgram) const override | ||
{ | ||
ANKI_ASSERT(rtName == "MotionBlur"); | ||
handles[0] = m_runCtx.m_rt; | ||
} | ||
|
||
RenderTargetHandle getRt() const | ||
{ | ||
return m_runCtx.m_rt; | ||
} | ||
|
||
private: | ||
ShaderProgramResourcePtr m_prog; | ||
ShaderProgramPtr m_maxVelocityGrProg; | ||
ShaderProgramPtr m_maxNeightbourVelocityGrProg; | ||
ShaderProgramPtr m_reconstructGrProg; | ||
|
||
RenderTargetDesc m_maxVelocityRtDesc; | ||
RenderTargetDesc m_maxNeighbourVelocityRtDesc; | ||
RenderTargetDesc m_finalRtDesc; | ||
|
||
class | ||
{ | ||
public: | ||
RenderTargetHandle m_rt; | ||
} m_runCtx; | ||
}; | ||
/// @} | ||
|
||
} // end namespace anki |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.