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

Commit 0dbcd2e

Browse files
committed
[Impeller] started scaling the gaussian blur sigma to match skia output
1 parent 394744d commit 0dbcd2e

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

impeller/entity/contents/filters/directional_gaussian_blur_filter_contents.cc

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@
2323

2424
namespace impeller {
2525

26+
// This function was derived with polynomial regression when comparing the
27+
// results with Skia. Changing the curve below should invalidate this.
28+
//
29+
// The following data points were used:
30+
// 0 | 1
31+
// 75 | 0.8
32+
// 150 | 0.5
33+
// 300 | 0.22
34+
// 400 | 0.2
35+
// 500 | 0.15
36+
Sigma ScaleSigma(Sigma sigma) {
37+
// Limit the kernel size to 1000x1000 pixels, like Skia does.
38+
Scalar clamped = std::min(sigma.sigma, 500.0f);
39+
Scalar scalar = 1.02 - 3.89e-3 * clamped + 4.36e-06 * clamped * clamped;
40+
return Sigma(clamped * scalar);
41+
}
42+
2643
DirectionalGaussianBlurFilterContents::DirectionalGaussianBlurFilterContents() =
2744
default;
2845

@@ -76,8 +93,7 @@ std::optional<Entity> DirectionalGaussianBlurFilterContents::RenderFilter(
7693
return std::nullopt;
7794
}
7895

79-
// Limit the kernel size to 1000x1000 pixels, like Skia does.
80-
auto radius = std::min(Radius{blur_sigma_}.radius, 500.0f);
96+
auto radius = Radius{ScaleSigma(blur_sigma_)}.radius;
8197

8298
auto transform = entity.GetTransformation() * effect_transform.Basis();
8399
auto transformed_blur_radius =

0 commit comments

Comments
 (0)