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

Calculate pixel snap in canvas space instead of world space #97260

Merged
merged 1 commit into from
Sep 21, 2024

Conversation

clayjohn
Copy link
Member

@clayjohn clayjohn commented Sep 21, 2024

This ensures that you are actually snapping to pixels in the viewport and not an arbitrary amount

Fixes: #67164 and maybe others

During the 4.0 rewrite, we added the concept of a world matrix. In Godot 3, we didn't transform into world space ever. The modelview matrix transformed directly from model space into canvas space. In Godot 4 we do that transform in 2 stages and pixel snap was mistakenly done before the transformation to canvas space.

Accordingly, what this actually was doing was snapping to world space units instead of pixels. If your camera was aligned with world space such that a world space unit was the same as a canvas unit, it worked ok. But as soon as you zoom or rotate it would break.

Here is an MRP that really highlights the issue, it's adapted from #71074. Basically all it takes is a highly zoomed in camera. When running this in 4.3, the grid turns into a mess, and the player movement jumps several pixel at a time. With this PR it looks perfect.
PixelSnapMRP.zip

before
Screenshot 2024-09-20 at 6 03 25 PM

after
Screenshot 2024-09-20 at 6 04 13 PM

This ensures that you are actually snapping to pixels in the viewport and not an arbitrary amount
@clayjohn clayjohn added this to the 4.4 milestone Sep 21, 2024
@clayjohn clayjohn requested a review from a team as a code owner September 21, 2024 00:49
@clayjohn clayjohn added cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release labels Sep 21, 2024
@akien-mga akien-mga merged commit 5f5c690 into godotengine:master Sep 21, 2024
19 checks passed
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release topic:rendering topic:2d
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flickering sprite bleed on top row of moving sprite2ds and animatedsprites in Godot V4 (does not appear in V3)
3 participants