From 3eed34fa6f7ca9442c2bee8b93bb7465d6984259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Mon, 29 Jul 2024 21:26:03 +0200 Subject: [PATCH] Snap `Quad` lines to the pixel grid in `iced_wgpu` --- wgpu/src/shader/quad/solid.wgsl | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/wgpu/src/shader/quad/solid.wgsl b/wgpu/src/shader/quad/solid.wgsl index d908afbcb0..8eee16bb03 100644 --- a/wgpu/src/shader/quad/solid.wgsl +++ b/wgpu/src/shader/quad/solid.wgsl @@ -30,6 +30,15 @@ fn solid_vs_main(input: SolidVertexInput) -> SolidVertexOutput { var pos: vec2 = (input.pos + min(input.shadow_offset, vec2(0.0, 0.0)) - input.shadow_blur_radius) * globals.scale; var scale: vec2 = (input.scale + vec2(abs(input.shadow_offset.x), abs(input.shadow_offset.y)) + input.shadow_blur_radius * 2.0) * globals.scale; + var snap: vec2 = vec2(0.0, 0.0); + + if input.scale.x == 1.0 { + snap.x = round(pos.x) - pos.x; + } + + if input.scale.y == 1.0 { + snap.y = round(pos.y) - pos.y; + } var min_border_radius = min(input.scale.x, input.scale.y) * 0.5; var border_radius: vec4 = vec4( @@ -43,13 +52,13 @@ fn solid_vs_main(input: SolidVertexInput) -> SolidVertexOutput { vec4(scale.x + 1.0, 0.0, 0.0, 0.0), vec4(0.0, scale.y + 1.0, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), - vec4(pos - vec2(0.5, 0.5), 0.0, 1.0) + vec4(pos - vec2(0.5, 0.5) + snap, 0.0, 1.0) ); out.position = globals.transform * transform * vec4(vertex_position(input.vertex_index), 0.0, 1.0); out.color = input.color; out.border_color = input.border_color; - out.pos = input.pos * globals.scale; + out.pos = input.pos * globals.scale + snap; out.scale = input.scale * globals.scale; out.border_radius = border_radius * globals.scale; out.border_width = input.border_width * globals.scale;