From 806f35f589f4d2a45fd10cb48598d8d7001f8574 Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Sat, 3 Dec 2022 00:54:01 -0800 Subject: [PATCH] [Impeller] Make perspective transform resolve to left handed clip space --- impeller/geometry/geometry_unittests.cc | 20 ++++++++++---------- impeller/geometry/matrix.h | 2 +- impeller/renderer/renderer_unittests.cc | 3 ++- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/impeller/geometry/geometry_unittests.cc b/impeller/geometry/geometry_unittests.cc index 9bafff468b1d8..95a0287eef600 100644 --- a/impeller/geometry/geometry_unittests.cc +++ b/impeller/geometry/geometry_unittests.cc @@ -240,7 +240,7 @@ TEST(GeometryTest, MatrixVectorMultiplication) { auto vector = Vector3(3, 3, -3); Vector3 result = matrix * vector; - auto expected = Vector3(1, 1, 0.673401); + auto expected = Vector3(-1, -1, 1.3468); ASSERT_VECTOR3_NEAR(result, expected); } @@ -250,7 +250,7 @@ TEST(GeometryTest, MatrixVectorMultiplication) { auto point = Point(3, 3); Point result = matrix * point; - auto expected = Point(1, 1); + auto expected = Point(-1, -1); ASSERT_POINT_NEAR(result, expected); } @@ -343,10 +343,10 @@ TEST(GeometryTest, MatrixMakePerspective) { { auto m = Matrix::MakePerspective(Degrees(60), Size(100, 200), 1, 10); auto expect = Matrix{ - 3.4641, 0, 0, 0, // - 0, 1.73205, 0, 0, // - 0, 0, -1.11111, -1, // - 0, 0, -1.11111, 0, // + 3.4641, 0, 0, 0, // + 0, 1.73205, 0, 0, // + 0, 0, 1.11111, 1, // + 0, 0, -1.11111, 0, // }; ASSERT_MATRIX_NEAR(m, expect); } @@ -354,10 +354,10 @@ TEST(GeometryTest, MatrixMakePerspective) { { auto m = Matrix::MakePerspective(Radians(1), 2, 10, 20); auto expect = Matrix{ - 0.915244, 0, 0, 0, // - 0, 1.83049, 0, 0, // - 0, 0, -2, -1, // - 0, 0, -20, 0, // + 0.915244, 0, 0, 0, // + 0, 1.83049, 0, 0, // + 0, 0, 2, 1, // + 0, 0, -20, 0, // }; ASSERT_MATRIX_NEAR(m, expect); } diff --git a/impeller/geometry/matrix.h b/impeller/geometry/matrix.h index 2d50f3045007b..9829317deb939 100644 --- a/impeller/geometry/matrix.h +++ b/impeller/geometry/matrix.h @@ -421,7 +421,7 @@ struct Matrix { return { 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_far - z_near), 1.0f, 0.0f, 0.0f, -(z_far * z_near) / (z_far - z_near), 0.0f, }; // clang-format on diff --git a/impeller/renderer/renderer_unittests.cc b/impeller/renderer/renderer_unittests.cc index cfd3637f9a8c2..e5678dd2c26ae 100644 --- a/impeller/renderer/renderer_unittests.cc +++ b/impeller/renderer/renderer_unittests.cc @@ -117,6 +117,7 @@ TEST_P(RendererTest, CanRenderPerspectiveCube) { auto desc = PipelineBuilder::MakeDefaultPipelineDescriptor(*context); ASSERT_TRUE(desc.has_value()); desc->SetCullMode(CullMode::kBackFace); + desc->SetWindingOrder(WindingOrder::kCounterClockwise); desc->SetSampleCount(SampleCount::kCount4); auto pipeline = context->GetPipelineLibrary()->GetPipeline(std::move(desc)).Get(); @@ -184,7 +185,7 @@ TEST_P(RendererTest, CanRenderPerspectiveCube) { uniforms.mvp = Matrix::MakePerspective(fov_y, pass.GetRenderTargetSize(), 0, 10) * - Matrix::MakeTranslation({0, 0, -distance}) * + Matrix::MakeTranslation({0, 0, distance}) * Matrix::MakeRotationX(Radians(euler_angles.x)) * Matrix::MakeRotationY(Radians(euler_angles.y)) * Matrix::MakeRotationZ(Radians(euler_angles.z));