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 approach Particle System trail effect, using DOTS?

Discussion in 'Entity Component System' started by Antypodish, Dec 24, 2021.

  1. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,574
    Hey and happy xmas / holidays to everyone.

    I want to ask, how would you propose to approach trail effect, which uses Particle System in DOTS?

    I use PS Trails, and Game Objects pooling system and culling, but as more projectiles are rendered and handled, this start takes a performance toll, when PS is handled. Also I need generate tons of GOs with PS just to do that visual effect.

    upload_2021-12-24_10-34-24.png

    So here is an example of what I try to optimise

    upload_2021-12-24_10-40-15.png

    I was thinking about line renderer approach with DOTS or something like that.

    Any thoughts?

    @eizenhorn any thoughts how would you be approaching problem, for flammable arrows as per your game?
     
  2. inSight01

    inSight01

    Joined:
    Apr 18, 2017
    Posts:
    86
    I'll second this. I was just looking into this myself. I don't recommend attaching a Particle System to the entity because it will cripple performance. So I'm very curious to know how others are managing particle effects on the tens of thousands of entities being produced.
     
  3. Arnold_2013

    Arnold_2013

    Joined:
    Nov 24, 2013
    Posts:
    262
    I use VFX graph for my trails. It might be faster because they run on GPU. But no physics. So the emitter (entity with unity physics in ECS) is moving and does physics while emitting smoke quads aligned to camera.
    The smoke quads are set in WorldSpace in VFX, so they are not affected by emitter movement. They do disappear when the emitter (ECS entity) is destroyed, so I Stop() the VFX and wait with destroying the ECS entity until the smoke is gone.

    You still have the VFX as companion objects (not ECS), so it might not help for performance as much as you want. But VFX graph is supposed to be more efficient than particle system for showing massive amounts of them.

    Example of green smoke bouncing on terrain:
    upload_2021-12-24_11-16-26.png
     
    Antypodish likes this.
  4. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    As an alternative for Particle System pooling, you could try emitting particles from single system instead of creating multiple game objects. This is significantly faster on larger scale, albeit a bit trickier to setup.

    And there's a bunch of caveats for the Emit call. But its worth it.
    I'm using similar setup for bullet casing(s), which allows to spawn thousands of those from a single Particle System.

    As a bonus - you're able to fully control budget of how many particles can be spawned, and whether they use buffer etc.


    Con is the culling. All particles would be drawn no matter what (unless they're localized in an area outside the view).

    But at high quantity counts its usually faster to just render thousands of particles in a single draw call, than deal with culling, bounds etc. This depends on target device of course.
     
    Last edited: Dec 24, 2021
    Antypodish likes this.
  5. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,653
    Well, it's in our TODO list after EA in January, but I already designed on paper my solution. It will be just a custom trail renderer, we already have our own billboard particles with sprite sheet animation, we'll just expand that solution to support trails. As in our case we need simple trails, they will be just simple billboard polygon lines (depends on the resolution of the trail just imagine 2-3-4 quads in a line) with bezier equation calculation points in a shader for proper bending, and through per-instance properties, every trail pivot will be positioned in current projectile position and will have a per-instance property of current and previous velocity of the projectile and will reconstruct backwards trail vertices position, as it will be mostly vertex-based calculation four couple of vertices on GPU it's pretty cheap. Of course this approach not perfect, but for the RTS game, it's completely cover all the requirements.
     
  6. officialfonee

    officialfonee

    Joined:
    May 22, 2018
    Posts:
    42
    Adding to what eiznehorn said, I am sure there is also a solution with curves and using geometry shaders. This limits you to specific hardware but I being all on the GPU would mean some speed.
     
    Antypodish likes this.