Skip to content

Commit

Permalink
Reinstate rounding for sprites + keep ci rounding for draw only
Browse files Browse the repository at this point in the history
  • Loading branch information
adamscott committed Jan 24, 2024
1 parent b1ab8c1 commit acad6d6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
4 changes: 4 additions & 0 deletions scene/2d/animated_sprite_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions scene/2d/sprite_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
14 changes: 8 additions & 6 deletions servers/rendering/renderer_canvas_cull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit acad6d6

Please sign in to comment.