I decided to spend this week working on a voxel based terrain system.
After some brief research I settled on implementing the dual contouring algorithm.
I generated my voxel data using 3D perlin noise and ran it through the algorithm:
It looks like triangle soup from the exterior, but that’s only because we don’t render back facing triangles. Once inside things look a lot better:
There’s still an issue with the lighting because I’m not generating any vertex normals yet.
A heightmap can be trivially converted to voxel data by setting voxels above the generated height to air and below to solid:
I’ve used a triplanar texture mapping shader to apply a basic rock texture across the terrain. It looks like there are a few problems around flat areas.
I’ve drawn the following conclusions from this concept:
1. Generating the mesh is relatively simple.
2. Optimizing the mesh for the game is a little bit harder. I’ll probably need to use a Sparse Voxel Octree (SVO) or Sparse Voxel Direct Acyclic Graph (SVDAG). This will allow me to support a LOD system.
3. Changing the data in real time is harder still. You need to efficiently change the data, re-generate the mesh and re-upload to the GPU. Quite a lot of demos found on YouTube exhibit a clear stall when the terrain is modified.
4. Most fast implementations are using some combination of CPU and GPU.
5. There’s a big performance difference between naive and optimised implementations.
To be usable in a project I would need to:
1. Generate a large enough, interesting terrain to represent the play area.
2. Apply multiple materials to the mesh (e.g. dirt ground, rock cliffs, sandy beaches)
Special thanks to: