Search Unity

ECS LineRenderer released

Discussion in 'Data Oriented Technology Stack' started by 5argon, Dec 16, 2018.

  1. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,265
    Screenshot 2018-12-16 01.39.25.png

    I made a small package to render a line with pure ECS. One Entity per one line segment. I recently got a container arrangement visualization job for use in logistics which I decided to use ECS to tackle it.

    In the picture each straight line is one Entity with
    LineSegment
    containing float3 indicating from-to position and a line width. And
    LineStyle : ISharedComponentData
    indicating what material to use. Both components on one Entity will cause the system to attach the remaning things to be able to render a line, like MIR and LocalToWorld.

    https://github.com/5argon/ECSLineRenderer

    Idea
    Generate a thin rectangle mesh that goes 1 unit in the Z axis. Using MeshInstanceRenderer component and the TransformSystem, we could use z scale as line length, x scale as line width, position as line from, and rotation as line to. Assuming that this is only one segment of a line.

    To construct complex lines, we create more LineSegment entity. They should be render instanced as they are using the same mesh. What's left is to wait for MeshInstanceRendererSystem to support material property block so we could change line color without a new material. Rounded caps not suported yet, but surely that will break instancing because of different mesh.

    All lines are always rotated to face the main camera in billboard rendering style.

    ~billboard.gif
     
    Baptiste-, illinar, tbriley and 7 others like this.
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    1,428
    Fine :) I'm also waits official ecs renderer with layers, MPB and other :) (of course we can use our own version). In my case I use simple quad mesh with my billboard shader for game indicators, and use global vector for scale. But every indicator view use different material (with same texture but different offset), but wih MPB I'll can change atlas offsets without generation new instances and drawcalls :)

    (old video)
     
    Last edited: Dec 16, 2018
    5argon likes this.
  3. tbriley

    tbriley

    Joined:
    Sep 10, 2013
    Posts:
    111
    works great, though i get a boxing error at line 69. it's not obvious to me why the boxing happens, and why this resolves it:

    Code (CSharp):
    1.  
    2. if (seg.from.Equals(seg.to) || seg.from.Equals(cameraPosition))
    3. {
    4.   continue;
    5. }
    6.  
     
  4. Srokaaa

    Srokaaa

    Joined:
    Sep 18, 2018
    Posts:
    72
    Just in time! I needed something exactly like this. Did you do any benchmarks on large amounts of lines drawn on a screen?
     
  5. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,265
    No time to do it yet.. but essentially it should be equivalent of any ECS showcase which draws a ton of boxes or spheres since each line is essentially just a tiny plane with same mesh + different matrix calculation. Something might be inefficient there that I have to look at later.

    I would like to make a benchmark scene like that Kingdom Hearts 2 boss who shoots million of lasers from around you to the center, but I would like to add rounded caps support first.

    Is the error only when using Burst? I might forgot to turn it on the whole time. Will look at it later. Thanks!
     
  6. tbriley

    tbriley

    Joined:
    Sep 10, 2013
    Posts:
    111
    yep, only with burst
     
  7. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    1,661
    Your issue is there is no explicit implementation of float3.Equals() so it's using the default Object.Equals(object, object) method which causes the boxing.
     
    florianhanke likes this.