Skip to content

Commit

Permalink
TemporalAntiAliasing: added GetJitteredProjMatrix helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Jan 8, 2025
1 parent 08c942a commit b0bacc2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
12 changes: 4 additions & 8 deletions Hydrogent/src/Tasks/HnBeginFrameTask.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 Diligent Graphics LLC
* Copyright 2023-2025 Diligent Graphics LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,6 +40,7 @@
#include "MapHelper.hpp"
#include "ScopedDebugGroup.hpp"
#include "GLTF_PBR_Renderer.hpp"
#include "TemporalAntiAliasing.hpp"

namespace Diligent
{
Expand Down Expand Up @@ -493,10 +494,7 @@ void HnBeginFrameTask::UpdateFrameConstants(IDeviceContext* pCtx,
PrevCamera = CamAttribs;
if (m_pCamera != nullptr)
{
float4x4 ProjMatrix = m_pCamera->GetProjectionMatrix();
ProjMatrix[2][0] = Jitter.x;
ProjMatrix[2][1] = Jitter.y;

const float4x4 ProjMatrix = TemporalAntiAliasing::GetJitteredProjMatrix(m_pCamera->GetProjectionMatrix(), Jitter);
const float4x4& ViewMatrix = m_pCamera->GetViewMatrix();
const float4x4& WorldMatrix = m_pCamera->GetWorldMatrix();
const float4x4 ViewProj = ViewMatrix * ProjMatrix;
Expand Down Expand Up @@ -554,9 +552,7 @@ void HnBeginFrameTask::UpdateFrameConstants(IDeviceContext* pCtx,
}
else
{
float4x4 PrevProj = PrevCamera.mProj;
PrevProj[2][0] = Jitter.x;
PrevProj[2][1] = Jitter.y;
const float4x4 PrevProj = TemporalAntiAliasing::GetJitteredProjMatrix(PrevCamera.mProj, Jitter);
if (PrevProj != CamAttribs.mProj)
{
CameraTransformDirty = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Diligent Graphics LLC
* Copyright 2024-2025 Diligent Graphics LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -116,6 +116,25 @@ class TemporalAntiAliasing

ITextureView* GetAccumulatedFrameSRV(bool IsPrevFrame = false, Uint32 AccumulationBufferIdx = 0) const;

static inline float4x4 GetJitteredProjMatrix(float4x4 Proj, const float2& Jitter)
{
if (Proj.m33 == 0.f)
{
// Perspective projection.
// Make jitter proportional to z so that it is constant in screen space.
Proj.m20 += Jitter.x;
Proj.m21 += Jitter.y;
}
else
{
// Orthographic projection.
// Apply offsets directly.
Proj.m30 += Jitter.x;
Proj.m31 += Jitter.y;
}
return Proj;
}

private:
using RenderTechnique = PostFXRenderTechnique;
using ResourceInternal = RefCntAutoPtr<IDeviceObject>;
Expand Down

0 comments on commit b0bacc2

Please sign in to comment.