Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Impeller] Make perspective transform resolve to left handed clip space #38052

Merged
merged 1 commit into from
Dec 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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