Remove TAA and Motion Blur implementations

This commit is contained in:
Wojtek Figat
2020-12-22 18:07:53 +01:00
parent 4fe91d57b7
commit cf0aeb79bf
9 changed files with 26 additions and 827 deletions

View File

@@ -12,7 +12,7 @@
bool TAA::Init()
{
// Create pipeline state
_psTAA.CreatePipelineStates();
//_psTAA.CreatePipelineStates();
// Load shader
_shader = Content::LoadAsyncInternal<Shader>(TEXT("Shaders/TAA"));
@@ -34,22 +34,6 @@ bool TAA::setupResources()
}
const auto shader = _shader->GetShader();
// Validate shader constant buffer size
if (shader->GetCB(0)->GetSize() != sizeof(Data))
{
REPORT_INVALID_SHADER_PASS_CB_SIZE(shader, 0, Data);
return true;
}
// Create pipeline state
GPUPipelineState::Description psDesc;
if (!_psTAA.IsValid())
{
psDesc = GPUPipelineState::Description::DefaultFullscreenTriangle;
if (_psTAA.Create(psDesc, shader, "PS"))
return true;
}
return false;
}
@@ -58,10 +42,7 @@ void TAA::Dispose()
// Base
RendererPass::Dispose();
// Delete pipeline state
_psTAA.Delete();
// Release asset
_psTAA = nullptr;
_shader.Unlink();
}
@@ -75,7 +56,7 @@ void TAA::Render(RenderContext& renderContext, GPUTexture* input, GPUTextureView
auto context = GPUDevice::Instance->GetMainContext();
// Ensure to have valid data
if (checkIfSkipPass())
//if (checkIfSkipPass())
{
// Resources are missing. Do not perform rendering, just copy source frame.
context->SetRenderTarget(output);
@@ -119,32 +100,5 @@ void TAA::Render(RenderContext& renderContext, GPUTexture* input, GPUTextureView
blendStrength = 0.0f;
}
// Bind input
Data data;
data.ScreenSize = renderContext.View.ScreenSize;
data.TaaJitterStrength.X = renderContext.View.TemporalAAJitter.X;
data.TaaJitterStrength.Y = renderContext.View.TemporalAAJitter.Y;
data.TaaJitterStrength.Z = data.TaaJitterStrength.X / tempDesc.Width;
data.TaaJitterStrength.W = data.TaaJitterStrength.Y / tempDesc.Height;
data.FinalBlendParameters.X = settings.TAA_StationaryBlending * blendStrength;
data.FinalBlendParameters.Y = settings.TAA_MotionBlending * blendStrength;
data.FinalBlendParameters.Z = 100.0f * 60.0f;
data.FinalBlendParameters.W = settings.TAA_Sharpness;
const auto cb = _shader->GetShader()->GetCB(0);
context->UpdateCB(cb, &data);
context->BindCB(0, cb);
context->BindSR(0, input);
context->BindSR(1, inputHistory);
context->BindSR(2, renderContext.Buffers->MotionVectors);
context->BindSR(3, renderContext.Buffers->DepthBuffer);
// Render
GPUTextureView* rts[] = { output, outputHistory->View() };
context->SetRenderTarget(nullptr, ToSpan(rts, ARRAY_COUNT(rts)));
context->SetState(_psTAA.Get(renderContext.View.IsOrthographicProjection() ? 1 : 0));
context->DrawFullscreenTriangle();
// Swap the history
RenderTargetPool::Release(inputHistory);
renderContext.Buffers->TemporalAA = outputHistory;
// ...
}

View File

@@ -12,15 +12,8 @@ class TAA : public RendererPass<TAA>
{
private:
PACK_STRUCT(struct Data
{
Vector4 ScreenSize;
Vector4 TaaJitterStrength;
Vector4 FinalBlendParameters;
});
AssetReference<Shader> _shader;
GPUPipelineStatePermutationsPs<2> _psTAA;
GPUPipelineState* _psTAA;
public:
@@ -44,7 +37,7 @@ private:
#if COMPILE_WITH_DEV_ENV
void OnShaderReloading(Asset* obj)
{
_psTAA.Release();
_psTAA = nullptr;
invalidateResources();
}
#endif

View File

@@ -11,19 +11,16 @@
#include "Engine/Graphics/RenderTargetPool.h"
#include "Engine/Graphics/RenderBuffers.h"
PACK_STRUCT(struct Data {
GBufferData GBuffer;
Matrix CurrentVP;
Matrix PreviousVP;
Vector4 TemporalAAJitter;
});
MotionBlurPass::MotionBlurPass()
: _motionVectorsFormat(PixelFormat::Unknown)
, _velocityFormat(PixelFormat::Unknown)
, _psCameraMotionVectors(nullptr)
, _psMotionVectorsDebug(nullptr)
, _psMotionVectorsDebugArrow(nullptr)
, _psVelocitySetup(nullptr)
, _psTileMax1(nullptr)
, _psTileMax2(nullptr)
, _psTileMax4(nullptr)
, _psTileMaxV(nullptr)
, _psNeighborMax(nullptr)
, _psReconstruction(nullptr)
{
}
@@ -36,15 +33,6 @@ bool MotionBlurPass::Init()
{
// Create pipeline state
_psCameraMotionVectors = GPUDevice::Instance->CreatePipelineState();
_psMotionVectorsDebug = GPUDevice::Instance->CreatePipelineState();
_psMotionVectorsDebugArrow = GPUDevice::Instance->CreatePipelineState();
_psVelocitySetup = GPUDevice::Instance->CreatePipelineState();
_psTileMax1 = GPUDevice::Instance->CreatePipelineState();
_psTileMax2 = GPUDevice::Instance->CreatePipelineState();
_psTileMax4 = GPUDevice::Instance->CreatePipelineState();
_psTileMaxV = GPUDevice::Instance->CreatePipelineState();
_psNeighborMax = GPUDevice::Instance->CreatePipelineState();
_psReconstruction = GPUDevice::Instance->CreatePipelineState();
// Load shader
_shader = Content::LoadAsyncInternal<Shader>(TEXT("Shaders/MotionBlur"));
@@ -98,62 +86,6 @@ bool MotionBlurPass::setupResources()
if (_psCameraMotionVectors->Init(psDesc))
return true;
}
if (!_psVelocitySetup->IsValid())
{
psDesc.PS = shader->GetPS("PS_VelocitySetup");
if (_psVelocitySetup->Init(psDesc))
return true;
}
if (!_psTileMax1->IsValid())
{
psDesc.PS = shader->GetPS("PS_TileMax1");
if (_psTileMax1->Init(psDesc))
return true;
}
if (!_psTileMax2->IsValid())
{
psDesc.PS = shader->GetPS("PS_TileMax2");
if (_psTileMax2->Init(psDesc))
return true;
}
if (!_psTileMax4->IsValid())
{
psDesc.PS = shader->GetPS("PS_TileMax4");
if (_psTileMax4->Init(psDesc))
return true;
}
if (!_psTileMaxV->IsValid())
{
psDesc.PS = shader->GetPS("PS_TileMaxV");
if (_psTileMaxV->Init(psDesc))
return true;
}
if (!_psNeighborMax->IsValid())
{
psDesc.PS = shader->GetPS("PS_NeighborMax");
if (_psNeighborMax->Init(psDesc))
return true;
}
if (!_psReconstruction->IsValid())
{
psDesc.PS = shader->GetPS("PS_Reconstruction");
if (_psReconstruction->Init(psDesc))
return true;
}
if (!_psMotionVectorsDebug->IsValid())
{
psDesc.PS = shader->GetPS("PS_MotionVectorsDebug");
if (_psMotionVectorsDebug->Init(psDesc))
return true;
}
if (!_psMotionVectorsDebugArrow->IsValid())
{
psDesc.PrimitiveTopologyType = PrimitiveTopologyType::Line;
psDesc.VS = shader->GetVS("VS_DebugArrow");
psDesc.PS = shader->GetPS("PS_DebugArrow");
if (_psMotionVectorsDebugArrow->Init(psDesc))
return true;
}
return false;
}
@@ -165,15 +97,6 @@ void MotionBlurPass::Dispose()
// Delete pipeline state
SAFE_DELETE_GPU_RESOURCE(_psCameraMotionVectors);
SAFE_DELETE_GPU_RESOURCE(_psMotionVectorsDebug);
SAFE_DELETE_GPU_RESOURCE(_psMotionVectorsDebugArrow);
SAFE_DELETE_GPU_RESOURCE(_psVelocitySetup);
SAFE_DELETE_GPU_RESOURCE(_psTileMax1);
SAFE_DELETE_GPU_RESOURCE(_psTileMax2);
SAFE_DELETE_GPU_RESOURCE(_psTileMax4);
SAFE_DELETE_GPU_RESOURCE(_psTileMaxV);
SAFE_DELETE_GPU_RESOURCE(_psNeighborMax);
SAFE_DELETE_GPU_RESOURCE(_psReconstruction);
// Release asset
_shader.Unlink();
@@ -275,39 +198,13 @@ void MotionBlurPass::RenderDebug(RenderContext& renderContext, GPUTextureView* f
{
auto context = GPUDevice::Instance->GetMainContext();
const auto motionVectors = renderContext.Buffers->MotionVectors;
if (!motionVectors->IsAllocated() || setupResources())
//if (!motionVectors->IsAllocated() || setupResources())
{
context->Draw(frame);
return;
}
PROFILE_GPU_CPU("Motion Vectors Debug");
// Bind input
Data data;
GBufferPass::SetInputs(renderContext.View, data.GBuffer);
const float rows = 16.0f;
const float cols = rows * renderContext.Buffers->GetWidth() / renderContext.Buffers->GetHeight();
data.DebugBlend = 0.7f;
data.DebugAmplitude = 2.0f;
data.DebugRowCount = static_cast<int32>(rows);
data.DebugColumnCount = static_cast<int32>(cols);
auto cb = _shader->GetShader()->GetCB(0);
context->UpdateCB(cb, &data);
context->BindCB(0, cb);
context->BindSR(0, frame);
context->BindSR(1, renderContext.Buffers->MotionVectors);
// Draw motion gradient
context->SetState(_psMotionVectorsDebug);
context->DrawFullscreenTriangle();
// Draw arrows
context->SetState(_psMotionVectorsDebugArrow);
context->Draw(0, static_cast<uint32>(cols * rows * 6));
// Cleanup
context->ResetSR();
// ..
}
void MotionBlurPass::Render(RenderContext& renderContext, GPUTexture*& input, GPUTexture*& output)
@@ -335,128 +232,5 @@ void MotionBlurPass::Render(RenderContext& renderContext, GPUTexture*& input, GP
return;
}
// Need to have valid motion vectors created and rendered before
ASSERT(motionVectors->IsAllocated());
PROFILE_GPU_CPU("Motion Blur");
// Calculate the maximum blur radius in pixels
const float maxBlurRadius = 5.0f;
const int32 maxBlurPixels = static_cast<int32>(maxBlurRadius * motionVectorsHeight / 100.0f);
// Calculate the TileMax size (it should be a multiple of 8 and larger than maxBlur)
const int32 tileSize = ((maxBlurPixels - 1) / 8 + 1) * 8;
// Bind input
Data data;
GBufferPass::SetInputs(renderContext.View, data.GBuffer);
Matrix::Transpose(renderContext.View.ViewProjection(), data.CurrentVP);
Matrix::Transpose(renderContext.View.PrevViewProjection, data.PreviousVP);
data.TemporalAAJitter = renderContext.View.TemporalAAJitter;
data.VelocityScale = settings.Scale;
data.MaxBlurRadius = static_cast<float>(maxBlurPixels);
data.RcpMaxBlurRadius = 1.0f / maxBlurPixels;
data.TileMaxOffs = Vector2::One * (tileSize / 8.0f - 1.0f) * -0.5f;
data.TileMaxLoop = static_cast<int32>(tileSize / 8.0f);
data.LoopCount = Math::Clamp(settings.SampleCount / 2.0f, 1.0f, 64.0f);
const float invWidth = 1.0f / motionVectorsWidth;
const float invHeight = 1.0f / motionVectorsHeight;
data.TexelSize1 = Vector2(invWidth, invHeight);
data.TexelSize2 = Vector2(invWidth * 2.0f, invHeight * 2.0f);
data.TexelSize4 = Vector2(invWidth * 4.0f, invHeight * 4.0f);
data.TexelSizeV = Vector2(invWidth * 8.0f, invHeight * 8.0f);
data.TexelSizeNM = Vector2(invWidth * tileSize, invHeight * tileSize);
data.MotionVectorsTexelSize = Vector2(1.0f / motionVectorsWidth, invHeight * tileSize);
auto cb = _shader->GetShader()->GetCB(0);
context->UpdateCB(cb, &data);
context->BindCB(0, cb);
context->BindSR(0, renderContext.Buffers->DepthBuffer);
auto rtDesc = GPUTextureDescription::New2D(motionVectorsWidth, motionVectorsHeight, _velocityFormat);
// Pass 1 - Velocity/depth packing
auto vBuffer = RenderTargetPool::Get(rtDesc);
context->SetRenderTarget(*vBuffer);
context->SetViewportAndScissors((float)rtDesc.Width, (float)rtDesc.Height);
context->BindSR(0, motionVectors->View());
context->BindSR(1, renderContext.Buffers->DepthBuffer->View());
context->SetState(_psVelocitySetup);
context->DrawFullscreenTriangle();
context->UnBindSR(1);
// Pass 2 - First TileMax filter (1/2 downsize)
rtDesc.Format = _motionVectorsFormat;
rtDesc.Width = motionVectorsWidth / 2;
rtDesc.Height = motionVectorsHeight / 2;
auto tile2 = RenderTargetPool::Get(rtDesc);
context->ResetRenderTarget();
context->SetRenderTarget(tile2->View());
context->SetViewportAndScissors((float)rtDesc.Width, (float)rtDesc.Height);
context->BindSR(0, vBuffer->View());
context->SetState(_psTileMax1);
context->DrawFullscreenTriangle();
// Pass 3 - Second TileMax filter (1/4 downsize)
rtDesc.Width = motionVectorsWidth / 4;
rtDesc.Height = motionVectorsHeight / 4;
auto tile4 = RenderTargetPool::Get(rtDesc);
context->ResetRenderTarget();
context->SetRenderTarget(tile4->View());
context->SetViewportAndScissors((float)rtDesc.Width, (float)rtDesc.Height);
context->BindSR(0, tile2->View());
context->SetState(_psTileMax2);
context->DrawFullscreenTriangle();
RenderTargetPool::Release(tile2);
// Pass 4 - Third TileMax filter (1/8 downsize)
rtDesc.Width = motionVectorsWidth / 8;
rtDesc.Height = motionVectorsHeight / 8;
auto tile8 = RenderTargetPool::Get(rtDesc);
context->ResetRenderTarget();
context->SetRenderTarget(tile8->View());
context->SetViewportAndScissors((float)rtDesc.Width, (float)rtDesc.Height);
context->BindSR(0, tile4->View());
context->SetState(_psTileMax4);
context->DrawFullscreenTriangle();
RenderTargetPool::Release(tile4);
// Pass 5 - Fourth TileMax filter (reduce to tileSize)
rtDesc.Width = motionVectorsWidth / tileSize;
rtDesc.Height = motionVectorsHeight / tileSize;
auto tile = RenderTargetPool::Get(rtDesc);
context->ResetRenderTarget();
context->SetRenderTarget(tile->View());
context->SetViewportAndScissors((float)rtDesc.Width, (float)rtDesc.Height);
context->BindSR(0, tile8->View());
context->SetState(_psTileMaxV);
context->DrawFullscreenTriangle();
RenderTargetPool::Release(tile8);
// Pass 6 - NeighborMax filter
rtDesc.Width = motionVectorsWidth / tileSize;
rtDesc.Height = motionVectorsHeight / tileSize;
auto neighborMax = RenderTargetPool::Get(rtDesc);
context->ResetRenderTarget();
context->SetRenderTarget(neighborMax->View());
context->SetViewportAndScissors((float)rtDesc.Width, (float)rtDesc.Height);
context->BindSR(0, tile->View());
context->SetState(_psNeighborMax);
context->DrawFullscreenTriangle();
RenderTargetPool::Release(tile);
// Pass 7 - Reconstruction pass
context->ResetRenderTarget();
context->SetRenderTarget(*output);
context->SetViewportAndScissors((float)screenWidth, (float)screenHeight);
context->BindSR(0, input->View());
context->BindSR(1, vBuffer->View());
context->BindSR(2, neighborMax->View());
context->SetState(_psReconstruction);
context->DrawFullscreenTriangle();
// Cleanup
context->ResetSR();
context->ResetRenderTarget();
RenderTargetPool::Release(vBuffer);
RenderTargetPool::Release(neighborMax);
Swap(output, input);
// ..
}

View File

@@ -10,43 +10,11 @@
class MotionBlurPass : public RendererPass<MotionBlurPass>
{
private:
PACK_STRUCT(struct Data {
GBufferData GBuffer;
Matrix CurrentVP;
Matrix PreviousVP;
Vector4 TemporalAAJitter;
Vector2 TileMaxOffs;
float VelocityScale;
int32 TileMaxLoop;
float MaxBlurRadius;
float RcpMaxBlurRadius;
Vector2 TexelSize1;
Vector2 TexelSize2;
Vector2 TexelSize4;
Vector2 TexelSizeV;
Vector2 TexelSizeNM;
float LoopCount;
float Dummy0;
Vector2 MotionVectorsTexelSize;
float DebugBlend;
float DebugAmplitude;
int32 DebugColumnCount;
int32 DebugRowCount;
});
PixelFormat _motionVectorsFormat;
PixelFormat _velocityFormat;
AssetReference<Shader> _shader;
GPUPipelineState* _psCameraMotionVectors;
GPUPipelineState* _psMotionVectorsDebug;
GPUPipelineState* _psMotionVectorsDebugArrow;
GPUPipelineState* _psVelocitySetup;
GPUPipelineState* _psTileMax1;
GPUPipelineState* _psTileMax2;
GPUPipelineState* _psTileMax4;
GPUPipelineState* _psTileMaxV;
GPUPipelineState* _psNeighborMax;
GPUPipelineState* _psReconstruction;
GPUPipelineState* _psCameraMotionVectors = nullptr;
public:
@@ -84,15 +52,6 @@ private:
void OnShaderReloading(Asset* obj)
{
_psCameraMotionVectors->ReleaseGPU();
_psMotionVectorsDebug->ReleaseGPU();
_psMotionVectorsDebugArrow->ReleaseGPU();
_psVelocitySetup->ReleaseGPU();
_psTileMax1->ReleaseGPU();
_psTileMax2->ReleaseGPU();
_psTileMax4->ReleaseGPU();
_psTileMaxV->ReleaseGPU();
_psNeighborMax->ReleaseGPU();
_psReconstruction->ReleaseGPU();
invalidateResources();
}
#endif

View File

@@ -306,6 +306,7 @@ void RenderInner(SceneRenderTask* task, RenderContext& renderContext)
#endif
renderContext.List->Settings.AntiAliasing.Mode = aaMode;
// Prepare
renderContext.View.Prepare(renderContext);
renderContext.Buffers->Prepare();
@@ -484,7 +485,8 @@ void RenderInner(SceneRenderTask* task, RenderContext& renderContext)
context->ResetRenderTarget();
context->SetRenderTarget(task->GetOutputView());
context->SetViewportAndScissors((float)renderContext.Buffers->GetWidth(), (float)renderContext.Buffers->GetHeight());
MotionBlurPass::Instance()->RenderDebug(renderContext, frameBuffer->View());
context->Clear(frameBuffer->View(), Color::Black);
//MotionBlurPass::Instance()->RenderDebug(renderContext, frameBuffer->View());
return;
}