3d particle system

Started by
4 comments, last by Richy2k 16 years, 11 months ago
I've been trying to make a pretty simple particlesystem for a fire in a 3d-game, i am pretty satisfied with the result this far, there is just one problem. The particlesystem spawns a new billboard every 5ms and sends it upwards, for every update the billboard is moved further upwards and also shrunk by 10%. I also move it backwards a small amount to place new particles(rendered last in renderloop) in front of the old ones. The problem comes when you view the fire from above, then the increase in Y will be much larger than the increase in Z and the old particles will be placed over the new ones which looks like crap because the textures of the quad is semi-transparent. This picture might explain better :) Just noticed that the last image is wrong but using too large dZ will mess things up anyway, particles will get moved into walls etc... :P Is there any smart way to solve this or is Z-sorting for every frame the only option?
Advertisement
Are you using alpha blending or additive blending?
If you are using alpha blending you will need to draw your particles furthest away first to the nearest last.
That is, assuming I understood your problem?
Adventures of a Pro & Hobby Games Programmer - http://neilo-gd.blogspot.com/Twitter - http://twitter.com/neilogd
I'm using alpha blending and i know that i have to draw particles behind first, that's the reason i'm moving the particles a small step backwards for every frame ;) The problem is that this sorting-method doesn't work in all cases.

I've also tried additive blending and it looks good even without sorting, but then the problem is that you loose the z-buffer :|
Well...you don't lose the Z buffer...but its completely useless to do z writing with additive...

There is no need to move particles back along Z each frame, a simple solution is to do a bubble sort - but not fully sorting all the particles. Basically just perform a couple of iterations through the particle list each frame, should be more than quick enough. The particle system for a game I'm currently working on does 2 iterations of a bubble sort each way, for a few particles - about 100-200, it will sort them pretty much over a few frames, rarely do I see a glitch. Just sort by the actual distance from the cameras origin, rather than the Z - means it will work well from any viewing position or direction. A plus factor is it can handle several thousand very well, although you see more glitches.

Another way to sort is a Radix sort, but that will require more CPU to perform it per frame. But Radix sort is really quick in most circumstances with many objects to sort, so may be pretty good for smaller numbers of particles, a couple of hundred or so.
Adventures of a Pro & Hobby Games Programmer - http://neilo-gd.blogspot.com/Twitter - http://twitter.com/neilogd
Solved it by using additive blending and disabling z-writing. Before i disabled both z-writing and testing which made the system visible through walls but with only writing disabled it works perfect without any sorting at all :)
Additive does :)

For smoke effects that look nice you'd need alpha and sorting, but you can avoid it for the most part ;-)
Adventures of a Pro & Hobby Games Programmer - http://neilo-gd.blogspot.com/Twitter - http://twitter.com/neilogd

This topic is closed to new replies.

Advertisement