diff --git a/PostProcessing/Runtime/PostProcessLayer.cs b/PostProcessing/Runtime/PostProcessLayer.cs index 1b0866c9..1e1628ed 100644 --- a/PostProcessing/Runtime/PostProcessLayer.cs +++ b/PostProcessing/Runtime/PostProcessLayer.cs @@ -276,7 +276,11 @@ void OnPreCull() // We also need to force reset the non-jittered projection matrix here as it's not done // when ResetProjectionMatrix() is called and will break transparent rendering if TAA // is switched off and the FOV or any other camera property changes. - m_Camera.ResetProjectionMatrix(); + +#if UNITY_2018_2_OR_NEWER + if (!m_Camera.usePhysicalProperties) +#endif + m_Camera.ResetProjectionMatrix(); m_Camera.nonJitteredProjectionMatrix = m_Camera.projectionMatrix; #if !UNITY_SWITCH @@ -446,7 +450,13 @@ void OnPostRender() if (m_CurrentContext.IsTemporalAntialiasingActive()) { - m_Camera.ResetProjectionMatrix(); +#if UNITY_2018_2_OR_NEWER + // TAA calls SetProjectionMatrix so if the camera projection mode was physical, it gets set to explicit. So we set it back to physical. + if (m_CurrentContext.physicalCamera) + m_Camera.usePhysicalProperties = true; + else +#endif + m_Camera.ResetProjectionMatrix(); if (m_CurrentContext.stereoActive) { @@ -569,6 +579,11 @@ void SetupContext(PostProcessRenderContext context) context.antialiasing = antialiasingMode; context.temporalAntialiasing = temporalAntialiasing; context.logHistogram = m_LogHistogram; + +#if UNITY_2018_2_OR_NEWER + context.physicalCamera = context.camera.usePhysicalProperties; +#endif + SetLegacyCameraFlags(context); // Prepare debug overlay diff --git a/PostProcessing/Runtime/PostProcessRenderContext.cs b/PostProcessing/Runtime/PostProcessRenderContext.cs index 028644ef..21be6ad0 100644 --- a/PostProcessing/Runtime/PostProcessRenderContext.cs +++ b/PostProcessing/Runtime/PostProcessRenderContext.cs @@ -134,7 +134,9 @@ public Camera camera internal Texture logLut; internal AutoExposure autoExposure; internal int bloomBufferNameID; - +#if UNITY_2018_2_OR_NEWER + internal bool physicalCamera; +#endif public void Reset() { m_Camera = null; @@ -144,7 +146,9 @@ public void Reset() #if UNITY_2017_2_OR_NEWER m_sourceDescriptor = new RenderTextureDescriptor(0, 0); #endif - +#if UNITY_2018_2_OR_NEWER + physicalCamera = false; +#endif stereoActive = false; xrActiveEye = (int)Camera.StereoscopicEye.Left; screenWidth = 0; diff --git a/PostProcessing/Runtime/Utils/RuntimeUtilities.cs b/PostProcessing/Runtime/Utils/RuntimeUtilities.cs index baf95ddb..1c6a3018 100644 --- a/PostProcessing/Runtime/Utils/RuntimeUtilities.cs +++ b/PostProcessing/Runtime/Utils/RuntimeUtilities.cs @@ -576,44 +576,22 @@ public static float Exp2(float x) return Mathf.Exp(x * 0.69314718055994530941723212145818f); } - // Adapted heavily from PlayDead's TAA code - // https://github.com/playdeadgames/temporal/blob/master/Assets/Scripts/Extensions.cs + public static Matrix4x4 GetJitteredPerspectiveProjectionMatrix(Camera camera, Vector2 offset) { - float vertical = Mathf.Tan(0.5f * Mathf.Deg2Rad * camera.fieldOfView); - float horizontal = vertical * camera.aspect; float near = camera.nearClipPlane; - float far = camera.farClipPlane; - - offset.x *= horizontal / (0.5f * camera.pixelWidth); - offset.y *= vertical / (0.5f * camera.pixelHeight); - - float left = (offset.x - horizontal) * near; - float right = (offset.x + horizontal) * near; - float top = (offset.y + vertical) * near; - float bottom = (offset.y - vertical) * near; - - var matrix = new Matrix4x4(); + float far = camera.farClipPlane; - matrix[0, 0] = (2f * near) / (right - left); - matrix[0, 1] = 0f; - matrix[0, 2] = (right + left) / (right - left); - matrix[0, 3] = 0f; + float vertical = Mathf.Tan(0.5f * Mathf.Deg2Rad * camera.fieldOfView) * near; + float horizontal = vertical * camera.aspect; - matrix[1, 0] = 0f; - matrix[1, 1] = (2f * near) / (top - bottom); - matrix[1, 2] = (top + bottom) / (top - bottom); - matrix[1, 3] = 0f; + offset.x *= horizontal / (0.5f * camera.pixelWidth); + offset.y *= vertical / (0.5f * camera.pixelHeight); - matrix[2, 0] = 0f; - matrix[2, 1] = 0f; - matrix[2, 2] = -(far + near) / (far - near); - matrix[2, 3] = -(2f * far * near) / (far - near); + var matrix = camera.projectionMatrix; - matrix[3, 0] = 0f; - matrix[3, 1] = 0f; - matrix[3, 2] = -1f; - matrix[3, 3] = 0f; + matrix[0, 2] += offset.x / horizontal; + matrix[1, 2] += offset.y / vertical; return matrix; }