From c7d0078ddbbfe024b057e2d65fc694d52079225a Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Sat, 13 Aug 2022 03:48:05 -0700 Subject: [PATCH 1/2] Map to Metal's clip space in the perspective projection --- impeller/geometry/matrix.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/impeller/geometry/matrix.h b/impeller/geometry/matrix.h index 2a622a4ed2f63..a3c300dda1830 100644 --- a/impeller/geometry/matrix.h +++ b/impeller/geometry/matrix.h @@ -336,14 +336,13 @@ struct Matrix { Scalar z_far) { Scalar height = std::tan(fov_y.radians * 0.5); Scalar width = height * aspect_ratio; - Scalar z_diff = z_near - z_far; // clang-format off return { - 1.0f / width, 0.0f, 0.0f, 0.0f, - 0.0f, 1.0f / height, 0.0f, 0.0f, - 0.0f, 0.0f, (z_near + z_far) / z_diff, -1.0f, - 0.0f, 0.0f, (2.0f * z_near * z_far) / z_diff, 0.0f + 1.0f / width, 0.0f, 0.0f, 0.0f, + 0.0f, 1.0f / height, 0.0f, 0.0f, + 0.0f, 0.0f, z_far / (z_near - z_far), -1.0f, + 0.0f, 0.0f, -(z_far * z_near) / (z_far - z_near), 0.0f, }; // clang-format on } From 02f7dd9d9dd4e230719699afe47ebccbdc42b953 Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Sat, 13 Aug 2022 19:21:00 -0700 Subject: [PATCH 2/2] Fix test --- impeller/geometry/geometry_unittests.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/impeller/geometry/geometry_unittests.cc b/impeller/geometry/geometry_unittests.cc index c2b10a32d6798..8ba3c6e9b719d 100644 --- a/impeller/geometry/geometry_unittests.cc +++ b/impeller/geometry/geometry_unittests.cc @@ -284,8 +284,8 @@ TEST(GeometryTest, MatrixMakePerspective) { auto expect = Matrix{ 3.4641, 0, 0, 0, // 0, 1.73205, 0, 0, // - 0, 0, -1.22222, -1, // - 0, 0, -2.22222, 0, // + 0, 0, -1.11111, -1, // + 0, 0, -1.11111, 0, // }; ASSERT_MATRIX_NEAR(m, expect); } @@ -295,8 +295,8 @@ TEST(GeometryTest, MatrixMakePerspective) { auto expect = Matrix{ 0.915244, 0, 0, 0, // 0, 1.83049, 0, 0, // - 0, 0, -3, -1, // - 0, 0, -40, 0, // + 0, 0, -2, -1, // + 0, 0, -20, 0, // }; ASSERT_MATRIX_NEAR(m, expect); }