Optimizing All the Voxels
One of the difficulties in working with voxels is that the number the of triangles to render quickly gets out of hand - Adding each voxel to the scene will inevitably kill the engine's performance. Until now, the solution to this for ExtraGalactic was to export the voxel model to an Object file, then load that file instead. When access to an individual voxel is needed, I simply swap out the mesh for the individual voxels, and do what needs done. This works well enough, but the method has a couple of issues -
* We are now loading two files for each model, the optimized object file, and the original voxel model. In addition, we have to glue them together with script, which requires some manual setup as well.
* Voxel manipulation is often a one-way trip: We can't remove a chunk of our model, and swap back to the mesh: The mesh will not be updated with the new information.
* The object file uses a texture and UV map to render the colors. Since voxels in ExtraGalactic are not textured, this voxel-texture is actually the color palette rendered as a 1x256 pixel image. We would be better off using vertex-colors instead.
* The object file does not allow us to take advantage of special material properties the voxel modelling software provides - Tranparency, shininess, light emissions.
The solution to all these issues is not simple - it means writing my own model importer for Unity3D that produces a model asset that allows all of the above. Loading the voxel data is not difficult - the .vox file format is well documented, and alternatively, the .gox format is relatively easy to reverse-engineer (I have not found documentation on it). Once the voxel data is in, the next step is a tricky one. We need to produce a coherent mesh with the least possible triangles without giving up on performance (Remember, we want to be able to swap the mesh/voxels back and forth with minimal performance impact). To produce such a mesh, a technique known as "Greedy Voxel Meshing" seems to be the best fit, and as a learning exercise, I've written a small JavaScript implementation to demonstrate its function.
You can find it here:
https://armen138.github.io/greedy_quads/
(hitting space will replace the "voxels" by a set of quads, significantly reducing the number of edges (and thus triangles, when rendered in 3D).
I'm not quite done figuring this out and translating it back to Unity3Disms, so more updates on this will follow.
ExtraGalactic
A Silly Little Space Rescue Mission
More posts
- A quick gameplay updateAug 28, 2018
- Voxels Getting GreedyAug 05, 2018
- A little galaxy with a nameJul 16, 2018
Leave a comment
Log in with itch.io to leave a comment.