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

Commit 5405f2c

Browse files
authored
[Impeller] Switch to nearest sampling for the text atlas (#39104)
1 parent 6aa30b2 commit 5405f2c

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

impeller/entity/contents/text_contents.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ static bool CommonRender(
7878
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info));
7979

8080
SamplerDescriptor sampler_desc;
81-
sampler_desc.min_filter = MinMagFilter::kLinear;
82-
sampler_desc.mag_filter = MinMagFilter::kLinear;
81+
sampler_desc.min_filter = MinMagFilter::kNearest;
82+
sampler_desc.mag_filter = MinMagFilter::kNearest;
8383
sampler_desc.mip_filter = MipFilter::kNone;
8484

8585
typename FS::FragInfo frag_info;
@@ -146,10 +146,10 @@ static bool CommonRender(
146146
for (const auto& point : unit_points) {
147147
typename VS::PerVertexData vtx;
148148
vtx.unit_position = point;
149-
vtx.destination_position = offset_glyph_position + Point(0.5, 0.5);
149+
vtx.destination_position = offset_glyph_position;
150150
vtx.destination_size = Point(glyph_position.glyph.bounds.size);
151-
vtx.source_position = atlas_position + Point(0.5, 0.5);
152-
vtx.source_glyph_size = atlas_glyph_size - Point(1.0, 1.0);
151+
vtx.source_position = atlas_position;
152+
vtx.source_glyph_size = atlas_glyph_size;
153153
if constexpr (std::is_same_v<TPipeline, GlyphAtlasPipeline>) {
154154
vtx.has_color =
155155
glyph_position.glyph.type == Glyph::Type::kBitmap ? 1.0 : 0.0;

impeller/entity/shaders/glyph_atlas.frag

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ out vec4 frag_color;
2121

2222
void main() {
2323
vec2 uv_size = v_source_glyph_size / frag_info.atlas_size;
24-
vec2 offset = v_source_position / frag_info.atlas_size;
24+
vec2 uv_position = v_source_position / frag_info.atlas_size;
2525
if (v_has_color == 1.0) {
2626
frag_color =
27-
texture(glyph_atlas_sampler, v_unit_position * uv_size + offset);
27+
texture(glyph_atlas_sampler, v_unit_position * uv_size + uv_position);
2828
} else {
2929
frag_color =
30-
texture(glyph_atlas_sampler, v_unit_position * uv_size + offset).aaaa *
30+
texture(glyph_atlas_sampler, v_unit_position * uv_size + uv_position)
31+
.aaaa *
3132
frag_info.text_color;
3233
}
3334
}

impeller/entity/shaders/glyph_atlas.vert

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ void main() {
2626
gl_Position = IPPositionForGlyphPosition(
2727
frame_info.mvp, unit_position, destination_position, destination_size);
2828
v_unit_position = unit_position;
29-
v_source_position = source_position;
29+
// Pixel snap the source (sampling) start position.
30+
v_source_position = round(source_position);
3031
v_source_glyph_size = source_glyph_size;
3132
v_has_color = has_color;
3233
}

0 commit comments

Comments
 (0)