This project is read-only.

Sorting Particles

Feb 5, 2014 at 9:44 AM
Following situation:

I have a particle simulation / particle system running with CUDA.

The particles position are stored as VBO the movement is done with a Kernel as ptx file using managedCUDA. Everything is fine so far.

For rendering I render the VBO with a shader and get nice looking particles in my scene. So far so good.

BUT: For correct rendering I want to have back-to-front rendering of the particles. The idea is to use the distance to the image plane as key and sort the array high to low. So that particles far away from the viewer are rendered first and the whole thing looks nice for opaque or even transparent particles.

So of course I want to do the sorting on the device and I don't care if it is inplace or not, since the order of particles is irrelevant for the simulation kernel.

What is the fastest thing to do it? Radix Sort? How can I get a working kernel based on float keys? Is there a (easy) way to get thrust running (in this specific setup) ? How would you sort things in this case?
Feb 5, 2014 at 4:35 PM
Edited Feb 5, 2014 at 10:46 PM
Unfortunately you will end up writing your own specific kernel for this. Using thrust with managedCuda is currently not possible and I don’t think that this will change in future as this would require a lot of work to port host components to C#. Basically one would need to implement a bunch of standard algorithms as plain cuda kernels and corresponding host connections, and this for every single type. Kind of manually doing the compiler’s job for templates...
In case you have a GPU with compute capability 3.5, you can check out nvidia’s cuda samples, there are some sorting algorithms implemented. Also CUB has something, I think.

Two more links I found:

Feb 6, 2014 at 7:26 AM
Hey Michael,

thank you very much! I will take a look into that.