diff --git a/wgpu/src/shader/quad/gradient.wgsl b/wgpu/src/shader/quad/gradient.wgsl index a1b4b107..7eab8ad1 100644 --- a/wgpu/src/shader/quad/gradient.wgsl +++ b/wgpu/src/shader/quad/gradient.wgsl @@ -33,6 +33,9 @@ fn gradient_vs_main(input: GradientVertexInput) -> GradientVertexOutput { var pos: vec2 = input.position_and_scale.xy * globals.scale; var scale: vec2 = input.position_and_scale.zw * globals.scale; + var pos_snap: vec2 = vec2(round(pos.x + 0.01) - pos.x, round(pos.y + 0.01) - pos.y); + var scale_snap: vec2 = vec2(round(scale.x + 0.01) - scale.x, round(scale.y + 0.01) - scale.y); + var min_border_radius = min(input.position_and_scale.z, input.position_and_scale.w) * 0.5; var border_radius: vec4 = vec4( min(input.border_radius.x, min_border_radius), @@ -42,10 +45,10 @@ fn gradient_vs_main(input: GradientVertexInput) -> GradientVertexOutput { ); var transform: mat4x4 = mat4x4( - vec4(scale.x + 1.0, 0.0, 0.0, 0.0), - vec4(0.0, scale.y + 1.0, 0.0, 0.0), + vec4(scale.x + scale_snap.x + 1.0, 0.0, 0.0, 0.0), + vec4(0.0, scale.y + scale_snap.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 + pos_snap - vec2(0.5, 0.5), 0.0, 1.0) ); out.position = globals.transform * transform * vec4(vertex_position(input.vertex_index), 0.0, 1.0); @@ -55,7 +58,7 @@ fn gradient_vs_main(input: GradientVertexInput) -> GradientVertexOutput { out.colors_4 = input.colors_4; out.offsets = input.offsets; out.direction = input.direction * globals.scale; - out.position_and_scale = vec4(pos, scale); + out.position_and_scale = vec4(pos + pos_snap, scale + scale_snap); out.border_color = premultiply(input.border_color); out.border_radius = border_radius * globals.scale; out.border_width = input.border_width * globals.scale; diff --git a/wgpu/src/shader/quad/solid.wgsl b/wgpu/src/shader/quad/solid.wgsl index f4c39f3d..3a0de625 100644 --- a/wgpu/src/shader/quad/solid.wgsl +++ b/wgpu/src/shader/quad/solid.wgsl @@ -30,15 +30,9 @@ 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 pos_snap: vec2 = vec2(round(pos.x + 0.01) - pos.x, round(pos.y + 0.01) - pos.y); + var scale_snap: vec2 = vec2(round(scale.x + 0.01) - scale.x, round(scale.y + 0.01) - scale.y); var min_border_radius = min(input.scale.x, input.scale.y) * 0.5; var border_radius: vec4 = vec4( @@ -49,17 +43,17 @@ fn solid_vs_main(input: SolidVertexInput) -> SolidVertexOutput { ); var transform: mat4x4 = mat4x4( - vec4(scale.x + 1.0, 0.0, 0.0, 0.0), - vec4(0.0, scale.y + 1.0, 0.0, 0.0), + vec4(scale.x + scale_snap.x + 1.0, 0.0, 0.0, 0.0), + vec4(0.0, scale.y + scale_snap.y + 1.0, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), - vec4(pos - vec2(0.5, 0.5) + snap, 0.0, 1.0) + vec4(pos + pos_snap - vec2(0.5, 0.5), 0.0, 1.0) ); out.position = globals.transform * transform * vec4(vertex_position(input.vertex_index), 0.0, 1.0); out.color = premultiply(input.color); out.border_color = premultiply(input.border_color); - out.pos = input.pos * globals.scale + snap; - out.scale = input.scale * globals.scale; + out.pos = input.pos * globals.scale + pos_snap; + out.scale = input.scale * globals.scale + scale_snap; out.border_radius = border_radius * globals.scale; out.border_width = input.border_width * globals.scale; out.shadow_color = premultiply(input.shadow_color); diff --git a/widget/src/toggler.rs b/widget/src/toggler.rs index 70c38ce2..786844b2 100644 --- a/widget/src/toggler.rs +++ b/widget/src/toggler.rs @@ -424,7 +424,7 @@ where .style(&self.class, self.last_status.unwrap_or(Status::Disabled)); let border_radius = bounds.height / BORDER_RADIUS_RATIO; - let space = SPACE_RATIO * bounds.height; + let space = (SPACE_RATIO * bounds.height).round(); let toggler_background_bounds = Rectangle { x: bounds.x + space,