Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.

Commit 51eb95a

Browse files
committed
Added a callback for custom jittered matrix
1 parent 1e1fcbc commit 51eb95a

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

PostProcessing/Runtime/Components/TaaComponent.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using UnityEngine.Rendering;
23

34
namespace UnityEngine.PostProcessing
@@ -45,17 +46,25 @@ public void ResetHistory()
4546
m_ResetHistory = true;
4647
}
4748

48-
public void SetProjectionMatrix()
49+
public void SetProjectionMatrix(Func<Vector2, Matrix4x4> jitteredFunc)
4950
{
5051
var settings = model.settings.taaSettings;
5152

5253
var jitter = GenerateRandomOffset();
5354
jitter *= settings.jitterSpread;
5455

5556
context.camera.nonJitteredProjectionMatrix = context.camera.projectionMatrix;
56-
context.camera.projectionMatrix = context.camera.orthographic
57-
? GetOrthographicProjectionMatrix(jitter)
58-
: GetPerspectiveProjectionMatrix(jitter);
57+
58+
if (jitteredFunc != null)
59+
{
60+
context.camera.projectionMatrix = jitteredFunc(jitter);
61+
}
62+
else
63+
{
64+
context.camera.projectionMatrix = context.camera.orthographic
65+
? GetOrthographicProjectionMatrix(jitter)
66+
: GetPerspectiveProjectionMatrix(jitter);
67+
}
5968

6069
#if UNITY_5_5_OR_NEWER
6170
context.camera.useJitteredProjectionMatrixForTransparentRendering = false;

PostProcessing/Runtime/PostProcessingBehaviour.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ public class PostProcessingBehaviour : MonoBehaviour
1616
// Inspector fields
1717
public PostProcessingProfile profile;
1818

19+
public Func<Vector2, Matrix4x4> jitteredMatrixFunc;
20+
Matrix4x4 nonJitteredProjectionMatrix;
21+
1922
// Internal helpers
2023
Dictionary<Type, KeyValuePair<CameraEvent, CommandBuffer>> m_CommandBuffers;
2124
List<PostProcessingComponentBase> m_Components;
@@ -149,7 +152,10 @@ void OnPreCull()
149152

150153
// Temporal antialiasing jittering, needs to happen before culling
151154
if (!m_RenderingInSceneView && m_Taa.active && !profile.debugViews.willInterrupt)
152-
m_Taa.SetProjectionMatrix();
155+
{
156+
nonJitteredProjectionMatrix = m_Context.camera.projectionMatrix;
157+
m_Taa.SetProjectionMatrix(jitteredMatrixFunc);
158+
}
153159
}
154160

155161
void OnPreRender()
@@ -172,7 +178,7 @@ void OnPostRender()
172178
return;
173179

174180
if (!m_RenderingInSceneView && m_Taa.active && !profile.debugViews.willInterrupt)
175-
m_Camera.ResetProjectionMatrix();
181+
m_Context.camera.projectionMatrix = nonJitteredProjectionMatrix;
176182
}
177183

178184
// Classic render target pipeline for RT-based effects

0 commit comments

Comments
 (0)