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

Commit 8a0f378

Browse files
committed
TAA works with Multi and Single Pass Stereo
Fair bit of hacking done, need to do a lot of cleanup. RT arrays aren't addressed yet.
1 parent 85478d6 commit 8a0f378

3 files changed

Lines changed: 68 additions & 16 deletions

File tree

PostProcessing/Runtime/Effects/TemporalAntialiasing.cs

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,17 @@ enum Pass
4242
// Ping-pong between two history textures as we can't read & write the same target in the
4343
// same pass
4444
// TODO: We need to make left/right arrays
45-
readonly RenderTexture[] m_HistoryTextures = new RenderTexture[2];
46-
//readonly RenderTexture[][] m_HistoryTextures = new RenderTexture[2][];
47-
//m_HistoryTextures[0][] = new RenderTexture[2];
48-
int m_HistoryPingPong;
45+
//readonly RenderTexture[] m_HistoryTextures = new RenderTexture[2];
46+
readonly RenderTexture[][] m_HistoryTextures = new RenderTexture[2][];
47+
48+
//int m_HistoryPingPong;
49+
int[] m_HistoryPingPong = new int [2];
50+
51+
public TemporalAntialiasing()
52+
{
53+
m_HistoryTextures[0] = new RenderTexture[2];
54+
m_HistoryTextures[1] = new RenderTexture[2];
55+
}
4956

5057
public bool IsSupported()
5158
{
@@ -131,16 +138,18 @@ public void ConfiguredStereoJitteredProjectionMatrices(PostProcessRenderContext
131138

132139
RenderTexture CheckHistory(int id, PostProcessRenderContext context)
133140
{
134-
var rt = m_HistoryTextures[id];
141+
//var rt = m_HistoryTextures[id];
142+
var rt = m_HistoryTextures[context.activeEye][id];
135143

136144
if (m_ResetHistory || rt == null || !rt.IsCreated())
137145
{
138146
RenderTexture.ReleaseTemporary(rt);
139147

140148
rt = RenderTexture.GetTemporary(context.width, context.height, 0, context.sourceFormat);
141-
rt.name = "Temporal Anti-aliasing History";
149+
rt.name = "Temporal Anti-aliasing History id #" + id.ToString() + " for eye " + context.activeEye.ToString();
142150
rt.filterMode = FilterMode.Bilinear;
143-
m_HistoryTextures[id] = rt;
151+
//m_HistoryTextures[id] = rt;
152+
m_HistoryTextures[context.activeEye][id] = rt;
144153

145154
context.command.BlitFullscreenTriangle(context.source, rt);
146155
}
@@ -149,15 +158,18 @@ RenderTexture CheckHistory(int id, PostProcessRenderContext context)
149158
// On size change, simply copy the old history to the new one. This looks better
150159
// than completely discarding the history and seeing a few aliased frames.
151160
var rt2 = RenderTexture.GetTemporary(context.width, context.height, 0, context.sourceFormat);
152-
rt2.name = "Temporal Anti-aliasing History";
161+
//rt2.name = "Temporal Anti-aliasing History";
162+
rt2.name = "Temporal Anti-aliasing History id #" + id.ToString() + " for eye " + context.activeEye.ToString();
153163
rt2.filterMode = FilterMode.Bilinear;
154-
m_HistoryTextures[id] = rt2;
164+
//m_HistoryTextures[id] = rt2;
165+
m_HistoryTextures[context.activeEye][id] = rt2;
155166

156167
context.command.BlitFullscreenTriangle(rt, rt2);
157168
RenderTexture.ReleaseTemporary(rt);
158169
}
159170

160-
return m_HistoryTextures[id];
171+
//return m_HistoryTextures[id];
172+
return m_HistoryTextures[context.activeEye][id];
161173
}
162174

163175
internal void Render(PostProcessRenderContext context)
@@ -167,10 +179,12 @@ internal void Render(PostProcessRenderContext context)
167179
var cmd = context.command;
168180
cmd.BeginSample("TemporalAntialiasing");
169181

170-
int pp = m_HistoryPingPong;
182+
//int pp = m_HistoryPingPong;
183+
int pp = m_HistoryPingPong[context.activeEye];
171184
var historyRead = CheckHistory(++pp % 2, context);
172185
var historyWrite = CheckHistory(++pp % 2, context);
173-
m_HistoryPingPong = ++pp % 2;
186+
//m_HistoryPingPong = ++pp % 2;
187+
m_HistoryPingPong[context.activeEye] = ++pp % 2;
174188

175189
const float kMotionAmplification = 100f * 60f;
176190
sheet.properties.SetVector(ShaderIDs.Jitter, jitter);
@@ -192,12 +206,17 @@ internal void Release()
192206
{
193207
for (int i = 0; i < m_HistoryTextures.Length; i++)
194208
{
195-
RenderTexture.ReleaseTemporary(m_HistoryTextures[i]);
209+
for (int j = 0; j < m_HistoryTextures[i].Length; j++)
210+
{
211+
RenderTexture.ReleaseTemporary(m_HistoryTextures[i][j]);
212+
m_HistoryTextures[i][j] = null;
213+
}
196214
m_HistoryTextures[i] = null;
197215
}
198216

199217
m_SampleIndex = 0;
200-
m_HistoryPingPong = 0;
218+
m_HistoryPingPong[0] = 0;
219+
m_HistoryPingPong[1] = 0;
201220

202221
ResetHistory();
203222
}

PostProcessing/Runtime/PostProcessLayer.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,14 @@ void OnPreCull()
256256
// when ResetProjectionMatrix() is called and will break transparent rendering if TAA
257257
// is switched off and the FOV or any other camera property changes.
258258
m_Camera.ResetProjectionMatrix();
259-
m_Camera.nonJitteredProjectionMatrix = m_Camera.projectionMatrix;
259+
//m_Camera.nonJitteredProjectionMatrix = m_Camera.projectionMatrix;
260260
if (XR.XRSettings.isDeviceActive)
261+
{
261262
m_Camera.ResetStereoProjectionMatrices();
263+
//m_Camera.nonJitteredProjectionMatrix = m_Camera.GetStereoProjectionMatrix(Camera.StereoscopicEye.Left);
264+
}
265+
else
266+
m_Camera.nonJitteredProjectionMatrix = m_Camera.projectionMatrix;
262267

263268
context.Reset();
264269
context.camera = m_Camera;
@@ -381,6 +386,8 @@ void OnPreRender()
381386
// is switched off and the FOV or any other camera property changes.
382387
//m_Camera.ResetProjectionMatrix();
383388
//m_Camera.nonJitteredProjectionMatrix = m_Camera.projectionMatrix;
389+
//m_Camera.nonJitteredProjectionMatrix = m_Camera.GetStereoNonJitteredProjectionMatrix(Camera.StereoscopicEye.Right);
390+
//m_Camera.projectionMatrix = m_Camera.GetStereoProjectionMatrix(Camera.StereoscopicEye.Right);
384391

385392
context.Reset();
386393
context.camera = m_Camera;
@@ -496,8 +503,13 @@ void OnPostRender()
496503
if (m_CurrentContext.IsTemporalAntialiasingActive())
497504
{
498505
m_Camera.ResetProjectionMatrix();
506+
499507
if (XR.XRSettings.isDeviceActive)
500-
m_Camera.ResetStereoProjectionMatrices();
508+
{
509+
if (m_CurrentContext.xrSinglePass ||
510+
(m_Camera.stereoActiveEye == Camera.MonoOrStereoscopicEye.Right))
511+
m_Camera.ResetStereoProjectionMatrices();
512+
}
501513
}
502514
}
503515

PostProcessing/Runtime/PostProcessRenderContext.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,19 @@ public Camera camera
2727
// we should create eye-specific params
2828
// in order to support knowing the size of each eye
2929

30+
if (camera.stereoActiveEye == Camera.MonoOrStereoscopicEye.Right)
31+
m_activeEye = (int)Camera.StereoscopicEye.Right;
32+
3033
if ((xrDesc.vrUsage == VRTextureUsage.TwoEyes) &&
3134
(xrDesc.dimension != TextureDimension.Tex2DArray))
3235
{
3336
m_singleEyeWidth = m_width / 2;
3437
}
3538
else
3639
m_singleEyeWidth = m_width;
40+
41+
// if the intermediate texture is being used for two eyes, that's single pass
42+
m_xrSinglePass = (xrDesc.vrUsage == VRTextureUsage.TwoEyes);
3743
}
3844
else
3945
{
@@ -96,6 +102,12 @@ public int singleEyeWidth
96102
get { return m_singleEyeWidth; }
97103
}
98104

105+
private bool m_xrSinglePass;
106+
public bool xrSinglePass
107+
{
108+
get { return m_xrSinglePass; }
109+
}
110+
99111
// Are we currently rendering in the scene view?
100112
public bool isSceneView { get; internal set; }
101113

@@ -106,12 +118,21 @@ public int singleEyeWidth
106118
// to do temporal reprojection (see: Depth of Field)
107119
public TemporalAntialiasing temporalAntialiasing { get; internal set; }
108120

121+
private int m_activeEye;
122+
public int activeEye
123+
{
124+
get { return m_activeEye; }
125+
}
126+
109127
public void Reset()
110128
{
111129
m_camera = null;
112130
m_width = 0;
113131
m_height = 0;
132+
114133
m_singleEyeWidth = 0;
134+
m_activeEye = (int)Camera.StereoscopicEye.Left;
135+
m_xrSinglePass = false;
115136

116137
command = null;
117138
source = 0;

0 commit comments

Comments
 (0)