Skip to content

Commit

Permalink
Traktor: Rewrote TAA; a lot cheaper and visually stable.
Browse files Browse the repository at this point in the history
  • Loading branch information
apistol78 committed Mar 7, 2024
1 parent 98df26e commit 6c69a41
Show file tree
Hide file tree
Showing 11 changed files with 337 additions and 2,279 deletions.
5 changes: 2 additions & 3 deletions code/World/Shared/Passes/PostProcessPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void PostProcessPass::setup(
uint32_t frameCount,
render::RenderGraph& renderGraph,
render::handle_t gbufferTargetSetId,
const DoubleBufferedTarget& velocityTargetSetId,
render::handle_t velocityTargetSetId,
const DoubleBufferedTarget& visualTargetSetId,
render::handle_t outputTargetSetId
) const
Expand All @@ -192,8 +192,7 @@ void PostProcessPass::setup(
igctx.associateTextureTargetSet(s_handleInputColorLast, visualTargetSetId.previous, 0);
igctx.associateTextureTargetSet(s_handleInputDepth, gbufferTargetSetId, 0);
igctx.associateTextureTargetSet(s_handleInputNormal, gbufferTargetSetId, 1);
igctx.associateTextureTargetSet(s_handleInputVelocity, velocityTargetSetId.current, 0);
igctx.associateTextureTargetSet(s_handleInputVelocityLast, velocityTargetSetId.previous, 0);
igctx.associateTextureTargetSet(s_handleInputVelocity, velocityTargetSetId, 0);
igctx.associateTexture(s_handleInputColorGrading, m_colorGrading);

// Expose gamma, exposure and jitter.
Expand Down
2 changes: 1 addition & 1 deletion code/World/Shared/Passes/PostProcessPass.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class PostProcessPass : public Object
uint32_t frameCount,
render::RenderGraph& renderGraph,
render::handle_t gbufferTargetSetId,
const DoubleBufferedTarget& velocityTargetSetId,
render::handle_t velocityTargetSetId,
const DoubleBufferedTarget& visualTargetSetId,
render::handle_t outputTargetSetId
) const;
Expand Down
18 changes: 4 additions & 14 deletions code/World/Shared/Passes/VelocityPass.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2023 Anders Pistol.
* Copyright (c) 2023-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -31,12 +31,6 @@ namespace traktor::world

const resource::Id< render::ImageGraph > c_velocityPrime(L"{CB34E98B-55C9-E447-BD59-5A1D91DCA88E}");

const render::Handle s_handleVelocityTargetSet[] =
{
render::Handle(L"World_VelocityTargetSet_Even"),
render::Handle(L"World_VelocityTargetSet_Odd")
};

}

T_IMPLEMENT_RTTI_CLASS(L"traktor.world.VelocityPass", VelocityPass, Object)
Expand Down Expand Up @@ -73,7 +67,7 @@ bool VelocityPass::create(resource::IResourceManager* resourceManager, render::I
return true;
}

DoubleBufferedTarget VelocityPass::setup(
render::handle_t VelocityPass::setup(
const WorldRenderView& worldRenderView,
const GatherView& gatheredView,
uint32_t frameCount,
Expand All @@ -91,16 +85,12 @@ DoubleBufferedTarget VelocityPass::setup(
rgtd.referenceWidthDenom = 1;
rgtd.referenceHeightDenom = 1;
rgtd.targets[0].colorFormat = render::TfR16G16F;
const DoubleBufferedTarget velocityTargetSetId =
{
renderGraph.addPersistentTargetSet(L"Velocity Previous", s_handleVelocityTargetSet[frameCount % 2], false, rgtd, outputTargetSetId, outputTargetSetId),
renderGraph.addPersistentTargetSet(L"Velocity Current", s_handleVelocityTargetSet[(frameCount + 1) % 2], false, rgtd, outputTargetSetId, outputTargetSetId)
};
const render::handle_t velocityTargetSetId = renderGraph.addTransientTargetSet(L"Velocity", rgtd, outputTargetSetId, outputTargetSetId);

// Add Velocity render pass.
Ref< render::RenderPass > rp = new render::RenderPass(L"Velocity");
rp->addInput(gbufferTargetSetId);
rp->setOutput(velocityTargetSetId.current, render::TfDepth, render::TfColor | render::TfDepth);
rp->setOutput(velocityTargetSetId, render::TfDepth, render::TfColor | render::TfDepth);

if (m_velocityPrime)
{
Expand Down
2 changes: 1 addition & 1 deletion code/World/Shared/Passes/VelocityPass.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class VelocityPass : public Object

bool create(resource::IResourceManager* resourceManager, render::IRenderSystem* renderSystem, const WorldCreateDesc& desc);

DoubleBufferedTarget setup(
render::handle_t setup(
const WorldRenderView& worldRenderView,
const GatherView& gatheredView,
uint32_t frameCount,
Expand Down
1 change: 0 additions & 1 deletion code/World/WorldHandles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ const render::Handle s_handleInputColorLast(L"InputColorLast");
const render::Handle s_handleInputDepth(L"InputDepth");
const render::Handle s_handleInputNormal(L"InputNormal");
const render::Handle s_handleInputVelocity(L"InputVelocity");
const render::Handle s_handleInputVelocityLast(L"InputVelocityLast");
const render::Handle s_handleInputColorGrading(L"InputColorGrading");

// Persistent targets.
Expand Down
1 change: 0 additions & 1 deletion code/World/WorldHandles.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ extern const render::Handle T_DLLCLASS s_handleInputColorLast;
extern const render::Handle T_DLLCLASS s_handleInputDepth;
extern const render::Handle T_DLLCLASS s_handleInputNormal;
extern const render::Handle T_DLLCLASS s_handleInputVelocity;
extern const render::Handle T_DLLCLASS s_handleInputVelocityLast;
extern const render::Handle T_DLLCLASS s_handleInputColorGrading;

// Persistent targets.
Expand Down
25 changes: 20 additions & 5 deletions code/World/WorldTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,26 @@ const EntityState EntityState::All = { true, true, true };

Vector2 jitter(int32_t count)
{
const Vector2 kernelSize(0.5f, 0.5f);
return Vector2(
(float)((count / 2) & 1) * kernelSize.x - (2.0f * kernelSize.x) / 3.0f,
(float)(count & 1) * kernelSize.y - (2.0f * kernelSize.y) / 3.0f
);
const static Vector2 c_halton[] =
{
Vector2(0.500000f, 0.333333f),
Vector2(0.250000f, 0.666667f),
Vector2(0.750000f, 0.111111f),
Vector2(0.125000f, 0.444444f),
Vector2(0.625000f, 0.777778f),
Vector2(0.375000f, 0.222222f),
Vector2(0.875000f, 0.555556f),
Vector2(0.062500f, 0.888889f),
Vector2(0.562500f, 0.037037f),
Vector2(0.312500f, 0.370370f),
Vector2(0.812500f, 0.703704f),
Vector2(0.187500f, 0.148148f),
Vector2(0.687500f, 0.481481f),
Vector2(0.437500f, 0.814815f),
Vector2(0.937500f, 0.259259f),
Vector2(0.031250f, 0.592593f)
};
return c_halton[count % sizeof_array(c_halton)] - Vector2(0.5f, 0.5f);
}

}
Loading

0 comments on commit 6c69a41

Please sign in to comment.