Skip to content

Commit

Permalink
re #3. Improve text sharpness.
Browse files Browse the repository at this point in the history
Should use `textureLoad` instead of `textureSample`.
  • Loading branch information
wtholliday committed Oct 3, 2022
1 parent 670050f commit 4a57a50
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
18 changes: 8 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,6 @@ impl Vger {
pub fn text(&mut self, text: &str, size: u32, color: Color, max_width: Option<f32>) {
self.setup_layout(text, size, max_width);

let padding = 2.0_f32;

let scale = self.device_px_ratio;
let scaled_size = size as f32 * scale;

Expand All @@ -588,21 +586,21 @@ impl Vger {
assert!(glyph.height == rect.height as usize);

prim.quad_bounds = [
(glyph.x - padding) / scale,
(glyph.y - padding) / scale,
(glyph.x + padding + glyph.width as f32) / scale,
(glyph.y + padding + glyph.height as f32) / scale,
(glyph.x),
(glyph.y),
(glyph.x + glyph.width as f32),
(glyph.y + glyph.height as f32),
];
// println!("quad_bounds: {:?}", prim.quad_bounds);

// The extra +/- 1.0 offset ensures we cover the same
// number of pixels when rasterizing as the glyph
// in the texture.
prim.tex_bounds = [
rect.x as f32 - padding,
(rect.y + rect.height) as f32 + padding,
(rect.x + rect.width) as f32 + padding + 1.0,
rect.y as f32 - padding - 1.0,
rect.x as f32,
(rect.y + rect.height) as f32,
(rect.x + rect.width) as f32,
rect.y as f32,
];
prim.paint = paint.index as u32;
// println!("tex_bounds: {:?}", prim.tex_bounds);
Expand Down
7 changes: 2 additions & 5 deletions src/shader.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,8 @@ fn fs_main(
let scissor = scissors.scissors[prim.scissor];

// Look up glyph alpha (if not a glyph, still have to because of wgsl).
let a = textureSample(glyph_atlas, samp, (in.t+0.5)/1024.0).r;
// let a = textureLoad(glyph_atlas, vec2<i32>(in.t), 0).r;
// let a = textureSample(glyph_atlas, samp, (in.t+0.5)/1024.0).r;
let a = textureLoad(glyph_atlas, vec2<i32>(in.t), 0).r;

let s = scissor_mask(scissor, in.p);

Expand All @@ -627,9 +627,6 @@ fn fs_main(
let c = paint.inner_color;
var color = vec4<f32>(c.rgb, a);

//auto c = paint.innerColor;
//auto color = float4(c.rgb, c.a * glyphs.sample(glyphSampler, in.t).a);

//if(glow) {
// color.a *= paint.glow;
//}
Expand Down

0 comments on commit 4a57a50

Please sign in to comment.