Destructible Voxel Terrain

For my Computer Graphics II course, I chose to do a project on rendering voxels. I created two demos showing some of the ways that voxels can be rendered. This demo uses the marching cubes algorithm, which creates a triangle mesh from voxel data.

Features

This demo allows the user to fly around a terrain. Clicking the mouse will create a hole in the terrain where the user is aiming. The terrain can be reset, removing all the holes, and wireframe mode can be toggled on and off.

Implementation (C++/DirectX)

First, a heightmap is generated using the diamond-square algorithm. The heightmap is used to fill a three dimensional array representing the world. A different value is used for voxels that are near the surface of the terrain, so that they can be rendered with a grass texture. Next, meshes are generated from the voxel data using the marching cubes algorithm. It would be costly to recalculate a mesh for the entire terrain whenever it is modified, so the terrain is split into chunks, and a separate mesh is calculated for each chunk. Therefore, it is only necessary to recalculate the chunks that have been modified when part of the terrain is destroyed. The terrain is textured using a planar projection along each of the three axis, weighted with the polygon normal. Lastly, fog is added to show depth.

Media