I’ve added some PNG files to my project, and the lines in these files are flickering and moving weirdly when the object is moved slightly.
Unity 2021.3.20f1 Personal DX11
Universal Render Pipeline (URP).
It happens in Play Mode, Build and when I simply preview an animation with slightly Position adjustments outside of play mode.
My camera is set to an orthographic size of 8, but I have tried other sizes.
I’m using Cinemachine to control the camera.
I’ve tried adjusting the pixel per unit, compression, and filter mode settings, but these changes did not solve the issue.
Tested on two PCs in build mode as well.
I’ve also tried the following:
Adjusting the size of the PNG files to match the camera size
Changing the rendering mode of the lines
Disabling/Enabling MSAA/AA, HDR & PostProcessing
Using a different shader
I tried using a sprite with higher resolution type of 486x670 and it looks better, but it obviously looks bad when scaled down and you can still see the black lines moving a bit weird.
Test big sprites and higher orthographic size.
Checked the image itself and it looks good. The lines in Unity (sprite preview) looks low quality compared to the original. I don’t know if Unity just shows a bad preview or not
Unfortunately, none of these changes have solved the issue. If anyone has experienced similar issues or has any other suggestions for troubleshooting, I would greatly appreciate your input.
Thank you!
Edit:
Turning Render Scale to 2 fixes it, but I assume this isn’t a great solution due to performance?
You’re experiencing a basic case of texture aliasing.
Mipmaps exist to reduce or entirely remove texture aliasing, but at the cost of reducing the clarity of the image. There may also be some minor aliasing in the texture itself from downscaling the image.
MSAA won’t help here, because MSAA only affects geometry edges, not the interior of geometry. For sprites that’s basically useless unless you’re using very high detail mesh sprite shapes. And even then that still only helps the outside edge of the sprite. TAA can help, but not Unity’s implementation of it as it doesn’t work well on transparent surfaces, or sprites in general really. FXAA / SMAA or other post process AA techniques can kind of help blur some jagged edges away, but if details are too small that they’re flickering in and out, they can’t help that at all.
Super sampling, which is what you’re doing when you set the render scale to 2, obvious does help, but yes, that can be expensive to use.
Other things you can do to help:
Disable compression on the sprite, and if you’re using one, the Sprite Atlas itself.
If you’re not using a sprite atlas, make sure the sprite isn’t being scaled when imported into Unity. It shouldn’t, but by default for most textures it scales them to the closest power of two size. Sprites should default to that being off, but make sure.
Use texture biasing, or more usefully, use a shader that does the super sampling in the shader itself.
For that last suggestion you can find an example shader I posted here: