Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change 2d transform snapping from floor to round #43813

Merged
merged 1 commit into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scene/2d/animated_sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,8 @@ void AnimatedSprite::_notification(int p_what) {
ofs -= s / 2;

if (Engine::get_singleton()->get_snap_2d_transforms()) {
ofs = ofs.round();
} else if (Engine::get_singleton()->get_use_pixel_snap()) {
ofs = ofs.floor();
Comment on lines 455 to 458
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the current documentation clear enough about how 2d transform and pixel snapping will behave differently, including this new difference? (And the fact that 2d transform has precedence.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest I'm not convinced that we even need the floor with the pixel snap (which is actually done in the vertex shader). But I didn't want to remove it in this PR, just in case there is an actual need for it, we can evaluate removing it in a separate PR.

Perhaps I should take the opportunity to rename pixel_snap, at least internally because it seems to be causing confusion. The name is historical, but really vertex_shader_snap or something might be better. Or the name reduz used in his PR I will check that.

In either case I don't think mentioning it in the docs is wise at this stage until it is finalized. snap_2d_transforms does not totally take precedence, only here on CPU. On the GPU, pixel_snap still acts alongside the CPU snapping.

}
Rect2 dst_rect(ofs, s);
Expand Down
9 changes: 7 additions & 2 deletions scene/2d/sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ void Sprite::_get_rects(Rect2 &r_src_rect, Rect2 &r_dst_rect, bool &r_filter_cli
Point2 dest_offset = offset;
if (centered)
dest_offset -= frame_size / 2;
if (Engine::get_singleton()->get_use_pixel_snap()) {

if (Engine::get_singleton()->get_snap_2d_transforms()) {
dest_offset = dest_offset.round();
} else if (Engine::get_singleton()->get_use_pixel_snap()) {
dest_offset = dest_offset.floor();
}

Expand Down Expand Up @@ -378,7 +381,9 @@ Rect2 Sprite::get_rect() const {
Point2 ofs = offset;
if (centered)
ofs -= Size2(s) / 2;
if (Engine::get_singleton()->get_use_pixel_snap()) {
if (Engine::get_singleton()->get_snap_2d_transforms()) {
ofs = ofs.round();
} else if (Engine::get_singleton()->get_use_pixel_snap()) {
ofs = ofs.floor();
}

Expand Down
2 changes: 1 addition & 1 deletion servers/visual/visual_server_canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void VisualServerCanvas::_render_canvas_item(Item *p_canvas_item, const Transfor
Rect2 rect = ci->get_rect();
Transform2D xform = ci->xform;
if (snap_2d_transforms) {
xform.elements[2] = xform.elements[2].floor();
xform.elements[2] = xform.elements[2].round();
}
xform = p_transform * xform;

Expand Down
4 changes: 2 additions & 2 deletions servers/visual/visual_server_viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ static Transform2D _canvas_get_transform(VisualServerViewport::Viewport *p_viewp

Transform2D c_xform = p_viewport->canvas_map[p_canvas->parent].transform;
if (snap) {
c_xform.elements[2] = c_xform.elements[2].floor();
c_xform.elements[2] = c_xform.elements[2].round();
}
xf = xf * c_xform;
scale = p_canvas->parent_scale;
}

Transform2D c_xform = p_canvas_data->transform;
if (snap) {
c_xform.elements[2] = c_xform.elements[2].floor();
c_xform.elements[2] = c_xform.elements[2].round();
}
xf = xf * c_xform;

Expand Down