Skip to main content
GameDev.net gamedev.net
🔒 Locked

Sorting of GPU Particles

Started by goruka Jan 12, 2010 at 11:17 AM 2 replies 3.7k views
Original Post
goruka
goruka
hi! I recently started investigating on doing particle systems on GPU. As far as i could find, the biggest limitation is that for some effects such as smoke, particles need to be sorted by depth. I looked for ways around this, and i could only find 1) Bitonic merge sort - this algorithm seems to be the fastest way to do sorts on GPU, however it's still considerably very costly for large amount of elements. It seems to be recommended to do it incrementally but so far and even for not so fast emitting particle systems, it doesn't look it can keep the system sorted very well. 2) Use an accumulation buffer and divide (color/alpha_accum)/accum, which is an approximation but looks allright - this seems really fast but quite demanding on video ram and won't discriminate between a small or fullscreen particle effect. 3) Apply some sort of noise to alpha - this seems to work great for grass, though doesn't seem to work so great for smoke. So, what are your experiences with this? So far it seems the only way i could find was OpenCL/Compute which allow for scattered writes (thus, using other kind of algorithms).. but that won't work on older cards..
goruka
goruka
did i ask something too strange? should i clarify?
eq
eq
Another problem is that different alpha blended geometries could have different blend modes and/or textures/shaders.

Imagine a car with transparent windows that goes through some smoke.
The windows of the car might have some fancy fresnel reflections and refractions while the smoke might be using some simple billboarding approach.

This means that the windows needs some special textures (maybe dynamic) and some pixel shader math that the smoke doesn't need.

If you sort the individual triangles for the glass and smoke they might be interleaved and in the worst case you need to switch shaders / textures between every single triangle (or use an ubershader containing all shaders).
Worse is that you can not access any number of textures in a single shader (maybe you can in DX10 using texture arrays).

Even sorting individual triangles isn't enough since they could intersect.

All of the above boils down to the fact that it's extremely hard to handle alpha blended geometry 100% correct (especially if you need to have some sort of performance).

I think you should accept that you won't be able to handle things 100% correct and start thinking on how you can minimize artifacts instead (while still maintaining some performance).

Another problem with per triangle sorting is that billboarded triangles (i.e triangles facing the camera) will show popping artifacts on camera / particle movements.

In some cases (smoke for instance) it could look better to keep the wrong sorting order (this avoids popping).
Popping is quite bad IMO since it some cases it could cause a large portion of the screen to change from one color to another within a frame.
terra0nova
terra0nova
Radix sort works for positive floating point numbers, and is much faster than bitonic merge sort. I think cudpp's sort routine uses radix sort, and that should be fast enough for even a very large number of particles.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.