godot icon indicating copy to clipboard operation
godot copied to clipboard

Tilemap rendering incorrectly when positioned exactly on .5

Open blDraX opened this issue 2 years ago • 11 comments

Godot version

v4.0.2.stable.official [7a0977ce2]

System information

Windows 11

Issue description

When using typical settings for obtaining pixel-perfect rendering (texture filter nearest, stretch mode viewport), tilemaps do not render correctly when they (or the camera) are exactly positioned on a half-pixel (e.g. 0.5). Looks like the left-most column is duplicated and the right-most column is cut off. Only tested for a horizontal .5 coordinate.

https://user-images.githubusercontent.com/51884888/234953179-581a33e9-73e3-4cc0-a6e6-10aa57c88686.mp4

Steps to reproduce

Set up new project with a tilemap. Build a simple tilemap. Set texture filter to nearest and stretch mode viewport. Make resolution very small to make issue more apparent.

Minimal reproduction project

tilemap_rendering.zip

blDraX avatar Apr 27 '23 18:04 blDraX

I checked the code, but could not find anything wrong on the TileMap side. I think there's likely an issue with the rendering code but I have no clue what would cause that.

As a workaround, it seems like disabling Use texture padding helps with it.

groud avatar Jun 21 '23 11:06 groud

Is it related to #82696?

Cerno-b avatar Jan 06 '24 17:01 Cerno-b

I cannot reproduce, either on 4.0.4 or 4.3.dev, with the supplied MRP.

Can you confirm that the issue is still relevant, @blDraX?

adamscott avatar Jan 17 '24 15:01 adamscott

@adamscott: Yes, I can still reproduce this with the minimal example I've attached on v4.2.1.stable.official [b09f793f5].

In fact, while also testing this on my pixel art project, I found that the camera being close to .5 does not only do weird things to the tilemap but to my animated sprites as well. Check out this clip: https://www.youtube.com/watch?v=J7paPFCq0H8

The diamonds moving up and down is not a change in position but implemented as animated sprite with three frames. Attaching the texture I'm using as well. When the camera is on .5, the pixels are doing.. super weird stuff? Attaching the png as well.

diamond

(in the video you can also see the problem on the tilemap again. Check out the side of the cliffs for example. Outmost pixel column is duplicated and on the other side, one column is cut off; also attaching a marked screenshot) tilemap_issue

blDraX avatar Jan 17 '24 20:01 blDraX

@blDraX What should I see then in the MRP you joined?

adamscott avatar Jan 17 '24 20:01 adamscott

@adamscott: Sorry, I probably didn't choose a good texture in the MRP that easily shows the issue. But you should see essentially what I've also shown in the first video back in April last year. Change the camera position between 0 and 0.5 for example. You will see the tile texture wandering by one pixel column.

Here a recording using the MRP: https://www.youtube.com/watch?v=aDwzO_K3U9I

blDraX avatar Jan 17 '24 21:01 blDraX

@adamscott @Cerno-b @groud I would like to bring attention to this issue again as it is still unsolved for me.

@groud previously mentioned that disabling texture padding can be used as a workaround. It's true that this prevents this specific rendering issue from happening but instead, a new issue arises: It seems like in the situations where the bug previously occured, the respective rows/columns are now instead not drawn at all: image

It's hard for me to understand what is going on here and why only certain tiles are affected. I also have the issue attached on video which should make it a bit more clear what is going on.

I also want to add that this issue is apparently not limited to tilesets but also applies to ohter kinds of tiles images like for AnimatedSprite2D. In the second part of the video, you see the player sprite getting weirdly distorted as the camera moves diagonally, following the movement of the player up the slope: image

For example, the lines appearing above the player sprite sometimes is actually the bottom row of one of the frames of the animation (the feet of the player sprite): image

For reference, this is a part of the respective sprite sheet I'm using (tiled 32x32): image

Here is the video: https://github.com/godotengine/godot/assets/51884888/c27fd49b-4c4a-4189-951d-88ed0437fdbb

blDraX avatar Mar 15 '24 10:03 blDraX

I can confirm that this issue is still present on the latest stable release (4.3-stable)

RandomGamingDev avatar Sep 05 '24 02:09 RandomGamingDev

I've published a PR (#97891) which fixes this issue whose scope seems to include things like Sprite2D outside of the original Tileset issue, meaning that it encompasses other issues outside of this one, although I wasn't able to check them all.

Would you be able to check which specific issues regarding pixel rendering were fixed for your project @blDraX?

RandomGamingDev avatar Oct 06 '24 16:10 RandomGamingDev

cc. @markdibarry

adamscott avatar Oct 07 '24 16:10 adamscott

Hm. I get a segfault when trying to load the MRP, both in PR branch and in master. I'll tinker a bit.

markdibarry avatar Oct 08 '24 00:10 markdibarry