Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Fast Line Renderer

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

  1. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,197
    Not supported, email me for refund.
     
  2. hecali_aj

    hecali_aj

    Joined:
    Sep 1, 2015
    Posts:
    15
    Okay, thanks.
     
  3. lerpenbe

    lerpenbe

    Joined:
    Apr 27, 2018
    Posts:
    3
    Hi jixtra,
    We are currently testing your asset to achieve an effect we couldn't create with the standard LineRenderer.
    Basically we want to have 2 Sliders from 0 to 1 that control the amount of a line that gets drawn. Think of it like a percent range. So 0 and 1 draws the whole line and 0.33 to 0.66 would draw the middle of the line. Then we want to "animate" the higher value until the line reaches its end. The normal LineRenderer is not performant enough for the amount of points we have in a line. We tested it with direct point manipulation, which generates way too much garbage because large arrays are created and invalidated every frame. We also tried using a gradient and just moving the alphaKeys around, which kinda worked but still was very slow.

    I know it's possible to animate the lines with AddCreationTimeSecond but that isn't enough for this effect. How could we achieve this? Is there maybe a way where we could directly set the alpha values in a certain range to 0 or something similar? Directly set the range of the points that gets drawn?
    If you have any pointers where we should look or any ideas how to achieve this, that would be greatly appreciated!
     
    hneumann92 likes this.
  4. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,197
    I don't know if you can use the new visual effects graph but that is one option. If you are changing and creating lines every frame, you will run into some cpu and garbage issues with fast line renderer as it still has to create a new mesh and update it on the GPU when anything changes. If you are not changing lines every frame, fast line renderer is an order of magnitude faster than the Unity line renderer.
     
  5. ecurtz

    ecurtz

    Joined:
    May 13, 2009
    Posts:
    640
    Just bought this for a project, looks great. One disgusting but effective thing we do in UMA where we do a lot of runtime Mesh generation is to preallocate static maximum size lists and use reflection to set the internal size before calling the Unity Mesh setter methods. Then we can just reuse them instead of building new ones.
     
  6. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,197
    Please share the hack if you can I will get it put right in!
     
  7. ecurtz

    ecurtz

    Joined:
    May 13, 2009
    Posts:
    640
    ferretnt likes this.
  8. NADI_system

    NADI_system

    Joined:
    Apr 30, 2018
    Posts:
    1
    Fast Line Renderer support WebGL?
     
  9. Player7

    Player7

    Joined:
    Oct 21, 2015
    Posts:
    1,535
    Did you put in this implementation interested to see the results of it.
     
  10. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,197
    I haven't tested WebGL, no ETA on that...
     
  11. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,197
    Have not done it yet no.
     
  12. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    675
    Hey, bought your asset a couple days ago and am already running into a couple issues / nitpicks.

    1) You are instantiating the material instead of using MaterialPropertyBlock, thus wasting a ton of DrawCalls
    2) The shaders you are shipping with the package are wasting tons of instructions if someone wants to only draw lines. If there's no need for wobble / jitter / glow / animation / lifetime ... Please make some proper toggles for things like "DISABLE_CAPS", as it's currently very unclear what in your Inspector does what.
    3) Your worldspace implementation is broken since it adds that invisible GameObject to the object the FastLineRenderer is on. If you move that around now, the lines will follow despite they should be world space.
    4) Your localspace implementation has issues with the parent object being rotated, since the invisible renderer will "inherit" that rotation.
    5) Screenradius doesn't work since the dir isn't transformed into world space.
    6) Inspector is messy / no headers, difficult to use
    7) Doesn't work with the LDRP/HDRP

    And some suggestions:
    1) You provide a "minimal" shader example without all the bells and whistles so it can be adjusted for different usecases.
    2) This would also allow rebuilding the line shader in Amplify or ShaderGraph
    3) clean up the inspector
    4) show an example of how to draw lines at Edit time, not only at runtime

    Also, @NADI_system : we're using it successfully with WebGL (after fixing some of the issues outlined above).
     
  13. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,197
    1] Will look into it
    2] Any GPU in the last 5-6 years should branch off of a uniform value essentially for free. Doing a few multiplies vs introducing a lot of variant shaders is probably preferred. But let me know if you see a bottleneck. You are also free to clone the shader in your project, make new material without these features.
    3] I would suggest you put any static fast line renderer objects at the root of the scene instead of on specific game objects.
    4] Will look into it
    5] The screen radius was a quick and ugly hack to try and approximate constant line width, no ETA on something more elegant
    6] Will look into it
    7] LWRP and HDRP are supported in latest update. Let me know if you see any issues with that.

    Feel free to contact me if you want a refund (support@digitalruby.com).
     
    Last edited: Feb 28, 2019
  14. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,197
    Sent an update, 1.3.1. It helps with #1 and #6.

    The WorldSpace property simply orients at 0,0,0 relative to either parent or world space origin. After that it does nothing.

    I am open to ideas for #5, I've spent too many hours without luck so I stopped working on that a while ago.
     
  15. lerpenbe

    lerpenbe

    Joined:
    Apr 27, 2018
    Posts:
    3
    I just stumbled upon my own post and just wanted to update how we 'solved' our issue.
    We added the line:
    Code (CSharp):
    1.  if(i.color.a == 0) discard;
    at line 296 in FastLineRendererShaderInclude.cginc
    which allows us to have fake transparency. I know discard isn't very efficient, but it seems to work fine. If you use regular transparency you get weird glitchy effects where a non transparent line is overlayed by the transparent line. It looks like the transaprent parts of the line "punch a hole" into the non transparent parts.

    This allows us to set the alpha values of the
    Code (CSharp):
    1. fastLineRenderer.mesh.colors
    array, where we want to show/hide the line. Setting the color array every frame isn't super efficient, but it's within our frame budget.

    If you or anyone has any better ideas I'm all ears
     
  16. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,197
    Thanks for sharing, seems OK, I will add it to the asset!
     
  17. RedHotFlashman

    RedHotFlashman

    Joined:
    Mar 16, 2018
    Posts:
    27
    Outline I/O Glow:

    I want to create white lines with a black border. But black doesn't glow. Is there an easy way to do this.
    (I am not a Shader programmer)
     
  18. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,197
    Add a new texture with the black edges?
     
  19. Wolar

    Wolar

    Joined:
    Sep 25, 2014
    Posts:
    38
    Hello, would it be possible to modify the FastLineRenderer.shader (no glow version is enough) to make it write into the stencil buffer? What I want to achieve is to mask something (sprite renderer) with the line - basically have invisible line and have only stuff under the line visible in that sprite renderer.

    So I have copied the fast line renderer shader, made it write into the stencil buffer, made the sprite renderers shader to compare with stencil buffer and render after the Fast Line Renderer but apparently there is some shader magic in the FastLineRenderer that I don't understand which makes it not to write into the stencil buffer as I would expect.

    Is this be even possible to achieve or is there some shader magic that prevents me to do this?
     
  20. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,197
    NeatWolf likes this.
  21. Wolar

    Wolar

    Joined:
    Sep 25, 2014
    Posts:
    38
    Thank you for the link, I know how shaders and stencil buffer works (at least the basics) but if I try to modify the FastLineRenderer.shader to just write into the stencil buffer and render before the sprite renderer I want to mask, it doesn't work, but it does work with other sprite renderer as a mask (with shader writing to stencil buffer), that's why I ask if there is some magic in your shaders that I don't see / understand that would cause the FastLineRenderer.shader not to write into the stencil buffer even though I specified it there.
     
  22. NeatWolf

    NeatWolf

    Joined:
    Sep 27, 2013
    Posts:
    896
    Would be a really cool feature to have
    Would be a really cool feature to have.
    Willing to pay extra (upgrading to a hypothetical v2.0) to have such feature.

    I'm thinking about transitions.
    Dithering support, for a "smoother" stencil buffer "alpha painting" with trails would be cool :)
     
  23. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,197
    Fast line renderer 1.3.2 is now live with critical bug fixes for lines not showing up.
     
  24. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,197
    I have plans for a more powerful line asset in the future. It will involve compute shaders, won't use meshes at all, and it will be much faster than even fast line renderer, allowing screen space sized lines with consistent widths, easier and faster dynamic updates, scriptable object profiles and other goodness. No ETA on release.
     
    Korindian likes this.
  25. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,197
    Fast Line Renderer full code documentation is now online at https://unitydocs.digitalruby.com/

    You can peruse everything, in case you are looking for specific functions or just considering a purchase and want to know what you are getting.
     
  26. Player7

    Player7

    Joined:
    Oct 21, 2015
    Posts:
    1,535
    Still interested in this :)
     
  27. TheNick1140

    TheNick1140

    Joined:
    Mar 1, 2014
    Posts:
    2
    Does this line support a collider object?
     
  28. celechii

    celechii

    Joined:
    Nov 8, 2016
    Posts:
    3
    hey, i got this a couple days ago and its great, but for some reason the lines don't always render? based on camera position it seems? rotating the scene view camera in 3d mode also makes them disappear at some angles. im using unity 2019.1
     
  29. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,197
    Yea the billboarding is not perfect. Have you set your camera to orthographic?
     
  30. celechii

    celechii

    Joined:
    Nov 8, 2016
    Posts:
    3
    yeah, its a 2d game. the gif shows both the game and scene view with the camera set to orthographic mode
     
  31. BenDy557

    BenDy557

    Joined:
    Sep 18, 2015
    Posts:
    2
    Hey guys, does this support rendering to different layers? I cant seem to find anything specific in the documentation and I need it for splitscreen multiplayer reasons :/
    also happy christmas haha
     
  32. country_dragon

    country_dragon

    Joined:
    Jun 26, 2014
    Posts:
    7
    Hi

    I recently purchased your fast line renderer asset in the hope that I can directly swap it out for the Unity line renderer, however I'm experiencing a few issues.

    In a nutshell, I have replaced this code (using the unity line renderer):

    if (unityLineRenderer)
    {
    unityLineRenderer.positionCount = lineList.Count;
    unityLineRenderer.SetPositions(lineList.ToArray());
    }

    with this code (using the fast line renderer):

    if (fastLineRenderer)
    {
    fastLineRenderer.Reset();
    FastLineRendererProperties props = new FastLineRendererProperties();
    fastLineRenderer.AddLines(props, lineList, null);
    fastLineRenderer.Apply();
    }

    This is run every frame to draw lines that I have generated at runtime.

    Problems I've encountered:

    1 - Frame rate. My use-case (around 50k lines) runs very poorly at around 50 ms whereas the Unity line renderer would run comfortably within a frame. According to the profiler, all the time is being spent in FastLineRenderer.AddLines, which isn't surprising since this is doing a lot of stuff (50,000 times), so I can only assume that this is not the way to draw lines every frame. What should I be doing instead? If it's not possible to draw lots of different lines every frame at a reasonable frame rate then this wasn't clear from the asset store description.

    2 - I cannot render the lines to a UI canvas set to 'Screen Space - Camera', which was working fine with the Unity line renderer. I did manage to to get the fast line renderer kinda rendering via 'Screen Space - Overlay' but I've been unable to get this working again...and the lines also seemed to be rendering in the scene as well anyway.

    3 - Code exceptions encountered in FastLineRenderer.CreateWithParent due to parent being null in 'obj.layer = parent.layer', and in FastLineRendererEditor.OnInspectorGUI due to Camera.main being null. I have patched these up locally but I was surprised to see that the asset was throwing exceptions straight out of the box.

    I've played around with the prefabs included in the package and I can't get any of them to work correctly in the scenario where the Unity line renderer was working.

    Any help appreciated, otherwise I will be asking for a refund unfortunately.

    PS: I'm running on Unity version 2018.3.8f1.
     
    Last edited: Jan 11, 2020
  33. markashburner

    markashburner

    Joined:
    Aug 14, 2015
    Posts:
    202
    Hi I just purchased your asset, what is the equivalent of Unity's Line Renderer's renderer.set position with Fast Line?

    LineRenderer line;
    line.SetPosition(etc);

    Does Fast Line have that method?

    Thanks
     
  34. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,197
    FastLineRendererScript has AppendLine, there are lots of demo scripts to reference.
     
  35. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,197
    Are you still having issues? Post back if you are, the email notifications on this thread broke (again)...
     
  36. robertoranon

    robertoranon

    Joined:
    Feb 21, 2018
    Posts:
    16
    Hi, bought the asset yesterday, but I have on issue and a couple of questions, similar to @country_dragon.

    I have a few hundreds points that move on screen, and at each frame I build a Voronoi tasselation (or simply a triangulation) from those points, and turn it into a Mesh.

    I want to use FastLineRenderer to display the edges of such mesh, so I execute the following function at each frame

    Code (CSharp):
    1. private void DrawLines(Mesh mesh)
    2.     {
    3.         fastLineRenderer.Reset();
    4.        
    5.         var vertices = mesh.vertices;
    6.         var indices = mesh.GetIndices(0);
    7.         for (int i = 0; i < indices.Length-1; i += 2)
    8.         {
    9.             var startVertex = vertices[indices[i]];
    10.             var endVertex = vertices[indices[i + 1]];
    11.  
    12.             FastLineRendererProperties props = new FastLineRendererProperties();
    13.             props.Start = startVertex;
    14.             props.End = endVertex;
    15.             props.Radius = 0.01f;
    16.             fastLineRenderer.AddLine(props);
    17.            
    18.         }
    19.         fastLineRenderer.Apply();
    20.     }
    The question, as the other user, is if this is the right way to display a set of lines that change at each frame.
    I have also a problem, as the drawn lines are "longer" than they should be:

    Screenshot 2020-02-02 at 11.40.24.png


    If I do not call Reset(), lines are drawn correctly, but of course they "accumulate" over time ... which is not correct

    Screenshot 2020-02-02 at 11.43.17.png

    What is the problem here? Any help is greatly appreciated
     
  37. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,197
    I’ve sent the refund request to unity
     
  38. robertoranon

    robertoranon

    Joined:
    Feb 21, 2018
    Posts:
    16
    You mean to me?
     
  39. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,197
    Were you the one who asked for refund over email?
     
  40. robertoranon

    robertoranon

    Joined:
    Feb 21, 2018
    Posts:
    16
    No, but your post was just after mine, and I was asking for some help about a strange behaviour with Fast Line Renderer ... Btw, still expecting an answer.
     
  41. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,197
    Interesting. Any chance you could share the project?
     
  42. robertoranon

    robertoranon

    Joined:
    Feb 21, 2018
    Posts:
    16
    Let me reduce it to a small project. How do I share it to you?
     
  43. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,197
  44. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    676
    Hi @jixtra,

    I recently purchased the Fast Line Renderer and ran into quite a few problems.

    I'm rendering connected lines on a mesh, the result I'm getting with Unity's line renderer looks like this:
    upload_2020-4-17_14-15-11.png

    I wanted to get the lines to all have the same size and get it to scale well, since there will be a lot of lines on that mesh.

    When using the very same positions with FastLineRenderer I get this:
    upload_2020-4-17_14-17-52.png

    Interestingly enough, when I add them to the Initial Line Groups, I get the correct lengths
    upload_2020-4-17_14-20-44.png

    Also, updating the line every frame is actually a lot more expensive for me than with the normal line renderer. Maybe there is some hidden API I haven't found yet. The way I'm doing it right now looks like this:
    Code (CSharp):
    1. fastLineRenderer.Reset();
    2. fastLineRenderer.AddLine(lineRendererProperties, worldPoints, (FastLineRendererProperties props) => { });
    3. fastLineRenderer.Apply();
    If I need to use another API, please let me know.

    Settings for the Line Renderer:
    upload_2020-4-17_14-31-16.png

    Some smaller problems I had:

    * The Initial Line Groups break when using Experimental Play Mode (Added in Unity 2019.3)
    * The minimum line radius in the inspector is 0.01, which was too big for me, I changed it to 0.0001
    * The demo scenes do not show how to use this asset with nonstatic points
    * A looping option would be great to make sure the first and last points can be connected as well
    * Overshooting also happened for a simple square on each edge for the glow.

    Would love to get support on that!
     
  45. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,197
  46. seobyeongky

    seobyeongky

    Joined:
    Sep 29, 2015
    Posts:
    10
    @Johannski @robertoranon

    I had similar issue and the extended line is uninitialized glow mesh.
    My workaround is adding a lite version of Cleanup method.

    It just doesn't destroy mesh renderer every frame.

    Code (CSharp):
    1.  
    2. public void CleanupLite()
    3.         {
    4.             foreach (var list in verticesLists)
    5.             {
    6.                 list.Clear();
    7.             }
    8.             foreach (var list in texCoordsAndGlowLists)
    9.             {
    10.                 list.Clear();
    11.             }
    12.             foreach (var list in lineDirsLists)
    13.             {
    14.                 list.Clear();
    15.             }
    16.             foreach (var list in colorsLists)
    17.             {
    18.                 list.Clear();
    19.             }
    20.             foreach (var list in endsLists)
    21.             {
    22.                 list.Clear();
    23.             }
    24.             foreach (var list in lifeTimesLists)
    25.             {
    26.                 list.Clear();
    27.             }
    28.             for (int i = 0; i < boundsList.Count; i++)
    29.             {
    30.                 boundsList[i] = new Bounds();
    31.             }
    32.             ResetCurrentBounds();
    33.  
    34.             listIndex = 0;
    35.             lastPoint = null;
    36.  
    37.             AssignLists();
    38.         }
    39.  
    If you call this method instead of Reset, Then mesh will be reused.
    So it is better call mesh.Clear(true) before the mesh.SetVertices in ApplyListsToMeshes.

    In my case, the renderer moves everyframe so I added this code at the end of ApplyListsToMeshes method.
    Code (CSharp):
    1. if (UseWorldSpace)
    2.                 {
    3.                     noGlowRenderer.transform.position = Vector3.zero;
    4.                     glowRenderer.transform.position = Vector3.zero;
    5.                 }
    I don't know what the problem exactly is but this works for me.

     
    Last edited: Apr 18, 2020
  47. mwb87

    mwb87

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

    I am trying to make a selection cursor with the Fast Line Renderer. Unfortunately the new lines "blink" everytime they get updated. See gif below:

    ezgif-4-a95ca856c1ed.gif

    In the "FastLineRendererNoGlow prefab " I added the dotted line.
    I am using this code, based on the stuff I saw on this forum and the demo's;

    Code (CSharp):
    1. if (lastMousePosition != mousePosition)
    2. {
    3.     var LineGroupList = TileCorners.TileCorners2D(mousePosition, tileSize);
    4.     LineRenderer.Reset();
    5.  
    6.     for (int i = 0; i < LineGroupList.Count; i += 2)
    7.     {
    8.         var startVertex = LineGroupList[i];
    9.         var endVertex = LineGroupList[i + 1];
    10.      
    11.         FastLineRendererProperties props = new FastLineRendererProperties();
    12.         props.Start = startVertex;
    13.         props.End = endVertex;
    14.         props.Radius = 0.075f;
    15.         props.GlowIntensityMultiplier = 0;
    16.         LineRenderer.AddLine(props);
    17.     }
    18.  
    19.     lastMousePosition = mousePosition;
    20.     LineRenderer.Apply();
    21. }
    LineRenderer.Reset(); is causing this problem, when I don't use this, it works (but it doesn't delete the old selection box). Is there a way to only delete the old lines? Or can you point me to the right direction to fix this?

    Thanks!
     
  48. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,197
    The line blink bug is fixed in latest update, please download newest version
     
  49. mwb87

    mwb87

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

    Thanks for the reply. I successfully downloaded the new version (I see 24 changed files inside FastLineRenderer), but unfortunately the bug still occurs.

    ezgif-4-4593888671a2.gif

    I didn't change any of my code posted above.

    ps. I only changed the line texture in the prefab.

    Annotation 2020-04-27 144238.png
     
    Last edited: Apr 27, 2020
  50. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,197
unityunity