From acad6d63d2d4c82747bf9a4162fdc335959f235d Mon Sep 17 00:00:00 2001 From: Adam Scott Date: Wed, 24 Jan 2024 11:08:33 -0500 Subject: [PATCH] Reinstate rounding for sprites + keep ci rounding for draw only --- scene/2d/animated_sprite_2d.cpp | 4 ++++ scene/2d/sprite_2d.cpp | 8 ++++++++ servers/rendering/renderer_canvas_cull.cpp | 14 ++++++++------ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/scene/2d/animated_sprite_2d.cpp b/scene/2d/animated_sprite_2d.cpp index 9022bf978ff7..699d09c0d3d1 100644 --- a/scene/2d/animated_sprite_2d.cpp +++ b/scene/2d/animated_sprite_2d.cpp @@ -267,6 +267,10 @@ void AnimatedSprite2D::_notification(int p_what) { ofs -= s / 2; } + if (get_viewport() && get_viewport()->is_snap_2d_transforms_to_pixel_enabled()) { + ofs = ofs.round(); + } + Rect2 dst_rect(ofs, s); if (hflip) { diff --git a/scene/2d/sprite_2d.cpp b/scene/2d/sprite_2d.cpp index a79e6392d466..3c19dd002091 100644 --- a/scene/2d/sprite_2d.cpp +++ b/scene/2d/sprite_2d.cpp @@ -98,6 +98,10 @@ void Sprite2D::_get_rects(Rect2 &r_src_rect, Rect2 &r_dst_rect, bool &r_filter_c dest_offset -= frame_size / 2; } + if (get_viewport() && get_viewport()->is_snap_2d_transforms_to_pixel_enabled()) { + dest_offset = dest_offset.round(); + } + r_dst_rect = Rect2(dest_offset, frame_size); if (hflip) { @@ -397,6 +401,10 @@ Rect2 Sprite2D::get_rect() const { ofs -= Size2(s) / 2; } + if (get_viewport() && get_viewport()->is_snap_2d_transforms_to_pixel_enabled()) { + ofs = ofs.round(); + } + if (s == Size2(0, 0)) { s = Size2(1, 1); } diff --git a/servers/rendering/renderer_canvas_cull.cpp b/servers/rendering/renderer_canvas_cull.cpp index 8c2c4f4239cc..edcd1ed354f2 100644 --- a/servers/rendering/renderer_canvas_cull.cpp +++ b/servers/rendering/renderer_canvas_cull.cpp @@ -248,12 +248,14 @@ void RendererCanvasCull::_cull_canvas_item(Item *p_canvas_item, const Transform2 } Transform2D ci_xform = ci->xform; - Transform2D xform = p_transform; + Transform2D rounded_ci_xform = ci->xform; + Transform2D transform = p_transform; if (snapping_2d_transforms_to_pixel) { - ci_xform.columns[2] = ci_xform.columns[2].round(); - xform.columns[2] = xform.columns[2].round(); + rounded_ci_xform.columns[2] = rounded_ci_xform.columns[2].round(); + transform.columns[2] = transform.columns[2].round(); } - ci_xform = xform * ci_xform; + ci_xform = transform * ci_xform; + rounded_ci_xform = transform * rounded_ci_xform; Rect2 global_rect = ci_xform.xform(rect); global_rect.position += p_clip_rect.position; @@ -330,7 +332,7 @@ void RendererCanvasCull::_cull_canvas_item(Item *p_canvas_item, const Transform2 canvas_group_from = r_z_last_list[zidx]; } - _attach_canvas_item_for_draw(ci, p_canvas_clip, r_z_list, r_z_last_list, ci_xform, p_clip_rect, global_rect, modulate, p_z, p_material_owner, use_canvas_group, canvas_group_from); + _attach_canvas_item_for_draw(ci, p_canvas_clip, r_z_list, r_z_last_list, rounded_ci_xform, p_clip_rect, global_rect, modulate, p_z, p_material_owner, use_canvas_group, canvas_group_from); } } else { RendererCanvasRender::Item *canvas_group_from = nullptr; @@ -346,7 +348,7 @@ void RendererCanvasCull::_cull_canvas_item(Item *p_canvas_item, const Transform2 } _cull_canvas_item(child_items[i], ci_xform, p_clip_rect, modulate, p_z, r_z_list, r_z_last_list, (Item *)ci->final_clip_owner, p_material_owner, true, p_canvas_cull_mask); } - _attach_canvas_item_for_draw(ci, p_canvas_clip, r_z_list, r_z_last_list, ci_xform, p_clip_rect, global_rect, modulate, p_z, p_material_owner, use_canvas_group, canvas_group_from); + _attach_canvas_item_for_draw(ci, p_canvas_clip, r_z_list, r_z_last_list, rounded_ci_xform, p_clip_rect, global_rect, modulate, p_z, p_material_owner, use_canvas_group, canvas_group_from); for (int i = 0; i < child_item_count; i++) { if (child_items[i]->behind || use_canvas_group) { continue;