Pixel scaling on camera zoom

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By snk

Hi,

I got this little pixel art project where I’m currently playing with zooms on the camera. The problem is that everytime I zoom in or out (downscaling or upscaling the zoom property on the camera) all the pixels on the screen start to drool, going from perfect squares to rectangles with various shapes.

Does somebody know if it is possible to perform dynamic zooms on the screen while keeping the pixels clean ?

Thanks.

:bust_in_silhouette: Reply From: snk

Okay, I found the reason why it’s doing that. When I put a value that results to an uneven pixel ratio, I’m dealing with float imprecisions on rendering… A 0.5 zoom work fine because I’m simply upscaling the pixel by two so everything is fine. But if I’m put something like 0.6, I got a 1.6666… scale which is not even, so the engine starts to stretch some pixels to fill the gaps.

All of this results to a very limited set of zooms… :(. Does someone know if it is possible to put uneven scales to the display and keep a perfect pixel ratio onscreen ?

:bust_in_silhouette: Reply From: johnygames

Hi there!

So, what version are you using, because I am using 3.1 and I have no issue with sprites (or at least I don’t see what the issue is if there is any). When you zoom in you should do so equally on both axes. So your zoom values should be 0.6 on the x and 0.6 on the y. You could also tweak the import settings of your sprite to see if that has any effect on the end result. Specifically, go to the import tab, disable filter and enable mipmaps. See if that helps.

There may also be a connection with the project’s resolution, so I suggest you look into that as well. Multiple resolutions — Godot Engine (latest) documentation in English

Also take a look at this post https://forum.godotengine.org/1084/resolution-strech-mode-2d-vs-viewport

Last but not least, you might have to check the ‘Use pixel snap’ option found under Project->Project Settings->General-> Rendering->Quality->Use pixel snap