Render big amounts of box geometries with instanced mesh

I need to render big amount of simple static BoxGeometries, positions of geometries are parsed from local file, every line represents block area id(something like chunk id), position and scale (width, height, depth).
the problem is amount of data - some files are really huge, gigabytes of data(which is millions and tens millions of records).
I use InstancedMesh to render all this BoxGeometries in my scene, render on demand, also i “join” the BoxGeometries as different InstancedMeshes, so amount of instanced meshes is equal to amount of block areas (i do that because i assume that frustum culling doesnt work for individual geometries in instanced mesh, so at least i dont render some instanced mesh(block areas) outside of frustum), but still i believe there is room for performance optimisation.
i dont use any textures, just MeshBasicMaterial, also as i need to color different blocks based on some conditions. i do that with instanceColor and updating this attribute (which is better that using texture atlas with shaders, i tried).
The main issue is obviously performance and the questions i want to ask:

  1. is using BatchedMesh instead of Instanced can help?
  2. Is using bvh can help?
  3. is it possible to apply frustum culling for InstancedMesh so I render all the blocks as one InstancedMeh with only 1 draw call and dont render any instanced mesh geometries that are out of frustum? I believe i did see some examples utilizing bvh to sort geometries and set visibility to false for those that out of camera frustum but i couldnt make it work for my case.
  4. Is there occlusion culling for instanced mesh implementation example? Is it real to achieve?
  5. In my chrome dev tools rendering tab says that i use from 3 to 12 mb of gpu memory which is kinda weird, other three examples use more gpu memory. chrome hardware acceleration is on.when i disable hardware acceleration and things gets even worse, it takes like 10-15 seconds to apply any changes to the scene.is there any way of utilizing more gpu memory to increase performance? (my work station uses GeForce GT 710 with 16GB of RAM). i did test my app on other pc’s with more efficient cpu and performance is much better (~110 fps for 800k records in file, when i get 75 max with 100-200k records file)
  6. Is there any way of back face culling for this box geometries? Is it worth it?
  7. I’m looking into level of details, because i can not decrease amount of polygons of basic BoxGeometry(1, 1, 1) can i instead render some boxes as points/2d figures on distance?
  8. Is it possible to move some render tasks/computing to gpu with shaders and will it help with performance (im not familiar with shaders yet)

Any help/ideas/examples will be appreciated

Hi, I’ve written a library that you might find useful:

Example with 1 milion boxes:

4 Likes
  1. Doubt it.
  2. Possibly… but probably isn’t a drop-in replacement.
  3. No, not without including some other library on top… see #2
  4. no.
  5. I don’t think so. It’s using as much gpu as it can.
  6. They should be backface culled by default unless you’ve changed the default .side on the material
  7. Yeah that’s possible.
  8. Yes… but it’s Very non-trivial.
2 Likes

Big thanks, I did see your library and example looks impressive, but I couldn’t make it work for my app. I’ll try again:)

1 Like

No, I didn’t change any .side settings, didn’t know geometry is back face culled by default, thanks!

1 Like

If you need support there is the discord server linked in the readme.

1 Like