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

Commit b8e88db

Browse files
committed
Stop querying isDeviceActive, start using Camera.stereoEnabled
XRSettings.isDeviceActive makes sense for general XR activity, but we should be using Camera.stereoEnabled for per camera stereo state. I do cache this value in the PostProcessRenderContext.
1 parent d75634c commit b8e88db

3 files changed

Lines changed: 13 additions & 15 deletions

File tree

PostProcessing/Runtime/Effects/TemporalAntialiasing.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,7 @@ void GenerateHistoryName(RenderTexture rt, int id, PostProcessRenderContext cont
139139
{
140140
rt.name = "Temporal Anti-aliasing History id #" + id;
141141

142-
bool vrDeviceActive = false;
143-
144-
#if UNITY_2017_2_OR_NEWER
145-
vrDeviceActive = XR.XRSettings.isDeviceActive;
146-
#else
147-
vrDeviceActive = VR.VRSettings.isDeviceActive;
148-
#endif
149-
150-
if (vrDeviceActive)
142+
if (context.stereoActive)
151143
rt.name += " for eye " + context.xrActiveEye;
152144
}
153145

PostProcessing/Runtime/PostProcessLayer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ void OnPreCull()
272272
m_Camera.ResetProjectionMatrix();
273273
m_Camera.nonJitteredProjectionMatrix = m_Camera.projectionMatrix;
274274

275-
if (XRSettings.isDeviceActive)
275+
if (m_Camera.stereoEnabled)
276276
{
277277
m_Camera.ResetStereoProjectionMatrices();
278278
Shader.SetGlobalFloat("rvsGlobal", XRSettings.renderViewportScale);
@@ -434,7 +434,7 @@ void OnPostRender()
434434
{
435435
m_Camera.ResetProjectionMatrix();
436436

437-
if (XRSettings.isDeviceActive)
437+
if (m_CurrentContext.stereoActive)
438438
{
439439
if (RuntimeUtilities.isSinglePassStereoEnabled || m_Camera.stereoActiveEye == Camera.MonoOrStereoscopicEye.Right)
440440
m_Camera.ResetStereoProjectionMatrices();
@@ -618,7 +618,7 @@ public void Render(PostProcessRenderContext context)
618618
{
619619
if (!RuntimeUtilities.scriptableRenderPipelineActive)
620620
{
621-
if (XRSettings.isDeviceActive)
621+
if (context.stereoActive)
622622
{
623623
// We only need to configure all of this once for stereo, during OnPreCull
624624
if (context.camera.stereoActiveEye != Camera.MonoOrStereoscopicEye.Right)

PostProcessing/Runtime/PostProcessRenderContext.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public Camera camera
2323
{
2424
m_Camera = value;
2525

26-
if (XRSettings.isDeviceActive)
26+
if (m_Camera.stereoEnabled)
2727
{
2828
#if UNITY_2017_2_OR_NEWER
2929
var xrDesc = XRSettings.eyeTextureDesc;
@@ -40,11 +40,12 @@ public Camera camera
4040
height = XRSettings.eyeTextureHeight;
4141
#endif
4242

43-
if (camera.stereoActiveEye == Camera.MonoOrStereoscopicEye.Right)
43+
if (m_Camera.stereoActiveEye == Camera.MonoOrStereoscopicEye.Right)
4444
xrActiveEye = (int)Camera.StereoscopicEye.Right;
4545

4646
screenWidth = XRSettings.eyeTextureWidth;
4747
screenHeight = XRSettings.eyeTextureHeight;
48+
stereoActive = true;
4849
}
4950
else
5051
{
@@ -57,6 +58,7 @@ public Camera camera
5758
#endif
5859
screenWidth = width;
5960
screenHeight = height;
61+
stereoActive = false;
6062
}
6163
}
6264
}
@@ -152,7 +154,8 @@ public void GetScreenSpaceTemporaryRT(CommandBuffer cmd, int nameID,
152154
actualHeight = heightOverride;
153155

154156
cmd.GetTemporaryRT(nameID, actualWidth, actualHeight, depthBufferBits, filter, colorFormat, readWrite);
155-
// TODO: How to handle MSAA for XR in older versions? Query cam?
157+
// TODO: How to handle MSAA for XR in older versions? Query cam?
158+
// TODO: Pass in vrUsage into the args
156159
#endif
157160
}
158161

@@ -179,6 +182,8 @@ public RenderTexture GetScreenSpaceTemporaryRT(int depthBufferBits = 0, RenderTe
179182
#endif
180183
}
181184

185+
public bool stereoActive { get; private set; }
186+
182187
// Current active rendering eye (for XR)
183188
public int xrActiveEye { get; private set; }
184189

@@ -207,6 +212,7 @@ public void Reset()
207212
m_sourceDescriptor = new RenderTextureDescriptor(0, 0);
208213
#endif
209214

215+
stereoActive = false;
210216
xrActiveEye = (int)Camera.StereoscopicEye.Left;
211217
screenWidth = 0;
212218
screenHeight = 0;

0 commit comments

Comments
 (0)