Hey everyone, I´m currently working on a project: a milling machine simulator. To make material to be able to continuously being “cut”, I made a cube made of thousands of other cubes, so when the “cutting object” touches a small cube it will be destroyed. The main problem is that I have around 24k cubes so the performance is affected.
I already made some changes that really help, like:
Batching, reduce like 20k batches to 73
Disable all kinds of shadows
Mark as Static all objects that don´t move.
Occlusion seems to not really helping because all the cubes are literally in the camera´s point of view. (Or if anyone knows a good setup with this will be helpful).
The cubes materials are GPU instancing
After all this, it goes around 25-30 fps but when the table is moving it drops to 10-15 fps.
Somebody knows how can i increase the performance?
I also see that the physics get really overwhelm, only have 1 rigidbody the rest is just meshes.
I would recommend just using one mesh with a ton of vertices, then displacing those in the vertex shader. Similar to how it is done for snow on terrain in many games. Another option would be to do 2D polygon cutting using some kind of library like Clipper : Clipper2 - Polygon Clipping and Offsetting Library
Either of these would probably offer better performance.
If you are limited by the amount of geometry then perhaps think about dynamic subdivision (quadtree style) of the block where the drill bit is. Then only the region around the bit needs to be fully divided to the smallest grain size.
Also, as the bit cannot get to the bottom without cutting through the top, the subdivision can be done layer by layer.
not using colliders, but manually check if drill is inside 3d grid cell (since your blocks are not moving anyway)
have many tall cubes (for each position, instead of having many cubes on top of each other) and then make them shorter on hit (this might even work with colliders)
if the cutter doesn’t rotate, then basically all you need is a heightmap that you modify (make it lower based on drill tip)
use high resolution mesh cube, move vertices down based on drill tip (can try manually looping closest vertices to move, or use shader, or rendertexture, similar to heightmap)
voxel/marching cubes mesh (this might be best looking)