Skip to content
This repository has been archived by the owner on Feb 25, 2025. It is now read-only.

Commit

Permalink
[Impeller] Make perspective transform resolve to left handed clip spa…
Browse files Browse the repository at this point in the history
…ce (#38052)
  • Loading branch information
bdero authored Dec 3, 2022
1 parent 9b48471 commit b3e86c3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
20 changes: 10 additions & 10 deletions impeller/geometry/geometry_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -343,21 +343,21 @@ 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);
}

{
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);
}
Expand Down
2 changes: 1 addition & 1 deletion impeller/geometry/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion impeller/renderer/renderer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ TEST_P(RendererTest, CanRenderPerspectiveCube) {
auto desc = PipelineBuilder<VS, FS>::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();
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit b3e86c3

Please sign in to comment.