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

Commit b46351a

Browse files
committed
Fix matrix filter; make the golden much better
1 parent 3ade737 commit b46351a

File tree

2 files changed

+32
-44
lines changed

2 files changed

+32
-44
lines changed

impeller/aiks/aiks_unittests.cc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2911,16 +2911,21 @@ TEST_P(AiksTest, MatrixBackdropFilter) {
29112911
canvas.DrawPaint({.color = Color::Black()});
29122912
canvas.SaveLayer({}, std::nullopt);
29132913
{
2914-
canvas.DrawCircle(
2915-
Point(200, 200), 100,
2916-
{.color = Color::Green(), .blend_mode = BlendMode::kPlus});
2917-
// Should render a second intersecting circle, offset by 100, 100.
2914+
canvas.DrawCircle(Point(200, 200), 100,
2915+
{.color = Color::Green().WithAlpha(0.5),
2916+
.blend_mode = BlendMode::kPlus});
2917+
// Should render a second circle, centered on the bottom-right-most edge of
2918+
// the circle.
29182919
canvas.SaveLayer({}, std::nullopt,
29192920
[](const FilterInput::Ref& input,
29202921
const Matrix& effect_transform, bool is_subpass) {
2922+
Matrix matrix =
2923+
Matrix::MakeTranslation(Vector2(1, 1) *
2924+
(100 + 100 * k1OverSqrt2)) *
2925+
Matrix::MakeScale(Vector2(1, 1) * 0.2) *
2926+
Matrix::MakeTranslation(Vector2(-100, -100));
29212927
return FilterContents::MakeMatrixFilter(
2922-
input, Matrix::MakeTranslation(Vector2(100, 100)),
2923-
{}, Matrix(), true);
2928+
input, matrix, {}, Matrix(), true);
29242929
});
29252930
canvas.Restore();
29262931
}

impeller/entity/contents/filters/matrix_filter_contents.cc

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -34,45 +34,28 @@ std::optional<Entity> MatrixFilterContents::RenderFilter(
3434
return std::nullopt;
3535
}
3636

37-
if (is_subpass_) {
38-
// There are two special quirks with how Matrix filters behave when used as
39-
// subpass backdrop filters:
40-
//
41-
// 1. For subpass backdrop filters, the snapshot transform is always just a
42-
// translation that positions the parent pass texture correctly relative
43-
// to the subpass texture. However, this translation always needs to be
44-
// applied in screen space.
45-
//
46-
// Since we know the snapshot transform will always have an identity
47-
// basis in this case, we safely reverse the order and apply the filter's
48-
// matrix within the snapshot transform space.
49-
//
50-
// 2. The filter's matrix needs to be applied within the space defined by
51-
// the scene's current transformation matrix (CTM). For example: If the
52-
// CTM is scaled up, then translations applied by the matrix should be
53-
// magnified accordingly.
54-
//
55-
// To accomplish this, we sandwitch the filter's matrix within the CTM in
56-
// both cases. But notice that for the subpass backdrop filter case, we
57-
// use the "effect transform" instead of the Entity's transform!
58-
//
59-
// That's because in the subpass backdrop filter case, the Entity's
60-
// transform isn't actually the captured CTM of the scene like it usually
61-
// is; instead, it's just a screen space translation that offsets the
62-
// backdrop texture (as mentioned above). And so we sneak the subpass's
63-
// captured CTM in through the effect transform.
64-
//
37+
// The filter's matrix needs to be applied within the space defined by the
38+
// scene's current transformation matrix (CTM). For example: If the CTM is
39+
// scaled up, then translations applied by the matrix should be magnified
40+
// accordingly.
41+
//
42+
// To accomplish this, we sandwitch the filter's matrix within the CTM in both
43+
// cases. But notice that for the subpass backdrop filter case, we use the
44+
// "effect transform" instead of the Entity's transform!
45+
//
46+
// That's because in the subpass backdrop filter case, the Entity's transform
47+
// isn't actually the captured CTM of the scene like it usually is; instead,
48+
// it's just a screen space translation that offsets the backdrop texture (as
49+
// mentioned above). And so we sneak the subpass's captured CTM in through the
50+
// effect transform.
51+
52+
auto transform = is_subpass_ ? effect_transform.Basis()
53+
: entity.GetTransformation().Basis();
54+
snapshot->transform = transform * //
55+
matrix_ * //
56+
transform.Invert() * //
57+
snapshot->transform;
6558

66-
snapshot->transform = snapshot->transform * //
67-
effect_transform * //
68-
matrix_ * //
69-
effect_transform.Invert();
70-
} else {
71-
snapshot->transform = entity.GetTransformation() * //
72-
matrix_ * //
73-
entity.GetTransformation().Invert() * //
74-
snapshot->transform;
75-
}
7659
snapshot->sampler_descriptor = sampler_descriptor_;
7760
return Entity::FromSnapshot(snapshot, entity.GetBlendMode(),
7861
entity.GetStencilDepth());

0 commit comments

Comments
 (0)