Skip to content

Commit

Permalink
[Impeller] Support 'texture_sampler_y_coord_scale' in more filters (f…
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdPaleLight authored Sep 26, 2022
1 parent e6cc7dd commit 759bc70
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 11 deletions.
8 changes: 5 additions & 3 deletions impeller/entity/contents/filters/blend_filter_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,11 @@ static std::optional<Snapshot> PipelineBlend(
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
Matrix::MakeTranslation(-coverage.origin) *
input->transform;

auto uniform_view = host_buffer.EmplaceUniform(frame_info);
VS::BindFrameInfo(cmd, uniform_view);
FS::FragInfo frag_info;
frag_info.texture_sampler_y_coord_scale =
input->texture->GetYCoordScale();
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));

pass.AddCommand(cmd);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,11 @@ std::optional<Snapshot> BorderMaskBlurFilterContents::RenderFilter(
frame_info.src_factor = src_color_factor_;
frame_info.inner_blur_factor = inner_blur_factor_;
frame_info.outer_blur_factor = outer_blur_factor_;
auto uniform_view = host_buffer.EmplaceUniform(frame_info);
VS::BindFrameInfo(cmd, uniform_view);
FS::FragInfo frag_info;
frag_info.texture_sampler_y_coord_scale =
input_snapshot->texture->GetYCoordScale();
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));

auto sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
FS::BindTextureSampler(cmd, input_snapshot->texture, sampler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ std::optional<Snapshot> LinearToSrgbFilterContents::RenderFilter(
VS::FrameInfo frame_info;
frame_info.mvp = Matrix::MakeOrthographic(ISize(1, 1));

FS::FragInfo frag_info;
frag_info.texture_sampler_y_coord_scale =
input_snapshot->texture->GetYCoordScale();

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

FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));

return pass.AddCommand(std::move(cmd));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ std::optional<Snapshot> SrgbToLinearFilterContents::RenderFilter(
VS::FrameInfo frame_info;
frame_info.mvp = Matrix::MakeOrthographic(ISize(1, 1));

FS::FragInfo frag_info;
frag_info.texture_sampler_y_coord_scale =
input_snapshot->texture->GetYCoordScale();

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

FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));

return pass.AddCommand(std::move(cmd));
Expand Down
9 changes: 8 additions & 1 deletion impeller/entity/shaders/blending/blend.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <impeller/texture.glsl>

uniform sampler2D texture_sampler_src;

uniform FragInfo {
float texture_sampler_y_coord_scale;
} frag_info;

in vec2 v_texture_coords;

out vec4 frag_color;

void main() {
frag_color = texture(texture_sampler_src, v_texture_coords);
frag_color = IPSample(texture_sampler_src, v_texture_coords,
frag_info.texture_sampler_y_coord_scale);
}
9 changes: 8 additions & 1 deletion impeller/entity/shaders/border_mask_blur.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <impeller/texture.glsl>

// Constant time mask blur for image borders.
//
// This mask blur extends the geometry of the source image (with clamp border
Expand All @@ -13,6 +15,10 @@

uniform sampler2D texture_sampler;

uniform FragInfo {
float texture_sampler_y_coord_scale;
} frag_info;

in vec2 v_texture_coords;
in vec2 v_sigma_uv;
in float v_src_factor;
Expand Down Expand Up @@ -48,7 +54,8 @@ float BoxBlurMask(vec2 uv) {
}

void main() {
vec4 image_color = texture(texture_sampler, v_texture_coords);
vec4 image_color = IPSample(texture_sampler, v_texture_coords,
frag_info.texture_sampler_y_coord_scale);
float blur_factor = BoxBlurMask(v_texture_coords);

float within_bounds =
Expand Down
8 changes: 7 additions & 1 deletion impeller/entity/shaders/linear_to_srgb_filter.frag
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@
// found in the LICENSE file.

#include <impeller/color.glsl>
#include <impeller/texture.glsl>

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

uniform sampler2D input_texture;

uniform FragInfo {
float texture_sampler_y_coord_scale;
} frag_info;

in vec2 v_position;
out vec4 frag_color;

void main() {
vec4 input_color = texture(input_texture, v_position);
vec4 input_color = IPSample(input_texture, v_position,
frag_info.texture_sampler_y_coord_scale);

for (int i = 0; i < 4; i++) {
if (input_color[i] <= 0.0031308) {
Expand Down
8 changes: 7 additions & 1 deletion impeller/entity/shaders/srgb_to_linear_filter.frag
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@
// found in the LICENSE file.

#include <impeller/color.glsl>
#include <impeller/texture.glsl>

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

uniform sampler2D input_texture;

uniform FragInfo {
float texture_sampler_y_coord_scale;
} frag_info;

in vec2 v_position;
out vec4 frag_color;

void main() {
vec4 input_color = texture(input_texture, v_position);
vec4 input_color = IPSample(input_texture, v_position,
frag_info.texture_sampler_y_coord_scale);

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

0 comments on commit 759bc70

Please sign in to comment.