Photo by Gabriele Domicolo on Unsplash
Voxel terrain is a popular way to represent 3D geometry in games and simulations. However, voxel terrain can look blocky and unrealistic. In this post, I will describe an algorithm for smoothing voxel terrain to make it look more organic and less blocky.
This post doesn't describe how to generate or store voxels, but rather how to convert them into a mesh and then smooth the geometry.
Step 1: Convert voxels to mesh
Once you have your voxels in some data structure, you can convert them into a mesh. This can be done by iterating through all the voxels and adding a quad for each boundary between two voxels whenever on one side of the boundary there is air and on the other side there is solid material.
The result could look like this:
Step 2: Smooth the geometry
To smooth the geometry, you can use a simple algorithm that iterates through all the vertices, and moves each one of them towards the average of their neighbors. This will make the geometry look more organic and less blocky.
You could fine-tune the algorithm by taking a weighted average of the original vertex position and the average of the neighbors, and by adjusting the weights so that the smoothing looks good with your particular geometry.
Step 3: Apply Catmull-Clark subdivision
Finally, to further smooth the geometry, we can apply a subdivision algorithm such as Catmull-Clark. This algorithm will subdivide each face into smaller faces, and move the vertices towards the average of their neighbors. This will make the geometry even smoother and more organic.