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

Stabilize snapping 2D transforms to pixel #87297

Merged
merged 1 commit into from
Feb 12, 2024

Conversation

adamscott
Copy link
Member

@adamscott adamscott commented Jan 17, 2024

tl;dr

This PR simplifies greatly the snapping of 2D transforms to pixel. Instead of relying on flooring sprites, CanvasItems (so twice flooring for sprites) and the camera transform, this PR only rounds each CanvasItem position.

Co-authorship

This PR is heavily inspired by #84380 by @KeyboardDanni, so I added them to the commit as co-author.

Why?

There's some issues with pixel perfect both due to:

  • the numerous places where flooring occurs;
  • the flooring itself;

Superseding

Tests

#84380 test

master

master.webm

This PR

87297.webm

Merlin: Scale of the Magic

(author note: the project was edited to add debug info)

master

master.webm

This PR

87297.webm

Production edit: closes godotengine/godot-roadmap#79

Bugsquad edit:

@adamscott

This comment was marked as outdated.

@adamscott adamscott force-pushed the 2d-pixel-art-stability branch from a955862 to 8968e4d Compare January 17, 2024 16:58
@YuriSizov

This comment was marked as resolved.

@adamscott adamscott force-pushed the 2d-pixel-art-stability branch 2 times, most recently from 3532649 to 5055d51 Compare January 18, 2024 02:40
@adamscott adamscott force-pushed the 2d-pixel-art-stability branch 2 times, most recently from aad6666 to acad6d6 Compare January 24, 2024 16:09
@adamscott adamscott force-pushed the 2d-pixel-art-stability branch 3 times, most recently from a607f8f to 76913a7 Compare February 1, 2024 15:04
@markdibarry
Copy link
Contributor

Just tested with both pixel perfect test projects, and both look as expected.

@adamscott adamscott force-pushed the 2d-pixel-art-stability branch 2 times, most recently from 70437ba to 25fc819 Compare February 7, 2024 15:15
Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

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

Great research everyone!

Let's give this a spin and see how pixel art users like it in the next dev snapshot (4.3-dev4).

@akien-mga akien-mga merged commit 9050ee1 into godotengine:master Feb 12, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

@alvinhochun
Copy link
Contributor

A bit late to the party, but I have the feeling that instead of rounding, it should have been floor(x + 0.5) instead. This is because rounding to nearest has different behaviour for positive and negative values when the fractional part is 0.5.

Consider this: We position a sprite at x=0.5, which is snapped to x=1 on screen. We move it to the left by 1px. Where should the sprite be at on screen?

The expectation should be x=0. However, since the subpixel position is now x=-0.5, the sprite is actually snapped to x=-1 on screen thanks to rounding. Which means the supposedly 1px move becomes a 2px move on screen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sprite "crunch" when placed in certain positions on screen Vulkan: 2D Pixel Snap not working
5 participants