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

Sprite "crunch" when placed in certain positions on screen #84632

Closed
Araraura opened this issue Nov 8, 2023 · 9 comments · Fixed by #87297
Closed

Sprite "crunch" when placed in certain positions on screen #84632

Araraura opened this issue Nov 8, 2023 · 9 comments · Fixed by #87297

Comments

@Araraura
Copy link
Contributor

Araraura commented Nov 8, 2023

Godot version

v4.2.beta5.official [4c96e96]

System information

Godot v4.2.beta5 - Windows 10.0.22621 - Vulkan (Forward+) - dedicated AMD Radeon RX 7900 XTX (Advanced Micro Devices, Inc.; 31.0.22023.1014) - AMD Ryzen 9 7950X3D 16-Core Processor (32 Threads)

Issue description

In 4.2, there is an issue mostly visible on pixel art games with small resolutions that scale up to larger screens. While the game is running, moving sprites to certain places in the screen will cause the sprites to appear uneven or "crunched", and it's usually more noticeable if the sprite is animated.

example

Window settings:
image

This seems to happen when moving the position of the sprite to X.5.
This happens in all 3 renderers.
This issue does not occur in Godot 4.1.3.
This issue occurs as early as 4.2 dev1.

Note: I'm using a 4K monitor with Windows scaled up to 175%.

Steps to reproduce

  1. Download the reproduction project
  2. Open the project
  3. Run the game
  4. If the issue doesn't immediately show itself, slightly moving the character to the left/right a few times should trigger it.

Minimal reproduction project

SpriteCrunchIssue.zip

@AThousandShips
Copy link
Member

AThousandShips commented Nov 8, 2023

This seems to happen when moving the position of the sprite to X.5

This is due to sampling issues and non-pixel positions, does this go away if you enable rendering/2d/snap/snap_2d_transforms_to_pixel?

I'd say this is largely hard to avoid due to rendering and sampling

@Araraura
Copy link
Contributor Author

Araraura commented Nov 8, 2023

This seems to happen when moving the position of the sprite to X.5

This is due to sampling issues and non-pixel positions, does this go away if you enable rendering/2d/snap/snap_2d_transforms_to_pixel?

I'd say this is largely hard to avoid due to rendering and sampling

This specific issue disappears with this setting, but it also introduces a lot of different ones.
In this project specifically the character sprite will hover above the ground, movement looks choppy, etc.

@Calinou
Copy link
Member

Calinou commented Nov 10, 2023

Can you try following the same steps on previous 4.2 dev/beta builds? You can download them here.

Also check if this occurs with 4.1.3 (not just 4.1).

@Araraura
Copy link
Contributor Author

Araraura commented Nov 10, 2023

Can you try following the same steps on previous 4.2 dev/beta builds? You can download them here.

Also check if this occurs with 4.1.3 (not just 4.1).

I should've mentioned I tested it on 4.1.3 and not 4.1, my bad

And this happens as early as 4.2 dev1

@joined72
Copy link
Contributor

joined72 commented Nov 15, 2023

I managed to fix your issue simply changing Project Settings/Display/Window/Stretch/Mode from "viewport" to "canvas_item", take a try. 😉
PS: I fixed using Godot 4.2b6

@Araraura
Copy link
Contributor Author

I managed to fix your issue simply changing Project Settings/Display/Window/Stretch/Mode from "viewport" to "canvas_item", take a try. 😉 PS: I fixed using Godot 4.2b6

This doesn't seem to be a complete fix. At certain locations, the pixels of the sprite wobble:
gif

@Gnumaru
Copy link
Contributor

Gnumaru commented Nov 26, 2023

@Araraura Try this: Ensure that your spritesheet texture has even dimensions (like 48x16 instead of 49x17) and that each frame of animation also has even dimensions (like each frame having 16x16 instead of 16.333.x17). As a last resort, you could set the centered property to false and see if it makes any difference.

I've been ensuring that every number is even (including collision shape dimensions) for so long that I usually forget about the consequences.

@adamscott
Copy link
Member

I could reproduce the "issue" on Godot 3.x, when the camera is at 1x and when I deactivate rendering/2d/snapping/use_gpu_pixel_snap.

Capture.video.du.2023-12-20.13-58-23.webm

SpriteCrunchIssueGodot3.zip

@AThousandShips is pretty spot on with the issue at hand:

This seems to happen when moving the position of the sprite to X.5

This is due to sampling issues and non-pixel positions, does this go away if you enable rendering/2d/snap/snap_2d_transforms_to_pixel?

I'd say this is largely hard to avoid due to rendering and sampling

The only difference here between Godot 3.x and Godot 4.x, it seems, is the order of operations. It appears like that Godot 3 scales from (0,0), then applies the correctly scaled sprite into the canvas, offsetting it by half a pixel.

Godot 4 instead positions the sprite first at half a pixel, then scales the result. Hence the weird sprite state.

@clayjohn, does something ring you a bell?

@akien-mga
Copy link
Member

Fixed by #87297.

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