GPU particles
category: general [glöplog]
What's the best way to create a GPU based particle emitter? I've got a few particles floating around a noise field, but I'm not sure what's the best way to add and remove particles.
Coder colors (normal mal) with glow.
Coder colors (normal mal) with glow.
buy a blender
Randomly.
Dig through smashs articles, he wrote about it.
Dig through smashs articles, he wrote about it.
Use a geometry shader. Every particle should know its type (emitter is a particle type). in the geometry shader emit your Emiter Particle unchanged, and then additionally emit the generated particle of your choice. Use transform feedback / stream out for getting your new particle buffer which you're going to render.
So I should simply add (with glBufferSubData) a particle marked as an emitter at the end of the buffer, then I should process the physics of the thingy on the vertex shader, and emit 0 or a bunch of particles on the geometry shader?
Yes, use two passes:
1st pass: with a GS: don't emit particles that became dead, emit generated particles and also emit the "emiter particle as well". Using transform feedback you route all emitted particles to a buffer, that buffer has your "live particles", which you can use for your 2nd pass.
2nd pass: use the live particles buffer, transform them in the VS, draw them with the PS.
finally use that live particles buffer as an input for the 1st pass in the next frame. You should ping-pong 2 buffers for this to work efficiently.
1st pass: with a GS: don't emit particles that became dead, emit generated particles and also emit the "emiter particle as well". Using transform feedback you route all emitted particles to a buffer, that buffer has your "live particles", which you can use for your 2nd pass.
2nd pass: use the live particles buffer, transform them in the VS, draw them with the PS.
finally use that live particles buffer as an input for the 1st pass in the next frame. You should ping-pong 2 buffers for this to work efficiently.
oh, and of course, don't render your emitter particle in the 2nd pass. simply discard that vertex.
Xernobyl,
Looks like when galaxies formed after the big bang :D
Looks like when galaxies formed after the big bang :D
@moredhel I don't know, I wasn't there.
@xTr1m right now I'm doing a for on the GS to emit particles if the particle is an emitter, or I emit none if life's too short. But I'm still not sure on how to add new emitters.
@xTr1m right now I'm doing a for on the GS to emit particles if the particle is an emitter, or I emit none if life's too short. But I'm still not sure on how to add new emitters.
add new emitters? use a ranodm is_emissive flag on the particles. maybe you can hide in an unused bit somewhere, so it doesn't blow up the buffer for nonemmissive particles. or maybe you can store a random primitive id somewhere that let's the GS know when to emit some more.
and i just thought... there's a trick needed to output to a second stream while doing the standard rasterizer pipeline at the same. that way you could do it all in one pass i guess. M$ call. :D