Revert "Merge pull request #2962 from iced-rs/fix/blurry-quads"

This reverts commit 03326b955b, reversing
changes made to 7c5a4bc465.
This commit is contained in:
Héctor Ramón Jiménez 2025-05-28 22:51:10 +02:00
parent 6c0962c5c3
commit 9d4e849a0e
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
31 changed files with 78 additions and 59 deletions

View file

@ -147,6 +147,8 @@ impl Pipeline {
6 => Float32x2,
// Layer
7 => Sint32,
// Snap
8 => Uint32,
),
}],
compilation_options:
@ -241,7 +243,7 @@ impl State {
[bounds.width, bounds.height],
f32::from(image.rotation),
image.opacity,
scale,
image.snap,
atlas_entry,
match image.filter_method {
crate::core::image::FilterMethod::Nearest => {
@ -274,7 +276,7 @@ impl State {
size,
f32::from(svg.rotation),
svg.opacity,
scale,
true,
atlas_entry,
nearest_instances,
);
@ -504,6 +506,7 @@ struct Instance {
_position_in_atlas: [f32; 2],
_size_in_atlas: [f32; 2],
_layer: u32,
_snap: u32,
}
impl Instance {
@ -521,21 +524,14 @@ struct Uniforms {
}
fn add_instances(
mut image_position: [f32; 2],
mut image_size: [f32; 2],
image_position: [f32; 2],
image_size: [f32; 2],
rotation: f32,
opacity: f32,
scale: f32,
snap: bool,
entry: &atlas::Entry,
instances: &mut Vec<Instance>,
) {
let snap = |coordinate: f32| (coordinate * scale).round() / scale;
image_position[0] = snap(image_position[0]);
image_position[1] = snap(image_position[1]);
image_size[0] = snap(image_size[0]);
image_size[1] = snap(image_size[1]);
let center = [
image_position[0] + image_size[0] / 2.0,
image_position[1] + image_size[1] / 2.0,
@ -549,6 +545,7 @@ fn add_instances(
image_size,
rotation,
opacity,
snap,
allocation,
instances,
);
@ -578,8 +575,8 @@ fn add_instances(
];
add_instance(
position, center, size, rotation, opacity, allocation,
instances,
position, center, size, rotation, opacity, snap,
allocation, instances,
);
}
}
@ -593,6 +590,7 @@ fn add_instance(
size: [f32; 2],
rotation: f32,
opacity: f32,
snap: bool,
allocation: &atlas::Allocation,
instances: &mut Vec<Instance>,
) {
@ -615,6 +613,7 @@ fn add_instance(
(height as f32 - 1.0) / atlas::SIZE as f32,
],
_layer: layer as u32,
_snap: snap as u32,
};
instances.push(instance);

View file

@ -17,6 +17,7 @@ struct VertexInput {
@location(5) atlas_pos: vec2<f32>,
@location(6) atlas_scale: vec2<f32>,
@location(7) layer: i32,
@location(8) snap: u32,
}
struct VertexOutput {
@ -53,7 +54,11 @@ fn vs_main(input: VertexInput) -> VertexOutput {
// Calculate the final position of the vertex
out.position = vec4(vec2(globals.scale_factor), 1.0, 1.0) * (vec4<f32>(input.center, 0.0, 0.0) + rotate * vec4<f32>(v_pos, 0.0, 1.0));
out.position = round(out.position);
if bool(input.snap) {
out.position = round(out.position);
}
out.position = globals.transform * out.position;
return out;

View file

@ -33,9 +33,6 @@ fn gradient_vs_main(input: GradientVertexInput) -> GradientVertexOutput {
var pos: vec2<f32> = input.position_and_scale.xy * globals.scale;
var scale: vec2<f32> = input.position_and_scale.zw * globals.scale;
var pos_snap: vec2<f32> = round(pos + vec2(0.01, 0.01)) - pos;
var scale_snap: vec2<f32> = round(pos + scale + vec2(0.01, 0.01)) - pos - pos_snap - scale;
var min_border_radius = min(input.position_and_scale.z, input.position_and_scale.w) * 0.5;
var border_radius: vec4<f32> = vec4<f32>(
min(input.border_radius.x, min_border_radius),
@ -45,10 +42,10 @@ fn gradient_vs_main(input: GradientVertexInput) -> GradientVertexOutput {
);
var transform: mat4x4<f32> = mat4x4<f32>(
vec4<f32>(scale.x + scale_snap.x + 1.0, 0.0, 0.0, 0.0),
vec4<f32>(0.0, scale.y + scale_snap.y + 1.0, 0.0, 0.0),
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 + pos_snap, 0.0, 1.0)
vec4<f32>(pos - vec2<f32>(0.5, 0.5), 0.0, 1.0)
);
out.position = globals.transform * transform * vec4<f32>(vertex_position(input.vertex_index), 0.0, 1.0);
@ -58,7 +55,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<f32>(pos + pos_snap, scale + scale_snap);
out.position_and_scale = vec4<f32>(pos, scale);
out.border_color = premultiply(input.border_color);
out.border_radius = border_radius * globals.scale;
out.border_width = input.border_width * globals.scale;

View file

@ -30,9 +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);
var pos_snap: vec2<f32> = round(pos + vec2(0.01, 0.01)) - pos;
var scale_snap: vec2<f32> = round(pos + scale + vec2(0.01, 0.01)) - pos - pos_snap - scale;
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>(
@ -43,17 +49,17 @@ fn solid_vs_main(input: SolidVertexInput) -> SolidVertexOutput {
);
var transform: mat4x4<f32> = mat4x4<f32>(
vec4<f32>(scale.x + scale_snap.x + 1.0, 0.0, 0.0, 0.0),
vec4<f32>(0.0, scale.y + scale_snap.y + 1.0, 0.0, 0.0),
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 + pos_snap, 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 = premultiply(input.color);
out.border_color = premultiply(input.border_color);
out.pos = input.pos * globals.scale + pos_snap;
out.scale = input.scale * globals.scale + scale_snap;
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;
out.shadow_color = premultiply(input.shadow_color);