Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
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
34 changes: 22 additions & 12 deletions impeller/aiks/aiks_blur_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,29 @@ TEST_P(AiksTest, ClearBlendWithBlur) {
}

TEST_P(AiksTest, BlurHasNoEdge) {
Canvas canvas;
canvas.Scale(GetContentScale());
canvas.DrawPaint({});
Paint blur = {
.color = Color::Green(),
.mask_blur_descriptor =
Paint::MaskBlurDescriptor{
.style = FilterContents::BlurStyle::kNormal,
.sigma = Sigma(47.6),
},
Scalar sigma = 47.6;
auto callback = [&](AiksContext& renderer) -> std::optional<Picture> {
if (AiksTest::ImGuiBegin("Controls", nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::SliderFloat("Sigma", &sigma, 0, 50);
ImGui::End();
}
Canvas canvas;
canvas.Scale(GetContentScale());
canvas.DrawPaint({});
Paint blur = {
.color = Color::Green(),
.mask_blur_descriptor =
Paint::MaskBlurDescriptor{
.style = FilterContents::BlurStyle::kNormal,
.sigma = Sigma(sigma),
},
};
canvas.DrawRect(Rect::MakeXYWH(300, 300, 200, 200), blur);
return canvas.EndRecordingAsPicture();
};
canvas.DrawRect(Rect::MakeXYWH(300, 300, 200, 200), blur);
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));

ASSERT_TRUE(OpenPlaygroundHere(callback));
}

TEST_P(AiksTest, BlurredRectangleWithShader) {
Expand Down
10 changes: 7 additions & 3 deletions impeller/entity/contents/solid_rrect_blur_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@
namespace impeller {

namespace {
// Generous padding to make sure blurs with large sigmas are fully visible.
// Used to expand the geometry around the rrect.
// Generous padding to make sure blurs with large sigmas are fully visible. Used
// to expand the geometry around the rrect. Larger sigmas have more subtle
// gradients so they need larger padding to avoid hard cutoffs. Sigma is
// maximized to 3.5 since that should cover 99.95% of all samples. 3.0 should
// cover 99.7% but that was seen to be not enough for large sigmas.
Scalar PadForSigma(Scalar sigma) {
return sigma * 4.0;
Scalar scalar = std::min((1.0f / 47.6f) * sigma + 2.5f, 3.5f);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably get this down to 2.0x for small sigmas if we instead made the curve fit something like ln(x). I tried 2.0 as the bottom for the linear function but would hit some edges somewhere around sigma = 10.

return sigma * scalar;
}
} // namespace

Expand Down