Sign in to follow this  
Chimaira

3d particle system

Recommended Posts

Chimaira    134
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?

Share this post


Link to post
Share on other sites
Richy2k    313
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?

Share this post


Link to post
Share on other sites
Chimaira    134
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 :|

Share this post


Link to post
Share on other sites
Richy2k    313
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.

Share this post


Link to post
Share on other sites
Chimaira    134
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 :)

Share this post


Link to post
Share on other sites
Richy2k    313
Additive does :)

For smoke effects that look nice you'd need alpha and sorting, but you can avoid it for the most part ;-)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this