Skip to content

Commit

Permalink
Clamped downsample rate to 1/16th
Browse files Browse the repository at this point in the history
  • Loading branch information
gaaclarke committed Feb 1, 2024
1 parent bd67e03 commit a1ea660
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/shaders/gaussian_blur/kernel.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct KernelSample {

uniform KernelSamples {
int sample_count;
KernelSample samples[32];
KernelSample samples[48];
}
blur_info;

Expand Down

0 comments on commit a1ea660

Please sign in to comment.