Skip to content

Commit

Permalink
Merge pull request #2531 from iced-rs/fix/snap-quad-lines-in-wgpu
Browse files Browse the repository at this point in the history
Snap `Quad` lines to the pixel grid in `iced_wgpu`
  • Loading branch information
hecrj authored Jul 29, 2024
2 parents 6734d18 + 3eed34f commit ddd48ca
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions wgpu/src/shader/quad/solid.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ fn solid_vs_main(input: SolidVertexInput) -> SolidVertexOutput {

var pos: vec2<f32> = (input.pos + min(input.shadow_offset, vec2<f32>(0.0, 0.0)) - input.shadow_blur_radius) * globals.scale;
var scale: vec2<f32> = (input.scale + vec2<f32>(abs(input.shadow_offset.x), abs(input.shadow_offset.y)) + input.shadow_blur_radius * 2.0) * globals.scale;
var snap: vec2<f32> = vec2<f32>(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<f32> = vec4<f32>(
Expand All @@ -43,13 +52,13 @@ fn solid_vs_main(input: SolidVertexInput) -> SolidVertexOutput {
vec4<f32>(scale.x + 1.0, 0.0, 0.0, 0.0),
vec4<f32>(0.0, scale.y + 1.0, 0.0, 0.0),
vec4<f32>(0.0, 0.0, 1.0, 0.0),
vec4<f32>(pos - vec2<f32>(0.5, 0.5), 0.0, 1.0)
vec4<f32>(pos - vec2<f32>(0.5, 0.5) + snap, 0.0, 1.0)
);

out.position = globals.transform * transform * vec4<f32>(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;
Expand Down

0 comments on commit ddd48ca

Please sign in to comment.