I don't know how to work with my particle's lifetimes. My design is simple: each particle has a position, a speed and a lifetime. At each frame, each particle should update its position like this:

position.y = position.y + INCREMENT * speed.y

However, I'm having difficulties in choosing my INCREMENT. If I set it to some sort of FRAME_COUNT, it looks fine until FRAME_COUNT has to be set back to 0. The effect will be that all particles start over at the same time, which I don't want to happen. I want my particles sort of live "independent" of each other.

That's the reason I need a lifetime, but I don't know how to make use of it. I added a lifetime for each particle in the particle buffer, but I also need an individual increment that's updated on each frame, so that when PARTICLE_INCREMENT = PARTICLE_LIFETIME, each increment goes back to 0.

How can I achieve something like that?


1 Answer 1


Are you attempting to implement a stateless particle system in a shader? You need an extra vertex attribute: timeoffset. Pick a random timeoffset value for each particle.

So your vertex attributes are:

startpos // vec per vertex
velocity // vec per vertex
timeoffset // scalar per vertex (N random values in [0..lifetime])

and you have the uniform variables:

currenttime. // scalar, one value for all vertices
lifetime. // scalar, one value for all vertices

Then in your shader:

t = currenttime + timeoffset;
t = t % lifetime;
pos = startpos + t * velocity;
  • \$\begingroup\$ Thanks for your time. This is actually quite close to something I managed to implement after all (but that still had a few problems). I'll come back when I try your solution. \$\endgroup\$
    – async
    Commented Dec 1, 2013 at 19:14
  • \$\begingroup\$ Tried your solution, works precisely as I wanted. :) Thank you. \$\endgroup\$
    – async
    Commented Jan 21, 2014 at 22:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .