[Impeller] Account for the backend-dependent space of rendered textures in gaussian blur (flutter/engine#35257)
* Add single pass variation to gaussian blur test * Account for the backend-dependent space of rendered textures in gaussian blur
This commit is contained in:
@@ -138,6 +138,10 @@ bool DirectionalGaussianBlurFilterContents::RenderFilter(
|
||||
frame_info.mvp = Matrix::MakeOrthographic(ISize(1, 1));
|
||||
|
||||
FS::FragInfo frag_info;
|
||||
frag_info.texture_sampler_y_coord_scale =
|
||||
input_snapshot->texture->GetYCoordScale();
|
||||
frag_info.alpha_mask_sampler_y_coord_scale =
|
||||
source_snapshot->texture->GetYCoordScale();
|
||||
frag_info.blur_sigma = transformed_blur.GetLength();
|
||||
frag_info.blur_radius = Radius{Sigma{frag_info.blur_sigma}}.radius;
|
||||
frag_info.blur_direction = input_snapshot->transform.Invert()
|
||||
|
||||
@@ -847,6 +847,7 @@ TEST_P(EntityTest, GaussianBlurFilter) {
|
||||
|
||||
const char* input_type_names[] = {"Texture", "Solid Color"};
|
||||
const char* blur_type_names[] = {"Image blur", "Mask blur"};
|
||||
const char* pass_variation_names[] = {"Two pass", "Directional"};
|
||||
const char* blur_style_names[] = {"Normal", "Solid", "Outer", "Inner"};
|
||||
const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"};
|
||||
const FilterContents::BlurStyle blur_styles[] = {
|
||||
@@ -860,6 +861,7 @@ TEST_P(EntityTest, GaussianBlurFilter) {
|
||||
static int selected_input_type = 0;
|
||||
static Color input_color = Color::Black();
|
||||
static int selected_blur_type = 0;
|
||||
static int selected_pass_variation = 0;
|
||||
static float blur_amount[2] = {20, 20};
|
||||
static int selected_blur_style = 0;
|
||||
static int selected_tile_mode = 3;
|
||||
@@ -882,6 +884,11 @@ TEST_P(EntityTest, GaussianBlurFilter) {
|
||||
}
|
||||
ImGui::Combo("Blur type", &selected_blur_type, blur_type_names,
|
||||
sizeof(blur_type_names) / sizeof(char*));
|
||||
if (selected_blur_type == 0) {
|
||||
ImGui::Combo("Pass variation", &selected_pass_variation,
|
||||
pass_variation_names,
|
||||
sizeof(pass_variation_names) / sizeof(char*));
|
||||
}
|
||||
ImGui::SliderFloat2("Sigma", &blur_amount[0], 0, 200);
|
||||
ImGui::Combo("Blur style", &selected_blur_style, blur_style_names,
|
||||
sizeof(blur_style_names) / sizeof(char*));
|
||||
@@ -921,9 +928,18 @@ TEST_P(EntityTest, GaussianBlurFilter) {
|
||||
input_size = input_rect.size;
|
||||
}
|
||||
|
||||
auto blur = FilterContents::MakeGaussianBlur(
|
||||
FilterInput::Make(input), Sigma{blur_amount[0]}, Sigma{blur_amount[1]},
|
||||
blur_styles[selected_blur_style], tile_modes[selected_tile_mode]);
|
||||
std::shared_ptr<FilterContents> blur;
|
||||
if (selected_pass_variation == 0) {
|
||||
blur = FilterContents::MakeGaussianBlur(
|
||||
FilterInput::Make(input), Sigma{blur_amount[0]},
|
||||
Sigma{blur_amount[1]}, blur_styles[selected_blur_style],
|
||||
tile_modes[selected_tile_mode]);
|
||||
} else {
|
||||
Vector2 blur_vector(blur_amount[0], blur_amount[1]);
|
||||
blur = FilterContents::MakeDirectionalGaussianBlur(
|
||||
FilterInput::Make(input), Sigma{blur_vector.GetLength()},
|
||||
blur_vector.Normalize());
|
||||
}
|
||||
|
||||
auto mask_blur = FilterContents::MakeBorderMaskBlur(
|
||||
FilterInput::Make(input), Sigma{blur_amount[0]}, Sigma{blur_amount[1]},
|
||||
|
||||
@@ -20,6 +20,9 @@ uniform sampler2D texture_sampler;
|
||||
uniform sampler2D alpha_mask_sampler;
|
||||
|
||||
uniform FragInfo {
|
||||
float texture_sampler_y_coord_scale;
|
||||
float alpha_mask_sampler_y_coord_scale;
|
||||
|
||||
vec2 texture_size;
|
||||
vec2 blur_direction;
|
||||
|
||||
@@ -59,21 +62,21 @@ void main() {
|
||||
total_color +=
|
||||
gaussian *
|
||||
IPSampleWithTileMode(
|
||||
texture_sampler, // sampler
|
||||
v_texture_coords + blur_uv_offset * i, // texture coordinates
|
||||
1.0, // y coordinate scale
|
||||
frag_info.tile_mode // tile mode
|
||||
texture_sampler, // sampler
|
||||
v_texture_coords + blur_uv_offset * i, // texture coordinates
|
||||
frag_info.texture_sampler_y_coord_scale, // y coordinate scale
|
||||
frag_info.tile_mode // tile mode
|
||||
);
|
||||
}
|
||||
|
||||
vec4 blur_color = total_color / gaussian_integral;
|
||||
|
||||
vec4 src_color =
|
||||
IPSampleWithTileMode(alpha_mask_sampler, // sampler
|
||||
v_src_texture_coords, // texture coordinates
|
||||
1.0, // y coordinate scale
|
||||
frag_info.tile_mode // tile mode
|
||||
);
|
||||
vec4 src_color = IPSampleWithTileMode(
|
||||
alpha_mask_sampler, // sampler
|
||||
v_src_texture_coords, // texture coordinates
|
||||
frag_info.alpha_mask_sampler_y_coord_scale, // y coordinate scale
|
||||
frag_info.tile_mode // tile mode
|
||||
);
|
||||
float blur_factor = frag_info.inner_blur_factor * float(src_color.a > 0) +
|
||||
frag_info.outer_blur_factor * float(src_color.a == 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user