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

Refactor pixel snapping. #43194

Merged
merged 1 commit into from
Oct 30, 2020
Merged

Conversation

reduz
Copy link
Member

@reduz reduz commented Oct 29, 2020

-Rename pixel_snap to snap_2d_to_vertices
-Added snap_2d_to_transforms which is more useful

Fixes #41814
Solves proposal godotengine/godot-proposals#1666
Supersedes #35606, supersedes #41535, supersedes #41534

@reduz
Copy link
Member Author

reduz commented Oct 30, 2020

@RamaStudio I am not exactly sure what I should be looking at. 4.0 prior to this PR did not have pixel snap implemented, so even if you turn on the setting it was the same as just disabling it (made no difference).

If you are using filtered textures, you should probably not enable snapping. Snapping will be mostly useful for pixel art. This PR aims to solve the problems with motion (see the referenced issues/PRS0, not with scaling.

Pixel (no filter) scaling will always be wobbly, not sure if anything can be done about that.

@reduz
Copy link
Member Author

reduz commented Oct 30, 2020

Also you should most definitely not be using vertex to pixel snap for pixel art. Use the new transforms to pixel snap instead.

@reduz
Copy link
Member Author

reduz commented Oct 30, 2020

Ok just so we are on the same page, there are two options here:
image

The first one is meant to solve #41535. With it, the demos run ok, no jitter between objects reaching the next pixel at different times. When you turn it on, all reach the next pixel at the same time. This is definitely meant for pixel art, if your texture has filtering enabled you may not want to use this.

The second is the same as the old "pixel snap" in Godot 3.x and should work the same. It wasn't being enabled but it should use the same code as 3.2 so I assume it works. If it does not, it's most likely a bug and it needs to be fixed.

@RPicster
Copy link
Contributor

I would love to test this. It's a huge problem in my game.
Unfortunately I still did not understand how to make custom builds including certain PRs.
If someone has a Win build on 3.2 "lying around" with this change, I would love to test it and give feedback how it behaves with my project.

@@ -3419,6 +3440,8 @@ void Viewport::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "world_2d", PROPERTY_HINT_RESOURCE_TYPE, "World2D", 0), "set_world_2d", "get_world_2d");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "transparent_bg"), "set_transparent_background", "has_transparent_background");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "handle_input_locally"), "set_handle_input_locally", "is_handling_input_locally");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "snap_2d_transforms_to_pixel"), "set_snap_2d_transforms_to_pixel", "is_snap_2d_transforms_to_pixel_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "snap_2d_vertices_to_pixel"), "set_snap_2d_vertices_to_pixel", "is_snap_2d_vertices_to_pixel_enabled");
Copy link
Member

Choose a reason for hiding this comment

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

Seems like you forgot the method bindings for those?

@@ -3577,6 +3600,8 @@ Viewport::Viewport() {
debug_draw = DEBUG_DRAW_DISABLED;

snap_controls_to_pixels = true;
snap_2d_transforms_to_pixel = false;
Copy link
Member

Choose a reason for hiding this comment

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

You forgot to initialize the other one.

@Xrayez
Copy link
Contributor

Xrayez commented Oct 30, 2020

@RPicster builds artifacts are available for this PR to test:

Windows: https://github.com/godotengine/godot/actions/runs/336674241

Go into "Show all checks" → "Details" for each platform of interest → "Artifacts".

-Rename pixel_snap to snap_2d_to_vertices
-Added snap_2d_to_transforms which is more useful

Fixes godotengine#41814
Solves proposal godotengine/godot-proposals#1666
Supersedes godotengine#35606, supersedes godotengine#41535, supersedes godotengine#41534
@reduz reduz force-pushed the pixel-snap-refactor branch from df4f610 to 0e66645 Compare October 30, 2020 11:58
@Calinou
Copy link
Member

Calinou commented Oct 30, 2020

@RPicster This pull request is based on the master branch (with the Vulkan renderer), not the 3.2 branch. It's not compatible with 3.2.x projects.

@reduz reduz merged commit 704d06d into godotengine:master Oct 30, 2020
@Zireael07
Copy link
Contributor

Can the "viewport size = window size" requirement for pixel perfect get documented?

Transform2D xform = p_transform * ci->xform;
Transform2D xform = ci->xform;
if (snapping_2d_transforms_to_pixel) {
xform.elements[2].floor();
Copy link
Member

Choose a reason for hiding this comment

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

I've just been backporting this to 3.2, and noticed, there is an error here which stops the whole method from working.

This line needs to be xform.elements[2] = xform.elements[2].floor();, as it stands, this line is a no-op. I've made this mistake more than once with godot funcs myself! 😁

@lawnjelly
Copy link
Member

@reduz I've pointed out small typo which may be needed for this to work in master branch. I can't currently run 4.0 so anyone on 4.0 (@akien-mga ?) can make a small PR to fix this.

lawnjelly added a commit to lawnjelly/godot that referenced this pull request Nov 15, 2020
This is a cut back backport of reduz snapping PR godotengine#43194.

It just offers a global project setting for transform snapping.
@aaronfranke
Copy link
Member

aaronfranke commented Nov 16, 2020

@reduz Should those issues/PRs you linked be closed?

@lawnjelly
Copy link
Member

@reduz Should those issues/PRs you linked be closed?

For the issues at least an equivalent PR still has to be finalized / merged for 3.2 first I think (this one can't be cherry picked super easily because there are some differences).

HEAVYPOLY pushed a commit to HEAVYPOLY/godot that referenced this pull request Dec 14, 2020
This is a cut back backport of reduz snapping PR godotengine#43194.

It just offers a global project setting for transform snapping.
@lawnjelly lawnjelly mentioned this pull request Mar 20, 2021
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.

Godot Screen Pixel Jitter.
8 participants