Search Unity

Detect when particle is emit? Or last-pose vertex stream option?

Discussion in 'General Graphics' started by zezba9000, Jun 15, 2021.

  1. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    992
    I have a custom particle shader where I set some custom last-pose particle data via "SetCustomParticleData" etc.

    Problem is I need to know if its a particles first frame (which doesn't have last pose data) so I can set defaults.
    Unity doesn't seem to have any way to hook into this event.

    Also why doesn't Unity have an option to pass in the last-pose in a vertex stream like it does with normal objects? Like really? There is so much extra work needed because of this missing feature.
     
  2. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    992
    Ok found work-around in the code below. "lastParticle = particle;" is the line that detect when a new particle spawned.
    Code (CSharp):
    1. for (int i = 0; i != particleCount; ++i)
    2. {
    3.     var particle = particles[i];
    4.     var lastParticle = lastParticles[i];
    5.     lastParticle.remainingLifetime -= Time.deltaTime;
    6.     if (lastParticle.remainingLifetime < particle.remainingLifetime || i >= lastParticleCount) lastParticle = particle;
    7. // ...
    A big performance boost could be had if Unity would add an option for the last position as a vertex stream option to avoid all this hackery.