I've added a particle system to a voxel game I'm working on. At the moment, all the physics are done on the CPU, and it's pretty slow (my CPU struggles with 2000 particles).
For each particle, I determine the range of voxels that it could theoretically collide with (based on the particle's position and velocity, and the elapsed time), and then check for collisions with all the voxels in that range and use the nearest collision.
To increase performance, I'm exploring whether I can use a compute shader to perform the physics.
If I convert my voxel world into a bit array and toss that in an SSBO, then the compute shader has all the geometry information required to do the collision detection. However...
The collision detection code that I wrote for CPU is not going to be efficient at all on the GPU; there's just wayyy to much branching/looping. Is there an efficient way to have particles collide with a voxel grid, on a compute shader?