From 4a57a50d586739e71201bd213679d7d15c2eda93 Mon Sep 17 00:00:00 2001 From: Taylor Holliday Date: Sun, 2 Oct 2022 19:23:29 -0700 Subject: [PATCH] re #3. Improve text sharpness. Should use `textureLoad` instead of `textureSample`. --- src/lib.rs | 18 ++++++++---------- src/shader.wgsl | 7 ++----- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 976f516..455b917 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -564,8 +564,6 @@ impl Vger { pub fn text(&mut self, text: &str, size: u32, color: Color, max_width: Option) { 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; @@ -588,10 +586,10 @@ 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); @@ -599,10 +597,10 @@ impl Vger { // 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); diff --git a/src/shader.wgsl b/src/shader.wgsl index 1f9af84..7d208b1 100644 --- a/src/shader.wgsl +++ b/src/shader.wgsl @@ -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(in.t), 0).r; + // let a = textureSample(glyph_atlas, samp, (in.t+0.5)/1024.0).r; + let a = textureLoad(glyph_atlas, vec2(in.t), 0).r; let s = scissor_mask(scissor, in.p); @@ -627,9 +627,6 @@ fn fs_main( let c = paint.inner_color; var color = vec4(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; //}