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

Commit b3e86c3

Browse files
authored
[Impeller] Make perspective transform resolve to left handed clip space (#38052)
1 parent 9b48471 commit b3e86c3

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

impeller/geometry/geometry_unittests.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ TEST(GeometryTest, MatrixVectorMultiplication) {
240240
auto vector = Vector3(3, 3, -3);
241241

242242
Vector3 result = matrix * vector;
243-
auto expected = Vector3(1, 1, 0.673401);
243+
auto expected = Vector3(-1, -1, 1.3468);
244244
ASSERT_VECTOR3_NEAR(result, expected);
245245
}
246246

@@ -250,7 +250,7 @@ TEST(GeometryTest, MatrixVectorMultiplication) {
250250
auto point = Point(3, 3);
251251

252252
Point result = matrix * point;
253-
auto expected = Point(1, 1);
253+
auto expected = Point(-1, -1);
254254
ASSERT_POINT_NEAR(result, expected);
255255
}
256256

@@ -343,21 +343,21 @@ TEST(GeometryTest, MatrixMakePerspective) {
343343
{
344344
auto m = Matrix::MakePerspective(Degrees(60), Size(100, 200), 1, 10);
345345
auto expect = Matrix{
346-
3.4641, 0, 0, 0, //
347-
0, 1.73205, 0, 0, //
348-
0, 0, -1.11111, -1, //
349-
0, 0, -1.11111, 0, //
346+
3.4641, 0, 0, 0, //
347+
0, 1.73205, 0, 0, //
348+
0, 0, 1.11111, 1, //
349+
0, 0, -1.11111, 0, //
350350
};
351351
ASSERT_MATRIX_NEAR(m, expect);
352352
}
353353

354354
{
355355
auto m = Matrix::MakePerspective(Radians(1), 2, 10, 20);
356356
auto expect = Matrix{
357-
0.915244, 0, 0, 0, //
358-
0, 1.83049, 0, 0, //
359-
0, 0, -2, -1, //
360-
0, 0, -20, 0, //
357+
0.915244, 0, 0, 0, //
358+
0, 1.83049, 0, 0, //
359+
0, 0, 2, 1, //
360+
0, 0, -20, 0, //
361361
};
362362
ASSERT_MATRIX_NEAR(m, expect);
363363
}

impeller/geometry/matrix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ struct Matrix {
421421
return {
422422
1.0f / width, 0.0f, 0.0f, 0.0f,
423423
0.0f, 1.0f / height, 0.0f, 0.0f,
424-
0.0f, 0.0f, z_far / (z_near - z_far), -1.0f,
424+
0.0f, 0.0f, z_far / (z_far - z_near), 1.0f,
425425
0.0f, 0.0f, -(z_far * z_near) / (z_far - z_near), 0.0f,
426426
};
427427
// clang-format on

impeller/renderer/renderer_unittests.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ TEST_P(RendererTest, CanRenderPerspectiveCube) {
117117
auto desc = PipelineBuilder<VS, FS>::MakeDefaultPipelineDescriptor(*context);
118118
ASSERT_TRUE(desc.has_value());
119119
desc->SetCullMode(CullMode::kBackFace);
120+
desc->SetWindingOrder(WindingOrder::kCounterClockwise);
120121
desc->SetSampleCount(SampleCount::kCount4);
121122
auto pipeline =
122123
context->GetPipelineLibrary()->GetPipeline(std::move(desc)).Get();
@@ -184,7 +185,7 @@ TEST_P(RendererTest, CanRenderPerspectiveCube) {
184185

185186
uniforms.mvp =
186187
Matrix::MakePerspective(fov_y, pass.GetRenderTargetSize(), 0, 10) *
187-
Matrix::MakeTranslation({0, 0, -distance}) *
188+
Matrix::MakeTranslation({0, 0, distance}) *
188189
Matrix::MakeRotationX(Radians(euler_angles.x)) *
189190
Matrix::MakeRotationY(Radians(euler_angles.y)) *
190191
Matrix::MakeRotationZ(Radians(euler_angles.z));

0 commit comments

Comments
 (0)