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 Limit visible particles to graphics buffer count

Discussion in 'Visual Effect Graph' started by peaj_metric, Jan 18, 2023.

  1. peaj_metric

    peaj_metric

    Joined:
    Sep 15, 2014
    Posts:
    145
    I have a graphics buffer that contains positions and some additional data.
    The length of this buffer can be different each frame.
    I would like to limit the number of visible particles to the length of the buffer so it will only display as many particles as defined in the graphics buffer.
    What is the best way to limit this?

    I am currently setting their "Alive" state in the render context by comparing the particle id with the buffer length like this:

    upload_2023-1-18_11-12-50.png

    Is this actually the best solution?
     
  2. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,108
    If you have constant buffer size and you know that number of particles would never exceed this number, then hiding some particles by killing them sounds reasonable as you don't need any other thing than spawning that exact amount of particles at the beggining.

    However if you allocate+dispose that buffer over and over and it's size jumps like
    3 => 10 => 16 => 6 => 12
    and you want the system to have that exact number of particles equal to buffer I find it easier to control this by introducing some add/remove system. When you need 3 more particles then previously you send spawn event and spawn that number of particles, if you need 3 less, then you kill that number in update. Still, I can't remember right now if I made it work this way, because of particle id - I am not sure if that was just index of particle or it was distributed when spawned, so you would need to test.
     
  3. peaj_metric

    peaj_metric

    Joined:
    Sep 15, 2014
    Posts:
    145
    That sounds like an interesting solution. The buffer is mapped to enemy positions so its count will vary a lot over time.
    But I also dont have a clue how to map the buffer to particles if I actually kill/spawn them.
    Besides its easy to spawn particles via event bit how can I kill a specific number of particles via events.
     
  4. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,108
    You don't do it via events, but graph properties. You set count and then you do something like this in update:
    alive = particleIdOrSomething < count
     
  5. peaj_metric

    peaj_metric

    Joined:
    Sep 15, 2014
    Posts:
    145
    Oh I see thats what I was doing before moving the alive part into the render context.
    Thanks for explaining the difference to me in the otehr thread btw. (https://forum.unity.com/threads/how...tted-without-killing-it.1019896/#post-8734521)

    I guess I will see if this is a actually a performance bottleneck later and try out your suggestion if it is.
    Would be great if vfx graph would be able to scale the capacity at runtime or discard particles early based on their id though.