-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Apply "snap 2D transforms to pixel" to viewport #93786
Apply "snap 2D transforms to pixel" to viewport #93786
Conversation
Tested and can confirm that there's no jitter with odd-sized viewports. This does re-introduce the jitter for void Parallax2D::_camera_moved(const Transform2D &p_transform, const Point2 &p_screen_offset, const Point2 &p_adj_screen_pos) {
if (!ignore_camera_scroll) {
if (get_viewport() && get_viewport()->is_snap_2d_transforms_to_pixel_enabled()) {
Size2 vps = get_viewport_rect().size;
Vector2 offset;
offset.x = ((int)vps.width % 2) ? 0.0 : 0.5;
offset.y = ((int)vps.height % 2) ? 0.0 : 0.5;
set_screen_offset((p_adj_screen_pos + offset).floor());
} else {
set_screen_offset(p_adj_screen_pos);
}
}
} |
@alvinhochun Can you apply the change from Marks comment? After that, this should be good to merge. |
We shall not leave the viewport transform to be rounded by the code for rounding canvas items. Since the viewport transform is inverse to the camera transform, we get incorrect rounding at the halfway point that misaligns the viewport and the canvas item which the camera is following. Instead, reintroduce viewport rounding, but do it in a way that matches the rounding of canvas items. Also take into account the half-pixel offset of the centre point when viewport dimension is not divisible by two. For `CanvasLayer`s that follows viewport, take into account the scale when rounding. Overall this should work better compared to the rounding in Godot 4.2 (and earlier).
2729fc4
to
3f9bb59
Compare
@markdibarry Can you confirm that this no longer introduces a regression in your testing project? |
Sorry for the late reply. I didn't notice any regressions with the test project. No jitter for odd sized viewports, parallax or no. |
Thanks! |
We shall not leave the viewport transform to be rounded by the code for rounding canvas items. Since the viewport transform is inverse to the camera transform, we get incorrect rounding at the halfway point that misaligns the viewport and the canvas item which the camera is following.
Instead, reintroduce viewport rounding, but do it in a way that matches the rounding of canvas items. Also take into account the half-pixel offset of the centre point when viewport dimension is not divisible by two. For
CanvasLayer
s that follows viewport, take into account the scale when rounding. Overall this should work better compared to the rounding in Godot 4.2 (and earlier).Fixes #93712
This reimplements the viewport rounding removed from #87297.
I've tested this with the MRP there, with odd and even viewport sizes, and with a bunch of other scenarios with CanvasLayer following viewport and scaled.