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
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ std::optional<Entity> DirectionalGaussianBlurFilterContents::RenderFilter(
FS::BlurInfo frag_info;
auto r = Radius{transformed_blur_radius_length};
frag_info.blur_sigma = Sigma{r}.sigma;
frag_info.blur_radius = r.radius;
frag_info.blur_radius = std::round(r.radius);

// The blur direction is in input UV space.
frag_info.blur_uv_offset =
Expand Down Expand Up @@ -240,6 +240,8 @@ std::optional<Entity> DirectionalGaussianBlurFilterContents::RenderFilter(
source_descriptor.height_address_mode = SamplerAddressMode::kRepeat;
break;
}
input_descriptor.mag_filter = MinMagFilter::kLinear;
input_descriptor.min_filter = MinMagFilter::kLinear;

bool has_alpha_mask = blur_style_ != BlurStyle::kNormal;
bool has_decal_specialization =
Expand Down
23 changes: 16 additions & 7 deletions impeller/entity/shaders/gaussian_blur/gaussian_blur.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,23 @@ void main() {
f16vec4 total_color = f16vec4(0.0hf);
float16_t gaussian_integral = 0.0hf;

for (float16_t i = -blur_info.blur_radius; i <= blur_info.blur_radius; i++) {
float16_t gaussian = IPGaussian(i, blur_info.blur_sigma);
for (float16_t i = -blur_info.blur_radius; i <= blur_info.blur_radius;
i += 2.0hf) {
float16_t w1 = IPGaussian(i, blur_info.blur_sigma);
float16_t w2 = IPGaussian(i + 1.0hf, blur_info.blur_sigma);
float16_t gaussian = w1 + w2;

f16vec2 offset_1 = blur_info.blur_uv_offset * i;
f16vec2 offset_2 = offset_1 + blur_info.blur_uv_offset;
vec2 pos_c1 = v_texture_coords + offset_1;
vec2 pos_c2 = v_texture_coords + offset_2;

vec2 coords = (w1 * pos_c1 + w2 * pos_c2) / gaussian;

gaussian_integral += gaussian;
total_color +=
gaussian * Sample(texture_sampler, // sampler
v_texture_coords + blur_info.blur_uv_offset *
i // texture coordinates
);
total_color += gaussian * Sample(texture_sampler, // sampler
coords // texture coordinates
);
Copy link
Member

@bdero bdero Apr 3, 2023

Choose a reason for hiding this comment

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

Leveraging linear sampling is a great idea. :)

Instead of fanning out the two sides here, I think just taking the original and doing something like for (float16_t i = round(-blur_info.blur_radius); i <= blur_info.blur_radius; i += 2.hf) would be the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should we just round in the contents so blur_radius is always integral?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah rounding on the CPU seems good

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops, where did it go...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh nvm, its there

}

frag_color = total_color / gaussian_integral;
Expand Down
Loading