Draw many spheres

Hi,

I’m trying to generate >1Mill sphere using opengl, it is not working for now. I saw on some website people using Opencl in order to make the visualization faster. Could someone help me with the code i should write in opencl to make it work?

Thanks

I doubt that OpenCL would help. The bottleneck is likely to be between the CPU and the GPU.

The way to get more performance when drawing something like this is to improve the ‘batching’. Every draw call you make takes a ton of time - so if you can group your spheres into larger chunks of data that you can draw in one go - everything will be dramatically faster.

If you are making a million calls to the low level draw function - then that’s WAY too many.

It’s generally a good idea to aim to draw no more than 1000 meshes per frame if you want interactive rates. So you probably need to figure out a way to group tens - and preferably hundreds or even thousands of spheres into single meshes.

Also, obviously, try to use as few vertices as possible for each sphere. You might want to consider using fewer triangles in spheres that are a long way from the camera.

You could have a look at NVIDIAS oclParticles examples. They use some shader tricks to make points look like spheres. This method can render very large number of sphere-like objects in a single draw call, which, as SteveBaker pointed out, is good for performance.

Yeah - that’s true. If your spheres are boringly uniform in color (or even if they aren’t - providing you’re good at writing clever shader code!), you can draw a single polygon in a plane parallel to the screen with a just a 2D picture of a sphere on it…and it’ll look just like the real deal. With clever shader tricks, you can adjust the depth output of the fragment shader and get your fake spheres to intersect each other nicely.

That gets you down to one triangle per sphere - which is pretty lean! But you still have to batch them up because a million single triangle meshes take about the same amount of time to draw as a million 256 triangle meshes. That’s because the cost on the CPU side to setup to draw a mesh exceeds the the time it takes to transmit it to the GPU and draw it…unless the mesh has at least 256 vertices. Drawing less than 256 verts per mesh doesn’t save you a darned thing because the GPU just ends up waiting around for the CPU to give it the next thing to work on.

So reducing the number of triangles per mesh doesn’t help below about 256 verts. Once you hit that point, the only way to draw faster is to draw more than one sphere per mesh.