Search Unity

Fast Line Renderer

Discussion in 'Assets and Asset Store' started by jjxtra, Apr 25, 2016.

  1. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,464
    Sending an update @mwb87, re-download in about an hour.
     
  2. mwb87

    mwb87

    Joined:
    Mar 19, 2019
    Posts:
    13
    It works fine now, thanks for the quick action :)
     
  3. mwb87

    mwb87

    Joined:
    Mar 19, 2019
    Posts:
    13
    Hi @jjxtra,

    I have a small additional question. Is it possible to uniform scale a texture? I now use "Line UVX scale" but when a selection gets larger it (logically) stretches.

    selection.png

    I would like to keep the texture (a dot) the same size, and repeat over the length of a line. Vectrocity has a "textureScale" option, but I can't find anything like that in the documentation. Is this something FastLineRenderer can do?

    Thanks
     
  4. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,464
    Nothing like this exists currently, but you could break your selection into additional line segments to compensate, for example the longer sections could be two separate lines that are half the length. Does that make sense?
     
  5. mwb87

    mwb87

    Joined:
    Mar 19, 2019
    Posts:
    13
    That's too bad.

    I get what you are saying, but I think that makes the code too complex to archive this.
    Thanks for your answer.
     
  6. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,464
    You already have 8 line segments. This would take it to 12.
     
  7. mwb87

    mwb87

    Joined:
    Mar 19, 2019
    Posts:
    13
    My selection is based on a grid, so each side need to be the length of a grid cell. An I have different grid sizes, so its needs to be flexible.

    selection.png

    But i turns out i wasn't too bad to achieve :)
    Thanks for the suggestion though.
     
  8. Bambivalent

    Bambivalent

    Joined:
    Jan 25, 2017
    Posts:
    16
    Hi, I'd like to make a continuously drawn graph, like a seismograph. I only need around 15 points, but the whole graph = all points needs to be moving all the time.
    Is it correct that I have to reset the lineRenderer on every frame via Update() and then redraw the whole graph? Or can I "recycle" the existing graph and manipulate the existing points to save gpu time?
    upload_2020-5-8_23-21-30.png
     
  9. lmaxsmith

    lmaxsmith

    Joined:
    Nov 21, 2016
    Posts:
    3
    Hey, I'm using Fast Line Renderer to draw wireframes of thousands of objects in a scene, all read from a file and drawn at runtime. It's working great but I'm really trying to optimize to allow for a disgusting amount of content. I currently have a fastlinerenderer script on every object instance. Less than 100 line segments per object. I'm wondering if it might be better performance to have fewer fast line renderers that hold multiple objects? Or if it's just as good to keep tons of fast line renderers. (Targeting mobile ARM devices)
    Asking for insight here before making major changes to the code because it will be a significant move. Thanks.
     
  10. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,464
    If you have a lot of changing line renderers, then having one per object is better. If you have mostly static lines, then just use one line renderer.
     
  11. Whitepot

    Whitepot

    Joined:
    May 19, 2017
    Posts:
    16
    Hi there, I'm having a problem when drawing a (curved) animated line in the UI. In the first frame after calling Apply() (after I have set everything up with AppendCurve(...)). The line is stretched out, then in the subsequent frames it returns to normal.


    In this image you can see the stretched line in the background in white. Then in the next frames it looks as it should (see image below)


    I set up the curve as follows:
    Code (CSharp):
    1. _lineRenderer.Reset();
    2. FastLineRendererProperties props = new FastLineRendererProperties();
    3. lineRenderer.ScreenRadiusMultiplier = _screenRadiusMultiplier;
    4. props.GlowIntensityMultiplier = 0;
    5. props.GlowWidthMultiplier = 0;
    6. props.Radius = _radius;
    7. props.Color = Color.white;
    8. props.Start = point1.position;
    9. props.End = point2.position;
    10. _lineRenderer.AppendCurve(props, curvepoint1.position, curvepoint2.position, _noOfSegments, _startCap, _endCap, _animationTime);
    11. _lineRenderer.Apply();
    Is there anything I should be doing or avoiding to stop this from Happening?

    Thanks in Advance.
     

    Attached Files:

  12. lmaxsmith

    lmaxsmith

    Joined:
    Nov 21, 2016
    Posts:
    3
    Is there any chance this will be updated soon to support Single Pass Instanced rendering?
     
  13. oddreams

    oddreams

    Joined:
    Dec 3, 2016
    Posts:
    17
    Hey,
    Are 3D lines supported? I added the prefab into the scene, and added 2 lines, but when looking from different angles, they stay static (therefore completely disappear sometimes).

    Thanks,
    Edmond
     
  14. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,464
    Sort of. They will billboard a bit funny at sharper angles.
     
  15. oddreams

    oddreams

    Joined:
    Dec 3, 2016
    Posts:
    17
    is there any workaround for this, or its not possible to do that atm?
     
  16. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,464
    Not possible currently
     
  17. albanmdb

    albanmdb

    Joined:
    Jul 10, 2020
    Posts:
    3
    Hello.
    I bought your asset to draw some shapes the user will be able to interact with.
    It is much faster that Unity's line renderers indeed but there are some weird visual effects with the shader (see the attached gif). If I rotate the drawn lines they are progressively thinning then tchicking back. Same goes when I look at the line from different angles.
    How can I modify the shader to keep the visuals constant regardless of the camera position and the rotation of the gameObject ?
    Thanks

    ezgif.com-gif-maker (15).gif circle.PNG
     
  18. Arthur-LVGameDev

    Arthur-LVGameDev

    Joined:
    Mar 14, 2016
    Posts:
    228
    Hopefully this will save others some time, and yield a massive performance gain without having to spend the time benchmarking the different available solutions out there.

    FWIW -- This line-drawing library is the fastest one I've found & that is what I would call at least "moderately accessible". Note that YMMV, keep in mind my "context" and use-case, though I can say that I pretty thoroughly explored the options below and am relatively confident in my findings.

    Here's a quick breakdown, including my context & findings:

    Standard [Unity] Line Renderer -- If you're reading this, you already know it's very slow & really only useful for quick debugging, rapid prototyping, or other very small use-cases that will never need to scale.

    Vectrosity -- Faster than Unity's LR, but still relatively slow & simply does not scale. The API is nice, it has some nice "icing-on-cake" shiny features, and if you aren't trying to draw tons of lines then it might suffice for you. That said, the approach that it takes to rendering is quite dated & it really has not been updated for performance, neither to take advantage of [the many] "new" ways to improve via leveraging the GPU, nor to address the litany of allocation issues it has. It largely relies on a basic "pooling" strategy for performance; if you're doing something that needs to scale, you likely can rule it out simply knowing that it's largely relying on a [IMO mediocre] pooling strategy.

    Linefy -- Much, much faster than Vectrosity. Based on documentation and my quick skim of their promotional material & the forum, it's supposed to be very light on CPU / leverage GPU, so long as the lines are not changed in any given frame. Unfortunately my findings did not support that claim -- it may be due to overdraw, I'm really not sure, but I do know that the *exact same* lines drawn with Linefy came in at ~30FPS.

    Fast Line Renderer -- The fastest of the libraries I tried. Same exact scene/large 'set of lines' mentioned above renders at >=70FPS. The API absolutely requires more work to deal with though, so it's definitely going to be more work to implement, though that's also why it's the fastest -- you're able to give more "precise" data to the library (and really, to the mesh/GPU), which means there's simply less data that has to get to the GPU. Even then, the rendering alone is just far faster. If you need to render LOTS of lines (and you have some dev chops) then, at least as of the time of writing this, you don't need to look any further -- this is the way to go.

    Background -- My Use Case / Context:
    I'm drawing "2D roads" -- essentially a 'map view' of a city, with simple white line segments. Larger roads are thicker width, but they're still just white lines on a black background. Untextured, unlit, no lighting at all. All drawn in world space, drawn once [procedurally] at startup, and then never changed or altered.

    My 'main' test scene involved:
    2646 total Roads [each is 1 line]
    28547 total points [each pair is 1 line-segment]
    Avg. Pts per Line: 10 [I didn't check median but it's likely around the same]

    Test Info:
    Unity Editor version: 2020.3.14f1
    Machine: 2019 Mac Pro; lots of RAM; fast 12-core Xeon CPU; GPU is RX5700XT w/ 8GB RAM.

    Gripes with FastLineRenderer:
    Ignoring the slightly more-involved developer API, I have only one gripe for the developer & it ought to be an easy fix (or not doable due to something I'm overlooking). Currently each FLR instance is limited to N lines and M verts -- presumably due to the Unity mesh size limitation (16-bit / 65535 verts max). However, that limitation no longer exists in the latest version of Unity; you can now set the mesh indexFormat to 32-bit and have up to 4B verts per mesh. Platform support is quite good -- pretty much all desktop class GPUs support 32-bit indices; and even on mobile, most platforms do, too. More info here: https://docs.unity3d.com/ScriptReference/Mesh-indexFormat.html

    I'd like to see 32-bit mesh indexFormat be an option out of the box, so that users don't need to instantiate multiple instances of FLR.

    SUMMARY:
    If you're looking for VERY fast line rendering & you require a truly scalable solution -- I can confidently recommend this library. :)
     
    hopeful likes this.
  19. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,464
    Stand-by for an update :)
     
    hopeful likes this.
  20. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,464
    1.4.0 update has been sent to the asset store, with a default of 1 million max vertices. You can change this by modifying the MaxVerticesPerMesh variable in FastLineRenderer.cs.
     
  21. Arthur-LVGameDev

    Arthur-LVGameDev

    Joined:
    Mar 14, 2016
    Posts:
    228
    Well, yet another very fast thing about this asset -- the updates!! =)

    Good stuff. It's pretty rare for us to find an asset on the store that actually does a good job at solving the problem it's intended to solve, is well written, receives updates, and is actually 'usable' overall in a real production environment. Happy to be able to say, you've checked all those boxes & more.

    Ty & keep up the good work! :)
     
  22. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    522
    Hey, did you ever figure out more about this? I am thinking about changing from Vectrosity to something else, but cannot decide between Linefy and FLR.
    The most important feature to me is constant onscreen pixel size for world positioned lines, and I think FLR doesn't quite get this right? I dont have a huge amount of lines to draw, so convenience in the API is probably more important than performance actually. Would you recommend Linefy or FLR?
     
  23. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    I'm evaluating whether I can expect better behavior from this tool compared to Unity's LineRenderer for my purposes. I have a beam that can reflect off of surfaces. Unity's LineRenderer does a particular bad job with sharp angles, but it at least render's in a camera-facing billboard mode. So far, it seems like FastLineRenderer doesn't face the camera, and I get different thicknesses to the line depending on the viewing angle. Is there a way to avoid that?

    upload_2021-9-26_12-3-16.png

    For comparison, Unity's line render doesn't thin out the line depending on viewing angle:

    upload_2021-9-26_12-7-43.png

    Is this just a setting I'm missing? Thanks.
     
  24. knas01

    knas01

    Joined:
    Feb 24, 2018
    Posts:
    236
    @jjxtra Hi, I've been looking for something that can create a ton of cables, or the silhouette of them. Is it possible to create different bundled shapes of hanging or jumbled up cables? It must also work with URP and with fog and volumetric fog. Is this possible?
     
  25. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,464
    I haven’t gotten the constant size option just right yet unfortunately.
     
  26. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,464
    I need to adjust my lines in screen space. It’s been on my list of things to do for a while now…
     
  27. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    522
    I've been using Linefy for a while now, and it has very good and easy support for lines having a constant size in screenspace.. might be something worth looking into.
     
    Steve2375 likes this.
  28. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    424
    Hi! Does this asset suitable for UI and 2d grid renderers(of lines)? Can i use and blend textures for these lines?
     
  29. flipwon

    flipwon

    Joined:
    Dec 29, 2016
    Posts:
    179
    I was looking at doing something like this. This asset is incapable I take it?
     
  30. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,464
    Correct, my billboarding is not as nice as the Unity line renderer.
     
  31. flipwon

    flipwon

    Joined:
    Dec 29, 2016
    Posts:
    179
    Damn :(
     
  32. flipwon

    flipwon

    Joined:
    Dec 29, 2016
    Posts:
    179
    Any chance this is on a short list? :p
     
  33. aggaton

    aggaton

    Joined:
    Jul 3, 2021
    Posts:
    113
    @jjxtra Does this asset work in URP?
     
    Last edited: Dec 23, 2022
  34. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,464
    Should do but let me know if any issues
     
  35. idunlop_oefun

    idunlop_oefun

    Joined:
    Aug 31, 2010
    Posts:
    240
    Having some trouble figuring out how to use this asset. I've managed to put together a test script (see below). Is this the optimal way to do dynamic lines?

    https://drive.google.com/file/d/12v60tt9xeZpX7nY8wEP47WORlUeBWe43/view

    Fast Line Renderer.png

    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using DigitalRuby.FastLineRenderer;
    5. using UnityEngine;
    6.  
    7. public class singleFastLineTest : MonoBehaviour
    8. {
    9.     public FastLineRenderer LineRenderer;
    10.  
    11.     FastLineRendererProperties [] props;
    12.     FastLineRenderer r;
    13.     Color32 color = new Color32(0, 0, 0, 255);
    14.  
    15.     const int lineCount = 8000;
    16.  
    17.     void Start()
    18.     {
    19.         r = FastLineRenderer.CreateWithParent(null, LineRenderer);
    20.         r.Material.EnableKeyword("DISABLE_CAPS");
    21.         r.SetCapacity(lineCount * FastLineRenderer.VerticesPerLine);
    22.         r.Turbulence = 0.0f;
    23.         r.BoundsScale = new Vector3(100.0f, 100.0f, 100.0f);
    24.  
    25.         props = new FastLineRendererProperties[lineCount];
    26.         for(int i=0; i<lineCount; i++)
    27.         {
    28.             props[i] = new FastLineRendererProperties();
    29.             props[i].GlowIntensityMultiplier = 0.1f;
    30.             props[i].GlowWidthMultiplier = 2.0f;
    31.  
    32.             color.r = RandomByte();
    33.             color.g = RandomByte();
    34.             color.b = RandomByte();
    35.  
    36.             props[i].Radius = 0.02f;
    37.             props[i].Color = color;
    38.         }
    39.     }
    40.  
    41.     void Update()
    42.     {
    43.         r.Reset();
    44.         for (int i = 0; i < lineCount; i++)
    45.         {
    46.             props[i].Start = UnityEngine.Random.insideUnitSphere;
    47.             props[i].End = UnityEngine.Random.insideUnitSphere;
    48.             r.AddLine(props[i]);
    49.         }
    50.         r.Apply();
    51.     }
    52.  
    53.     private byte RandomByte()
    54.     {
    55.         return (byte)UnityEngine.Random.Range(0, byte.MaxValue);
    56.     }
    57. }
    58.  
     
  36. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,464
    Script looks good, but you only need to add the lines in start unless they change.
     
  37. idunlop_oefun

    idunlop_oefun

    Joined:
    Aug 31, 2010
    Posts:
    240
    In my case they are changing - no static lines.
    Thanks!
     
  38. Michael_Swan

    Michael_Swan

    Joined:
    Aug 24, 2021
    Posts:
    59
    Hi,
    Looks like a nice line render! Are you projecting the lines onto 2d screen space and rendering the lines in a pixel shader, hence the line thinning at close camera angles?

    Does it work in webgl - ie I'd imagine it'd have to be webgl 2.0?
     
  39. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,166
    Is it compatible with URP and Unity 2022.2?
     
  40. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,464
    Yes in theory. Haven’t tested it.
     
  41. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,464
    No it’s not that fancy unfortunately. Haven’t tried in webgl.
     
  42. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,166
    I can buy it in theory.
     
    vovo801 likes this.
  43. lmaxsmith

    lmaxsmith

    Joined:
    Nov 21, 2016
    Posts:
    3
    Whenever i populate a new object using these lines, I get a little flash at each endpoint. I assume it must be costing performance and I can't figure out how to get rid of it.