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

Question How to draw lines with efficiency and without pixelation or aliasing?

Discussion in 'General Graphics' started by maxkingdev, Dec 11, 2022.

  1. maxkingdev

    maxkingdev

    Joined:
    Mar 20, 2021
    Posts:
    12
    Hello Worldbuilders

    Has anyone discovered how to draw lines with efficiency and without pixelation?

    The pixelation problem occurs when using Unity's LineRender components - which has a nice simple interface. However I've yet to be able to get it to render nice, crisp thin lines. Instead it delivers pixelated lines and in some cases not lines at all. For example, this is a 2mm line screenshotted from Game Mode however the same problem occurs with larger widths and in Editor:

    When built to device (Quest) - the jagged lines render to the left eye but not the right eye.

    Thanks!
     
  2. vectorized-runner

    vectorized-runner

    Joined:
    Jan 22, 2018
    Posts:
    383
  3. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,574
    I would just use shaders, on large plane, to render many lines like that.
    You sdont want to use line renderer, for straight lines.
     
    bb8_1 likes this.
  4. Bas-Smit

    Bas-Smit

    Joined:
    Dec 23, 2012
    Posts:
    272
    Occuros, bb8_1 and apkdev like this.
  5. MicCode

    MicCode

    Joined:
    Nov 19, 2018
    Posts:
    58
  6. maxkingdev

    maxkingdev

    Joined:
    Mar 20, 2021
    Posts:
    12
    Thank you all for the suggestions.

    What would you use if you were drawing tick intervals (time measures across orders of magnitude - i.e. secs, mins, hrs,... years, centuries, millennia, etc.)?
     
  7. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,574
    Still shaders
    You could use two planes.
    One for thinner lines, one for thicker for example.
    Or more complex shader.
    I did something relevant in 2018

     
    maxkingdev likes this.
  8. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    I've done a grid like this before. It is indeed just a single shader that draws the whole thing. Basic trick is to use screen space derivatives (ddx and ddy) to make the lines crisp. In this case I've also used the derivatives to blend over powers of 10.

    grid.png

    This might be a good place to have a look at:
    https://madebyevan.com/shaders/grid/