Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Sprite lines flickering / moving weirdly

Discussion in 'General Graphics' started by khold93, Mar 13, 2023.

  1. khold93

    khold93

    Joined:
    Feb 11, 2020
    Posts:
    17
    Hello,

    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
    • Tried to use Texturepacker without luck
    Just an example of one of the sprites.


    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?
    - Adding Mip maps helped a lot, but not 100%
     
    Last edited: Mar 13, 2023
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    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:
    https://forum.unity.com/threads/how...-and-crisp-even-while-rotating-solved.651841/
    Feel free to use my example shader code there.
     
    khold93 likes this.
  3. khold93

    khold93

    Joined:
    Feb 11, 2020
    Posts:
    17
    Appreciate the reply, and thanks for the great information :)
    I understand more of why it happens and what I can do now.