Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Drawing millions cubes

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2011
    Posts
    4

    Drawing millions cubes

    Hi,

    I'm looking for the best way to render several millions of cubes. I have for example 2millions cubes, differents sizes but all aligned in the same way.

    My solutions for now is:
    - Compute normal vectors for each face (front, back, top, etc..).
    - Loading all data in 6 VAO/VBOs, one by face (one for each front face of all cubes, one for each back face, etc...). For each cube, I load 4vertices (3float per vertex) in each VBO.
    - Drawing each VBO with
    Code :
    glDrawArrays(GL_QUADS, 0, 4*nbCubes);
    . My normal for this face is set before as a uniform in my vertex shader.


    Is there a better way to do that?
    I tried to use one VBO with only 8vertices (instead of 6*4=24 in my solution) and using glDrawElements but I can't store indices for each cube. And millions calls to glDrawElements doesn't seem good.
    I have already increased my number of VBOs in order to get VBO of 4Mb.

    What techniques can I use if I can't load everything in the GPU?

    Thanks.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    941

    Re: Drawing millions cubes

    Use geometry instancing so that you have to store only a single cube's geometry and just use another buffer to store the transformation matrices. See ARB_draw_instanced and ARB_instanced_arrays.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Oct 2009
    Posts
    595

    Re: Drawing millions cubes

    I wonder what purpose these "million cubes" and "million spheres" projects serve. These topics regularly spring up. A GL fetish maybe?

  4. #4
    Junior Member Regular Contributor tksuoran's Avatar
    Join Date
    Mar 2008
    Location
    United Kingdom
    Posts
    200

    Re: Drawing millions cubes

    Quote Originally Posted by ugluk
    I wonder what purpose these "million cubes" and "million spheres" projects serve. These topics regularly spring up. A GL fetish maybe?
    Million cubes often translates to "minecraft". For minecraft like rendering: Don't forget to skip all cubes which have opaque blocks on all sides. For typical maps this reduces millions to thousands.

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Feb 2006
    Location
    Sweden
    Posts
    748

    Re: Drawing millions cubes

    i wrote this for just such an occasion
    http://www.flashbang.se/archives/315

  6. #6
    Junior Member Newbie
    Join Date
    Oct 2011
    Posts
    4

    Re: Drawing millions cubes

    Thanks for the replies.
    My context is not a "minecraft" like project. It's for a scientific visualization software. I don't have a 3D grid so I can't skip cubes with opaque blocks on all sides. I just have a set of *cuboid* (height, width, depth can be different) with different sizes.

    I am not sure if geometry instancing is usable in this case (different sizes).
    Thanks zeoverlord for your link. Geometry shader seems to be a good idea. I tried with a VBO loaded with for each cuboid its center location and its size (h, w, d), and drawn with GL_POINTS. The vertex shader just transfers these data and the geometry shader generates the associated triangle strip. I just have to figure out how to set normals properly.

  7. #7
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    941

    Re: Drawing millions cubes

    Geometry instancing is usable also in case if you have different sizes for the height, weight, depth, just you have to include the scaling in the model transform matrices of the instances.

    Geometry shader based solution can be as good as well, except that it may be slightly slower due to the additional geometry shader stage. If you can use it, you can accelerate things a bit by using an instanced geometry shader with 6 invocations so that you can emit the sides of the cuboid in parallel.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  8. #8
    Junior Member Newbie
    Join Date
    Oct 2011
    Posts
    4

    Re: Drawing millions cubes

    Thanks a lot agnuep!
    I tried geometry instancing with uniform buffer objects and it's a lot better!
    I have to implement some culling techniques now. Is there a best solution?

    And just to know, what do you mean by "instanced geometry shader with 6 invocations"? Any link about that?

    Thanks again!

  9. #9
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    941

    Re: Drawing millions cubes

    What I suggest is to do view frustum culling with a geometry shader .

    About instanced geometry shaders, you may check out the GL4 spec or the ARB_gpu_shader5 extension.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  10. #10
    Junior Member Newbie
    Join Date
    Oct 2011
    Posts
    1

    Re: Drawing millions cubes

    And if someone was to render like 20 million cubes, but all of them are of identical size and the only difference would be colour (2 variants)? They would all be fitted in a 3D grid, side by side. The PC I will be working with might have an integrated graphics card. The display wouldn't have to be refreshed too often. New cubes will appear rarely in the grid filling it very slowly and some of old, existing ones will be removed from time to time.

    What would be the best solution for this? The first thing I thought about was display list but I also heard about VBOs and FBOs.

    I'm trying to render something like this: http://www.leokrut.com/leocrystal7.gif

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •