Search Unity

ECS + VFX renders 10 million entities

Discussion in 'Graphics for ECS' started by JakHussain, Oct 5, 2019.

  1. JakHussain

    JakHussain

    Joined:
    Oct 20, 2016
    Posts:
    318
    I've published a package that defines some component data for point clouds and uses component systems to transfer the component data into render textures via compute shaders. The render textures are then passed as inputs to the VFX graph to define the position, rotation or even color per particle.

    (Made using Unity 2020.1 alpha)

    https://github.com/pablothedolphin/DOTS-Point-Clouds



    The example above is of 10 million quads being rendered on a mid range laptop at 45 fps and all of those points are representations of ECS data.

    I did this because the hybrid renderer wasn't able to render quite this many entities like the VFX graph can.

    Another limitation of the hybrid renderer is that you can't assign a unique color per mesh but with this you can.

    This can be used for even larger boid simulations and things of that nature. I hope to combine this with the boid simulation example to get like 1 million vs 1 million boids flying through space shooting and stuff. I think it'd be pretty sick.

    If anyone is willing to try it I really look forward to hearing your feedback! I'm new to DOTS so I'd like to be aware of things I can do better before going too far with this.
     
  2. Singtaa

    Singtaa

    Joined:
    Dec 14, 2010
    Posts:
    492
    Code (CSharp):
    1. NativeArray<Entity> eventEntities = eventQuery.ToEntityArray (Allocator.TempJob);
    2.  
    3. for (int i = 0; i < eventEntities.Length; i++)
    4. {
    5.     EntityManager.DestroyEntity (eventEntities[i]);
    6. }
    7.  
    8. eventEntities.Dispose ();
    You can use
    EntityManager.DestroyEntity(eventQuery)
    instead of looping each entity. Much faster using the batch version since it effectively destroy the chunk(s) the entities are in.

    Btw, your Scriptable Framework looks interesting, will take a deeper look!
     
    Last edited: Oct 5, 2019
    JakHussain likes this.
  3. JakHussain

    JakHussain

    Joined:
    Oct 20, 2016
    Posts:
    318
    Thanks for that @Creepgin! Scriptable Framework is another interpretation of Scriptable Object Architecture but ECS is equally modular so the framework is only applicable to monobehaviour projects.

    I'm hoping there could be a render texture API supported by DOTS since the biggest performance hit on my point cloud system is the wait between dispatching the compute shader and the work needing to finish on the same thread. Or am I misunderstanding something?
     
  4. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,271
    It looks like you are reloading the compute shader and render texture each frame. Try caching those in the OnCreate. Liewise, try caching your data writer in OnCreate as well since that is a class type and you are generating it every frame.
    Also, why are you dispatching the compute shaders to work on a temprorary render texture just to copy it into the real texture? And why are you flushing the graphics pipeline? Pretty much all the Graphics API use an internal command buffer and dispatch to the GPU. CopyTexture included.
     
  5. JakHussain

    JakHussain

    Joined:
    Oct 20, 2016
    Posts:
    318