diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 91977245c80..57a7749dd3b 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Changed - Removed the material pass probe volumes evaluation mode. - Updated the tooltip for the Decal Angle Fade property (requires to enable Decal Layers in both HDRP asset and Frame settings) (case 1308048). +- Fixed skybox for ortho cameras. ## [11.0.0] - 2020-10-21 diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs index 1231d34da2c..f8ab5ebeb03 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs @@ -1385,7 +1385,7 @@ Matrix4x4 ComputePixelCoordToWorldSpaceViewDirectionMatrix(ViewConstants viewCon } Vector2 lensShift = camera.GetGateFittedLensShift(); - return HDUtils.ComputePixelCoordToWorldSpaceViewDirectionMatrix(verticalFoV, lensShift, resolution, viewConstants.viewMatrix, false, aspect); + return HDUtils.ComputePixelCoordToWorldSpaceViewDirectionMatrix(verticalFoV, lensShift, resolution, viewConstants.viewMatrix, false, aspect, camera.orthographic); } void Dispose() diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Utility/HDUtils.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Utility/HDUtils.cs index 8a99e2587ab..04d2e0248a6 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Utility/HDUtils.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Utility/HDUtils.cs @@ -140,35 +140,49 @@ internal static int GetRuntimeDebugPanelWidth(HDCamera hdCamera) internal static float ProjectionMatrixAspect(in Matrix4x4 matrix) => - matrix.m11 / matrix.m00; - internal static Matrix4x4 ComputePixelCoordToWorldSpaceViewDirectionMatrix(float verticalFoV, Vector2 lensShift, Vector4 screenSize, Matrix4x4 worldToViewMatrix, bool renderToCubemap, float aspectRatio = -1) + internal static Matrix4x4 ComputePixelCoordToWorldSpaceViewDirectionMatrix(float verticalFoV, Vector2 lensShift, Vector4 screenSize, Matrix4x4 worldToViewMatrix, bool renderToCubemap, float aspectRatio = -1, bool isOrthographic = false) { - aspectRatio = aspectRatio < 0 ? screenSize.x * screenSize.w : aspectRatio; + Matrix4x4 viewSpaceRasterTransform; - // Compose the view space version first. - // V = -(X, Y, Z), s.t. Z = 1, - // X = (2x / resX - 1) * tan(vFoV / 2) * ar = x * [(2 / resX) * tan(vFoV / 2) * ar] + [-tan(vFoV / 2) * ar] = x * [-m00] + [-m20] - // Y = (2y / resY - 1) * tan(vFoV / 2) = y * [(2 / resY) * tan(vFoV / 2)] + [-tan(vFoV / 2)] = y * [-m11] + [-m21] + if (isOrthographic) + { + // For ortho cameras, project the skybox with no perspective + // the same way as builtin does (case 1264647) + viewSpaceRasterTransform = new Matrix4x4( + new Vector4(-2.0f * screenSize.z, 0.0f, 0.0f, 0.0f), + new Vector4(0.0f, -2.0f * screenSize.w, 0.0f, 0.0f), + new Vector4(1.0f, 1.0f, -1.0f, 0.0f), + new Vector4(0.0f, 0.0f, 0.0f, 0.0f)); + } + else + { + // Compose the view space version first. + // V = -(X, Y, Z), s.t. Z = 1, + // X = (2x / resX - 1) * tan(vFoV / 2) * ar = x * [(2 / resX) * tan(vFoV / 2) * ar] + [-tan(vFoV / 2) * ar] = x * [-m00] + [-m20] + // Y = (2y / resY - 1) * tan(vFoV / 2) = y * [(2 / resY) * tan(vFoV / 2)] + [-tan(vFoV / 2)] = y * [-m11] + [-m21] - float tanHalfVertFoV = Mathf.Tan(0.5f * verticalFoV); + aspectRatio = aspectRatio < 0 ? screenSize.x * screenSize.w : aspectRatio; + float tanHalfVertFoV = Mathf.Tan(0.5f * verticalFoV); - // Compose the matrix. - float m21 = (1.0f - 2.0f * lensShift.y) * tanHalfVertFoV; - float m11 = -2.0f * screenSize.w * tanHalfVertFoV; + // Compose the matrix. + float m21 = (1.0f - 2.0f * lensShift.y) * tanHalfVertFoV; + float m11 = -2.0f * screenSize.w * tanHalfVertFoV; - float m20 = (1.0f - 2.0f * lensShift.x) * tanHalfVertFoV * aspectRatio; - float m00 = -2.0f * screenSize.z * tanHalfVertFoV * aspectRatio; + float m20 = (1.0f - 2.0f * lensShift.x) * tanHalfVertFoV * aspectRatio; + float m00 = -2.0f * screenSize.z * tanHalfVertFoV * aspectRatio; - if (renderToCubemap) - { - // Flip Y. - m11 = -m11; - m21 = -m21; - } + if (renderToCubemap) + { + // Flip Y. + m11 = -m11; + m21 = -m21; + } - var viewSpaceRasterTransform = new Matrix4x4(new Vector4(m00, 0.0f, 0.0f, 0.0f), - new Vector4(0.0f, m11, 0.0f, 0.0f), - new Vector4(m20, m21, -1.0f, 0.0f), - new Vector4(0.0f, 0.0f, 0.0f, 1.0f)); + viewSpaceRasterTransform = new Matrix4x4(new Vector4(m00, 0.0f, 0.0f, 0.0f), + new Vector4(0.0f, m11, 0.0f, 0.0f), + new Vector4(m20, m21, -1.0f, 0.0f), + new Vector4(0.0f, 0.0f, 0.0f, 1.0f)); + } // Remove the translation component. var homogeneousZero = new Vector4(0, 0, 0, 1);