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

Commit 8ef540f

Browse files
committed
[Impeller] Support 'texture_sampler_y_coord_scale' in more filters
1 parent d440856 commit 8ef540f

File tree

8 files changed

+50
-11
lines changed

8 files changed

+50
-11
lines changed

impeller/entity/contents/filters/blend_filter_contents.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,11 @@ static std::optional<Snapshot> PipelineBlend(
192192
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
193193
Matrix::MakeTranslation(-coverage.origin) *
194194
input->transform;
195-
196-
auto uniform_view = host_buffer.EmplaceUniform(frame_info);
197-
VS::BindFrameInfo(cmd, uniform_view);
195+
FS::FragInfo frag_info;
196+
frag_info.texture_sampler_y_coord_scale =
197+
input->texture->GetYCoordScale();
198+
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
199+
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
198200

199201
pass.AddCommand(cmd);
200202
return true;

impeller/entity/contents/filters/border_mask_blur_filter_contents.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,11 @@ std::optional<Snapshot> BorderMaskBlurFilterContents::RenderFilter(
108108
frame_info.src_factor = src_color_factor_;
109109
frame_info.inner_blur_factor = inner_blur_factor_;
110110
frame_info.outer_blur_factor = outer_blur_factor_;
111-
auto uniform_view = host_buffer.EmplaceUniform(frame_info);
112-
VS::BindFrameInfo(cmd, uniform_view);
111+
FS::FragInfo frag_info;
112+
frag_info.texture_sampler_y_coord_scale =
113+
input_snapshot->texture->GetYCoordScale();
114+
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
115+
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
113116

114117
auto sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
115118
FS::BindTextureSampler(cmd, input_snapshot->texture, sampler);

impeller/entity/contents/filters/linear_to_srgb_filter_contents.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,13 @@ std::optional<Snapshot> LinearToSrgbFilterContents::RenderFilter(
6161
VS::FrameInfo frame_info;
6262
frame_info.mvp = Matrix::MakeOrthographic(ISize(1, 1));
6363

64+
FS::FragInfo frag_info;
65+
frag_info.texture_sampler_y_coord_scale =
66+
input_snapshot->texture->GetYCoordScale();
67+
6468
auto sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
6569
FS::BindInputTexture(cmd, input_snapshot->texture, sampler);
66-
70+
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
6771
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
6872

6973
return pass.AddCommand(std::move(cmd));

impeller/entity/contents/filters/srgb_to_linear_filter_contents.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,13 @@ std::optional<Snapshot> SrgbToLinearFilterContents::RenderFilter(
6161
VS::FrameInfo frame_info;
6262
frame_info.mvp = Matrix::MakeOrthographic(ISize(1, 1));
6363

64+
FS::FragInfo frag_info;
65+
frag_info.texture_sampler_y_coord_scale =
66+
input_snapshot->texture->GetYCoordScale();
67+
6468
auto sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
6569
FS::BindInputTexture(cmd, input_snapshot->texture, sampler);
66-
70+
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
6771
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
6872

6973
return pass.AddCommand(std::move(cmd));

impeller/entity/shaders/blending/blend.frag

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
#include <impeller/texture.glsl>
6+
57
uniform sampler2D texture_sampler_src;
68

9+
uniform FragInfo {
10+
float texture_sampler_y_coord_scale;
11+
} frag_info;
12+
713
in vec2 v_texture_coords;
814

915
out vec4 frag_color;
1016

1117
void main() {
12-
frag_color = texture(texture_sampler_src, v_texture_coords);
18+
frag_color = IPSample(texture_sampler_src, v_texture_coords,
19+
frag_info.texture_sampler_y_coord_scale);
1320
}

impeller/entity/shaders/border_mask_blur.frag

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
#include <impeller/texture.glsl>
6+
57
// Constant time mask blur for image borders.
68
//
79
// This mask blur extends the geometry of the source image (with clamp border
@@ -13,6 +15,10 @@
1315

1416
uniform sampler2D texture_sampler;
1517

18+
uniform FragInfo {
19+
float texture_sampler_y_coord_scale;
20+
} frag_info;
21+
1622
in vec2 v_texture_coords;
1723
in vec2 v_sigma_uv;
1824
in float v_src_factor;
@@ -48,7 +54,8 @@ float BoxBlurMask(vec2 uv) {
4854
}
4955

5056
void main() {
51-
vec4 image_color = texture(texture_sampler, v_texture_coords);
57+
vec4 image_color = IPSample(texture_sampler, v_texture_coords,
58+
frag_info.texture_sampler_y_coord_scale);
5259
float blur_factor = BoxBlurMask(v_texture_coords);
5360

5461
float within_bounds =

impeller/entity/shaders/linear_to_srgb_filter.frag

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,24 @@
33
// found in the LICENSE file.
44

55
#include <impeller/color.glsl>
6+
#include <impeller/texture.glsl>
67

78
// A color filter that applies the sRGB gamma curve to the color.
89
//
910
// This filter is used so that the colors are suitable for display in monitors.
1011

1112
uniform sampler2D input_texture;
1213

14+
uniform FragInfo {
15+
float texture_sampler_y_coord_scale;
16+
} frag_info;
17+
1318
in vec2 v_position;
1419
out vec4 frag_color;
1520

1621
void main() {
17-
vec4 input_color = texture(input_texture, v_position);
22+
vec4 input_color = IPSample(input_texture, v_position,
23+
frag_info.texture_sampler_y_coord_scale);
1824

1925
for (int i = 0; i < 4; i++) {
2026
if (input_color[i] <= 0.0031308) {

impeller/entity/shaders/srgb_to_linear_filter.frag

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,23 @@
33
// found in the LICENSE file.
44

55
#include <impeller/color.glsl>
6+
#include <impeller/texture.glsl>
67

78
// Creates a color filter that applies the inverse of the sRGB gamma curve
89
// to the RGB channels.
910

1011
uniform sampler2D input_texture;
1112

13+
uniform FragInfo {
14+
float texture_sampler_y_coord_scale;
15+
} frag_info;
16+
1217
in vec2 v_position;
1318
out vec4 frag_color;
1419

1520
void main() {
16-
vec4 input_color = texture(input_texture, v_position);
21+
vec4 input_color = IPSample(input_texture, v_position,
22+
frag_info.texture_sampler_y_coord_scale);
1723

1824
for (int i = 0; i < 4; i++) {
1925
if (input_color[i] <= 0.04045) {

0 commit comments

Comments
 (0)