Search Unity

Displaying very large numbers of static cubes?

Discussion in 'General Graphics' started by BillySV, Jan 18, 2020.

  1. BillySV

    BillySV

    Joined:
    Jan 18, 2020
    Posts:
    1
    (looking for general advice/ to be pointed towards reading or methods. I don't expect anyone to spoon feed / solve this for me)

    I'm currently experimenting with displaying larger numbers of static cubes in a low poly Civilization simulator.
    individual buildings are represented simple cubes. each transformed to have different widths and heights in a procedural manor.

    I'd like to have as many on screen at a time as possible. right now in having individual cubes instantiated as objects I'm limited to about 50,000 on screen at a time before serious frame drops kick in.

    I recently came across the particle system which seems to be able to handle millions of 3D modles on screen at a time. this tells me holding each cube as a game object probably isnt the best way to go.

    can anyone point me in the direction of method/s for handling very large numbers of permanent static 3D models on screen? any ideas are much appreciated.
     
  2. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    401
    What is your target hardware please? This would probably determine the optimal approach. Probably packing all of the cubes into a single mesh would help on most platforms.
     
  3. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Instancing is one option, if they’re dynamic meshes this is absolutely the fastest option.

    If they’re static then the best option is to merge them into single big meshes, like @jamespaterson recommended. 50k cubes is 1.2 million vertices if you just merge them together. Unity traditionally only supports up to 65536 vertices per mesh, and Unity’s built in Mesh.CombineMeshes() utility may still be limited to that. Since Unity’s built in cube mesh has 24 vertices, that’s roughly 2700 cubes per mesh. So for 50k static cube buildings you’d need at least 19 meshes, grouped either by area or material. You might also want to go with a custom “cube” that has no bottom face to remove 4 of those vertices, which would mean 3200 cubes per mesh. Depending on your setup, limiting the meshes you merge by an area roughly half the size of the area you can see at one time, even if that means more merged meshes, may be better than fewer if you can’t ever see all of the buildings at once since then the GPU isn’t rendering all of the cubes all of the time.

    If at any time during gameplay you need to be able to add or remove individual buildings, then this won’t work, and you’ll want to look into instancing.