[Impeller] Make perspective transform resolve to left handed clip space (flutter/engine#38052)

This commit is contained in:
Brandon DeRosier
2022-12-03 14:07:55 -08:00
committed by GitHub
parent 75b922861b
commit ab78871b66
3 changed files with 13 additions and 12 deletions

View File

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

View File

@@ -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

View File

@@ -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();
@@ -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));