Results 1 to 4 of 4

Thread: Draw many spheres

  1. #1
    Junior Member
    Join Date
    Nov 2010

    Draw many spheres


    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?


  2. #2
    Senior Member
    Join Date
    May 2010

    Re: Draw many spheres

    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.

  3. #3

    Re: Draw many spheres

    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.

  4. #4
    Senior Member
    Join Date
    May 2010

    Re: Draw many spheres

    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.

Similar Threads

  1. draw 3D cube
    By gandrakar in forum OpenGL ES general technical discussions
    Replies: 1
    Last Post: 06-14-2010, 02:02 AM
  2. How to draw a disk
    By Cumore in forum OpenGL ES general technical discussions
    Replies: 1
    Last Post: 12-17-2007, 11:50 PM
  3. how to draw a polyhedron
    By netsolv in forum OpenGL ES general technical discussions
    Replies: 0
    Last Post: 01-26-2005, 02:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean