Skip to content

Commit a54b10e

Browse files
authored
Fix issue 1354395 where the right eye was shifted in stereo mode (#5789)
This commit Unity-Technologies/PostProcessing@08b1319 forced a reset on the projection matrix in PreCull and PostRender to avoid issues when switching on/off the TAA. This is fine except that it doesn't reset the projection matrix to the device's projection matrix which seems to trickle down somewhere and result in some systems getting the wrong projection matrix. This fix consist in forcing the device's projection matrix onto the camera to make sure that everyone is using the correct matrix if we happen to be in stereo. PostRender doesn't need to copy from device because the Render step of the TAA PostProcessLayer performs that action. PostRender doesn't need to deal with unjittered because that's probably only used in TAA.
1 parent b0442a4 commit a54b10e

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

com.unity.postprocessing/PostProcessing/Runtime/PostProcessLayer.cs

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -447,14 +447,35 @@ void OnPreCull()
447447
#if UNITY_2018_2_OR_NEWER
448448
if (!m_Camera.usePhysicalProperties)
449449
#endif
450-
m_Camera.ResetProjectionMatrix();
450+
{
451+
m_Camera.ResetProjectionMatrix();
452+
m_Camera.nonJitteredProjectionMatrix = m_Camera.projectionMatrix;
453+
#if (ENABLE_VR_MODULE && ENABLE_VR)
454+
if (m_Camera.stereoEnabled)
455+
{
456+
m_Camera.ResetStereoProjectionMatrices();
457+
if (m_Camera.stereoActiveEye == Camera.MonoOrStereoscopicEye.Right)
458+
{
459+
m_Camera.CopyStereoDeviceProjectionMatrixToNonJittered(Camera.StereoscopicEye.Right);
460+
m_Camera.projectionMatrix = m_Camera.GetStereoNonJitteredProjectionMatrix(Camera.StereoscopicEye.Right);
461+
m_Camera.nonJitteredProjectionMatrix = m_Camera.projectionMatrix;
462+
m_Camera.SetStereoProjectionMatrix(Camera.StereoscopicEye.Right, m_Camera.GetStereoProjectionMatrix(Camera.StereoscopicEye.Right));
463+
}
464+
else if (m_Camera.stereoActiveEye == Camera.MonoOrStereoscopicEye.Left || m_Camera.stereoActiveEye == Camera.MonoOrStereoscopicEye.Mono)
465+
{
466+
m_Camera.CopyStereoDeviceProjectionMatrixToNonJittered(Camera.StereoscopicEye.Left); // device to unjittered
467+
m_Camera.projectionMatrix = m_Camera.GetStereoNonJitteredProjectionMatrix(Camera.StereoscopicEye.Left);
468+
m_Camera.nonJitteredProjectionMatrix = m_Camera.projectionMatrix;
469+
m_Camera.SetStereoProjectionMatrix(Camera.StereoscopicEye.Left, m_Camera.GetStereoProjectionMatrix(Camera.StereoscopicEye.Left));
470+
}
471+
}
472+
#endif
473+
}
451474
}
452-
m_Camera.nonJitteredProjectionMatrix = m_Camera.projectionMatrix;
453475

454476
#if (ENABLE_VR_MODULE && ENABLE_VR)
455477
if (m_Camera.stereoEnabled)
456478
{
457-
m_Camera.ResetStereoProjectionMatrices();
458479
Shader.SetGlobalFloat(ShaderIDs.RenderViewportScaleFactor, XRSettings.renderViewportScale);
459480
}
460481
else
@@ -689,12 +710,19 @@ void OnPostRender()
689710
m_Camera.usePhysicalProperties = true;
690711
else
691712
#endif
692-
m_Camera.ResetProjectionMatrix();
693-
694-
if (m_CurrentContext.stereoActive)
695713
{
696-
if (RuntimeUtilities.isSinglePassStereoEnabled || m_Camera.stereoActiveEye == Camera.MonoOrStereoscopicEye.Right)
697-
m_Camera.ResetStereoProjectionMatrices();
714+
// The camera must be reset on precull and post render to avoid issues with alpha when toggling TAA.
715+
m_Camera.ResetProjectionMatrix();
716+
if (m_CurrentContext.stereoActive)
717+
{
718+
if (RuntimeUtilities.isSinglePassStereoEnabled || m_Camera.stereoActiveEye == Camera.MonoOrStereoscopicEye.Right)
719+
{
720+
m_Camera.ResetStereoProjectionMatrices();
721+
// copy the left eye onto the projection matrix so that we're using the correct projection matrix after calling m_Camera.ResetProjectionMatrix(); above.
722+
if (XRSettings.stereoRenderingMode == XRSettings.StereoRenderingMode.MultiPass)
723+
m_Camera.projectionMatrix = m_Camera.GetStereoProjectionMatrix(Camera.StereoscopicEye.Left);
724+
}
725+
}
698726
}
699727
}
700728
}

0 commit comments

Comments
 (0)