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

Commit cae105f

Browse files
committed
Apply color filter to gradient decal borders
1 parent dc22f2e commit cae105f

13 files changed

+50
-16
lines changed

impeller/compiler/shader_lib/impeller/texture.glsl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,11 @@ vec4 IPSampleLinearWithTileMode(sampler2D tex,
114114
float y_coord_scale,
115115
vec2 half_texel,
116116
float x_tile_mode,
117-
float y_tile_mode) {
117+
float y_tile_mode,
118+
vec4 decal_border_color) {
118119
if (x_tile_mode == kTileModeDecal && (coords.x < 0 || coords.x >= 1) ||
119120
y_tile_mode == kTileModeDecal && (coords.y < 0 || coords.y >= 1)) {
120-
return vec4(0);
121+
return decal_border_color;
121122
}
122123

123124
return IPSampleLinear(tex, IPVec2Tile(coords, x_tile_mode, y_tile_mode),
@@ -152,9 +153,10 @@ vec4 IPSampleLinearWithTileMode(sampler2D tex,
152153
vec2 coords,
153154
float y_coord_scale,
154155
vec2 half_texel,
155-
float tile_mode) {
156+
float tile_mode,
157+
vec4 decal_border_color) {
156158
return IPSampleLinearWithTileMode(tex, coords, y_coord_scale, half_texel,
157-
tile_mode, tile_mode);
159+
tile_mode, tile_mode, decal_border_color);
158160
}
159161

160162
#endif

impeller/entity/contents/conical_gradient_contents.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ bool ConicalGradientContents::RenderTexture(const ContentContext& renderer,
140140
frag_info.center = center_;
141141
frag_info.radius = radius_;
142142
frag_info.tile_mode = static_cast<Scalar>(tile_mode_);
143+
frag_info.decal_border_color = decal_border_color_.Premultiply();
143144
frag_info.texture_sampler_y_coord_scale = gradient_texture->GetYCoordScale();
144145
frag_info.alpha = GetOpacity();
145146
frag_info.half_texel = Vector2(0.5 / gradient_texture->GetSize().width,
@@ -198,6 +199,7 @@ bool ConicalGradientContents::ApplyColorFilter(
198199
for (Color& color : colors_) {
199200
color = color_filter_proc(color);
200201
}
202+
decal_border_color_ = color_filter_proc(decal_border_color_);
201203
return true;
202204
}
203205

impeller/entity/contents/conical_gradient_contents.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class ConicalGradientContents final : public ColorSourceContents {
6060
std::vector<Color> colors_;
6161
std::vector<Scalar> stops_;
6262
Entity::TileMode tile_mode_;
63+
Color decal_border_color_ = Color::BlackTransparent();
6364
std::optional<Point> focus_;
6465
Scalar focus_radius_ = 0.0f;
6566

impeller/entity/contents/linear_gradient_contents.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ bool LinearGradientContents::RenderTexture(const ContentContext& renderer,
8282
frag_info.start_point = start_point_;
8383
frag_info.end_point = end_point_;
8484
frag_info.tile_mode = static_cast<Scalar>(tile_mode_);
85+
frag_info.decal_border_color = decal_border_color_.Premultiply();
8586
frag_info.texture_sampler_y_coord_scale = gradient_texture->GetYCoordScale();
8687
frag_info.alpha = GetOpacity();
8788
frag_info.half_texel = Vector2(0.5 / gradient_texture->GetSize().width,
@@ -189,6 +190,7 @@ bool LinearGradientContents::ApplyColorFilter(
189190
for (Color& color : colors_) {
190191
color = color_filter_proc(color);
191192
}
193+
decal_border_color_ = color_filter_proc(decal_border_color_);
192194
return true;
193195
}
194196

impeller/entity/contents/linear_gradient_contents.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class LinearGradientContents final : public ColorSourceContents {
6363
std::vector<Color> colors_;
6464
std::vector<Scalar> stops_;
6565
Entity::TileMode tile_mode_;
66+
Color decal_border_color_ = Color::BlackTransparent();
6667

6768
FML_DISALLOW_COPY_AND_ASSIGN(LinearGradientContents);
6869
};

impeller/entity/contents/radial_gradient_contents.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ bool RadialGradientContents::RenderTexture(const ContentContext& renderer,
139139
frag_info.center = center_;
140140
frag_info.radius = radius_;
141141
frag_info.tile_mode = static_cast<Scalar>(tile_mode_);
142+
frag_info.decal_border_color = decal_border_color_.Premultiply();
142143
frag_info.texture_sampler_y_coord_scale = gradient_texture->GetYCoordScale();
143144
frag_info.alpha = GetOpacity();
144145
frag_info.half_texel = Vector2(0.5 / gradient_texture->GetSize().width,
@@ -190,6 +191,7 @@ bool RadialGradientContents::ApplyColorFilter(
190191
for (Color& color : colors_) {
191192
color = color_filter_proc(color);
192193
}
194+
decal_border_color_ = color_filter_proc(decal_border_color_);
193195
return true;
194196
}
195197

impeller/entity/contents/radial_gradient_contents.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class RadialGradientContents final : public ColorSourceContents {
6161
std::vector<Color> colors_;
6262
std::vector<Scalar> stops_;
6363
Entity::TileMode tile_mode_;
64+
Color decal_border_color_ = Color::BlackTransparent();
6465

6566
FML_DISALLOW_COPY_AND_ASSIGN(RadialGradientContents);
6667
};

impeller/entity/contents/sweep_gradient_contents.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ bool SweepGradientContents::RenderTexture(const ContentContext& renderer,
147147
frag_info.scale = scale_;
148148
frag_info.texture_sampler_y_coord_scale = gradient_texture->GetYCoordScale();
149149
frag_info.tile_mode = static_cast<Scalar>(tile_mode_);
150+
frag_info.decal_border_color = decal_border_color_.Premultiply();
150151
frag_info.alpha = GetOpacity();
151152
frag_info.half_texel = Vector2(0.5 / gradient_texture->GetSize().width,
152153
0.5 / gradient_texture->GetSize().height);
@@ -197,6 +198,7 @@ bool SweepGradientContents::ApplyColorFilter(
197198
for (Color& color : colors_) {
198199
color = color_filter_proc(color);
199200
}
201+
decal_border_color_ = color_filter_proc(decal_border_color_);
200202
return true;
201203
}
202204

impeller/entity/contents/sweep_gradient_contents.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class SweepGradientContents final : public ColorSourceContents {
6464
std::vector<Color> colors_;
6565
std::vector<Scalar> stops_;
6666
Entity::TileMode tile_mode_;
67+
Color decal_border_color_ = Color::BlackTransparent();
6768

6869
FML_DISALLOW_COPY_AND_ASSIGN(SweepGradientContents);
6970
};

impeller/entity/shaders/conical_gradient_fill.frag

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ uniform FragInfo {
1414
highp vec2 center;
1515
float radius;
1616
float tile_mode;
17+
vec4 decal_border_color;
1718
float texture_sampler_y_coord_scale;
1819
float alpha;
1920
vec2 half_texel;
@@ -35,9 +36,13 @@ void main() {
3536
}
3637

3738
float t = res.x;
38-
frag_color = IPSampleLinearWithTileMode(
39-
texture_sampler, vec2(t, 0.5), frag_info.texture_sampler_y_coord_scale,
40-
frag_info.half_texel, frag_info.tile_mode);
39+
frag_color =
40+
IPSampleLinearWithTileMode(texture_sampler, //
41+
vec2(t, 0.5), //
42+
frag_info.texture_sampler_y_coord_scale, //
43+
frag_info.half_texel, //
44+
frag_info.tile_mode, //
45+
frag_info.decal_border_color);
4146
frag_color =
4247
vec4(frag_color.xyz * frag_color.a, frag_color.a) * frag_info.alpha;
4348
}

0 commit comments

Comments
 (0)