Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Drawing smooth lines with LineRenderer

Discussion in 'General Graphics' started by Emolk, Sep 19, 2020.

  1. Emolk

    Emolk

    Joined:
    Feb 11, 2014
    Posts:
    241
    Hi, how are you supposed to draw smooth non-pixelated lines with the line renderer?

    I have tried everything, anti-aliasing, changing every setting etc. Every thread I found about it has no solution.

    I can't seem to draw lines that aren't jagged/pixelated. The lines look fine in the scene view but in the build or game view they look terrible.

    Reference images below

    Build/game view







    Scene view

     
  2. Emolk

    Emolk

    Joined:
    Feb 11, 2014
    Posts:
    241
    Bump
     
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,529
    This is the 2D forum which relates to 2D features so it's probably why you've not got a response to a 3D renderer issue yet. Try asking on the general graphics forums.
     
    Emolk likes this.
  4. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535
    I feel like the line renderer has this problem, it doesn't render smooth enough lines for a sharp graphics game but also cannot render them pixelated enough to be used in a pixel art game
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,238
    I'm confused by what part of the above images is the line renderer, and how do you have the line renderer & its material setup?

    If the line renderer is using an alpha tested material, then no, it won't appear smooth. But the fact it does appear smooth in the scene view confuses me.
     
  6. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,240
    Those slightly rounded corners don't look like something the Line Renderer can do.
     
  7. Emolk

    Emolk

    Joined:
    Feb 11, 2014
    Posts:
    241
    I'm procedurally generating a path for an endless runner that goes vertical. I choose two points then draw two shapes (for each side of the path) passing in verticies. I then draw four lines around the edge of each shape with the linerenderer for artistic purposes as it looks a lot better. Was hoping the lines would by smooth though. I'm using the default-line material, most materials I use cause the lines to be jagged.




    The line renderer has the 'Corner Verticies' and 'End Cap Verticies' which I increased to get the rounded corners. Its even more jagged without them.
     
  8. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,238
    I don’t think I ever noticed there was a Default-Line material. And I still don’t have an explanation for why it’s jagged. I would expect a default line material to be using the particle unlit shader set to render mode Fade though. That shouldn’t have any issues, potentially even w/o any anti aliasing enabled depending on what texture it’s using.

    With the line removed, is the geometry you do see smooth? My only guess is that for some reason the scene view is getting some kind of post process AA (like FXAA) applied even though the game camera does not. You might have multiple cameras enabled in your scene but the one rendering the line renderer doesn’t have it.

    Fix that, and it should be fine. Or enable MSAA for the project and make sure it’s not disabled on the camera.

    Alternatively, don’t use a line renderer for this. I might say you look at using Shapes from the asset store, which can do perfect anti-aliasing without any post processing or MSAA (assuming you’re okay with using alpha blending).
    https://assetstore.unity.com/packages/tools/particles-effects/shapes-173167
     
    npatch and richardkettlewell like this.
  9. contact_unity364

    contact_unity364

    Joined:
    Sep 28, 2020
    Posts:
    5
    I have found this to be an issue with thin almost-horizontal or almost-vertical lines. Sometimes the line does not show and other times it has stepping. The issue will be that the drawing of the line simply has either fill in pixels or not, much like cutout transparency, and it does not have any way to alias the edges as it draws the line. So any antialising has to be handled as post processing but there is only so much you can do with jagged lines and you would have to try the various antialiasing options to see what works best. I suggest living with it. The higher the screen resolution the less likely it's an issue.