Skip to content

Commit b0bacc2

Browse files
TemporalAntiAliasing: added GetJitteredProjMatrix helper function
1 parent 08c942a commit b0bacc2

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

Hydrogent/src/Tasks/HnBeginFrameTask.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 Diligent Graphics LLC
2+
* Copyright 2023-2025 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,6 +40,7 @@
4040
#include "MapHelper.hpp"
4141
#include "ScopedDebugGroup.hpp"
4242
#include "GLTF_PBR_Renderer.hpp"
43+
#include "TemporalAntiAliasing.hpp"
4344

4445
namespace Diligent
4546
{
@@ -493,10 +494,7 @@ void HnBeginFrameTask::UpdateFrameConstants(IDeviceContext* pCtx,
493494
PrevCamera = CamAttribs;
494495
if (m_pCamera != nullptr)
495496
{
496-
float4x4 ProjMatrix = m_pCamera->GetProjectionMatrix();
497-
ProjMatrix[2][0] = Jitter.x;
498-
ProjMatrix[2][1] = Jitter.y;
499-
497+
const float4x4 ProjMatrix = TemporalAntiAliasing::GetJitteredProjMatrix(m_pCamera->GetProjectionMatrix(), Jitter);
500498
const float4x4& ViewMatrix = m_pCamera->GetViewMatrix();
501499
const float4x4& WorldMatrix = m_pCamera->GetWorldMatrix();
502500
const float4x4 ViewProj = ViewMatrix * ProjMatrix;
@@ -554,9 +552,7 @@ void HnBeginFrameTask::UpdateFrameConstants(IDeviceContext* pCtx,
554552
}
555553
else
556554
{
557-
float4x4 PrevProj = PrevCamera.mProj;
558-
PrevProj[2][0] = Jitter.x;
559-
PrevProj[2][1] = Jitter.y;
555+
const float4x4 PrevProj = TemporalAntiAliasing::GetJitteredProjMatrix(PrevCamera.mProj, Jitter);
560556
if (PrevProj != CamAttribs.mProj)
561557
{
562558
CameraTransformDirty = true;

PostProcess/TemporalAntiAliasing/interface/TemporalAntiAliasing.hpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 Diligent Graphics LLC
2+
* Copyright 2024-2025 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -116,6 +116,25 @@ class TemporalAntiAliasing
116116

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

119+
static inline float4x4 GetJitteredProjMatrix(float4x4 Proj, const float2& Jitter)
120+
{
121+
if (Proj.m33 == 0.f)
122+
{
123+
// Perspective projection.
124+
// Make jitter proportional to z so that it is constant in screen space.
125+
Proj.m20 += Jitter.x;
126+
Proj.m21 += Jitter.y;
127+
}
128+
else
129+
{
130+
// Orthographic projection.
131+
// Apply offsets directly.
132+
Proj.m30 += Jitter.x;
133+
Proj.m31 += Jitter.y;
134+
}
135+
return Proj;
136+
}
137+
119138
private:
120139
using RenderTechnique = PostFXRenderTechnique;
121140
using ResourceInternal = RefCntAutoPtr<IDeviceObject>;

0 commit comments

Comments
 (0)