PDA

View Full Version : Particle systems...



Teofuzz
02-21-2001, 12:30 AM
I coded a particle system that now works well...
Because I need to sort particles (viewer distance) in order to blend them properly, this causes a little slowdown... If I don't sort them the black rectangle of the texture becomes visible. I use glBlendFunc(GL_SRC_ALPHA,GL_ONE).
I'd like to know if there is some way to draw the particles without sorting.
Thanks!
tFz

Bob
02-21-2001, 02:33 AM
Yes, there are a few ways to draw particles without sorting. All you have to do is find a proper blendfunction, and use a correct texture format.

For additive blending, where particle emmits lightm like sparks and other glowing and somewhat transparent stuff for example, you can use glBlendFunc(GL_ONE, GL_ONE).

For non light-emitting objects, like smoke, you can use glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) (I'm really unsure about this one thoug, but it's something like that).

In the case of additive blending, you just use a standard RGB (or luminance) texture. For non light-emitting particles, you use a GL_ALPHA-texture, and set the color of the particle with glColor. If you have an alphatexture of a cloud/smoke, and set the color to somewhere near black, you will have a very dense black smoke where many particles are drawn. Where less particles are drawn, the dark color will be blended with the background.

And when not using sorting, you must draw first the surrounding environment, and then the particles. Also make sure you disable depthtest. Since you draw particles last, nothing else will be rendered in front of the particlesystem, so you can disable depthwrites aswell.

Also remember to render the different partclesystems in back to front order. This is no big deal, since you don't usually have that many systems in the world.