Tile outline not rendering properly and flickering

Hey everyone ! I currently have a rendering problem on my outlines when I select a block (put my mouse on it in game mode). My script is set to put the outline tile where my mouse is.

As you can see, when I am zoomed with Orthographic Camera, the outline works well, but as soon as I unzoom, the outline kinda desapears in weird ways (sometimes it’s the sides, other times the top of the sprite… pretty random).

I tried using Pixel Perfect camera, changed nothing. I tried removing anti-aliasing OR adding anti-aliasing, changed nothing. I made a Sprite Atlas with every sprite, worked to remove flickering for the main tilemap but not for the outline. I also made sure my outline is on different rendering level (z = -1 changed nothing, Tilemap renderer set to another sorting layer changed nothing.) I also tried changing the material from Sprite-lit-Default to Sprite-Unlit-Default changed nothing.

I searched on different forums and nobody seemed to have the same problem so idk what to do more, could you help me ? Thanks a lot !

This is probably an aliasing effect. Or the textures not using point filter. Or subpixel placement of the tiles. Or any of this in combination.

You also want to avoid zooming out to an “odd” scale. Ie don’t zoom by a factor of 1.43 or something but rather only to 1.5 or 2.0.

Consider what happens to each individual pixel when you had a 5x5 pixel image and you scale it down to 4x4 or 3x3 pixels … which of those 5 pixels is going to go away? This may seem random and it may very well be but ultimately, you can’t scale things smaller without a loss of data (here: displayed pixels, ie it’s only a temporarily destructive operation but destructive nevertheless).

Image scaling algorithms combat this by applying filters while scaling. AA won’t fix that because it only takes the resulting scaled image and smoothes out what’s being displayed ie AA runs “after the fact” of the destructive operation.

Try again. This looks like the sort of project where you have to use pixel-perfect. You need to find the settings that work for you though, it’s not a magic silver bullet that you add and it fixes everything but it’ll definitely be desirable for such a pixel art tile-based game.

One solution could be, rather than zooming in, to change the reference resolution at runtime making the zoomed in version of the game render at higher resolution.

1 Like

Well, thank you very much ! Apparently my previous tests with pixel perfect cam weren’t good and adding it was the solution !

Have a great day.

1 Like