From a1ea66072923dc5529bff8f63c490aaf64eb57f5 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Thu, 1 Feb 2024 15:29:13 -0800 Subject: [PATCH] Clamped downsample rate to 1/16th --- .../contents/filters/gaussian_blur_filter_contents.cc | 9 ++++++--- impeller/entity/shaders/gaussian_blur/kernel.glsl | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc index f9f9aa77ca758..79d39dde484cf 100644 --- a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc +++ b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc @@ -209,7 +209,10 @@ Scalar GaussianBlurFilterContents::CalculateScale(Scalar sigma) { } Scalar result = 4.0 / sigma; // Round to the nearest 1/(2^n) to get the best quality down scaling. - Scalar rounded = pow(2.0f, round(log2(result))); + Scalar exponent = round(log2f(result)); + // Don't scale down below 1/16th to preserve signal. + exponent = std::max(-4.0f, exponent); + Scalar rounded = powf(2.0f, exponent); return rounded; }; @@ -454,8 +457,8 @@ KernelPipeline::FragmentShader::KernelSamples GenerateBlurInfo( KernelPipeline::FragmentShader::KernelSamples result; result.sample_count = ((2 * parameters.blur_radius) / parameters.step_size) + 1; - // 32 comes from kernel.glsl. - FML_CHECK(result.sample_count < 32); + // 48 comes from kernel.glsl. + FML_CHECK(result.sample_count < 48); // Chop off the last samples if the radius >= 3 where they account for < 1.56% // of the result. diff --git a/impeller/entity/shaders/gaussian_blur/kernel.glsl b/impeller/entity/shaders/gaussian_blur/kernel.glsl index d8a544bf070f6..1aba5ad3e9342 100644 --- a/impeller/entity/shaders/gaussian_blur/kernel.glsl +++ b/impeller/entity/shaders/gaussian_blur/kernel.glsl @@ -16,7 +16,7 @@ struct KernelSample { uniform KernelSamples { int sample_count; - KernelSample samples[32]; + KernelSample samples[48]; } blur_info;