For Izle I wanted to create a procedural world that could be entirely destroyed. I used voxels to create islands of different size, populated with AIs, props, and secrets.
Note: most of the screenshots on this page are taken directly from the Unity Editor, and do not use the in-game lighting, fog, camera lens effect, and environmental fx from Izle. As a result they can seem flat and technical. That’s normal!
It works like this:
The world is split into chunks, sections and voxels (exactly like in Minecraft)
Voxels are filled with grass, dirt, ice, etc. with varying levels of fill to create smooth surfaces
Marching Cubes algorithm is used to generate a 3D mesh from the voxel structure
Generated 3D meshes can have physics and multiple materials
A list of surface voxels with their neighbour is built for custom pathfinding
All surface voxels have additional mini props like blades of grass or pebbles
Light is propagated from the sky and result is passed per-vertex to the terrain shader
Props are added on the surface, trees, AIs, chests, rocks, etc.
When an island is built next to another island a bridge is generated between them
Other features:
Caves inside the island can be added with a random path to the surface
Textures can be used to add vertical terrain to create layered hills or maze walls
Textures can be used to remove land and create an island broken into pieces
Final result with debug information shown for one section:
Finding the right mathematical functions and noises to generate the island can be quite difficult:
We need a noise for the edge of the island to avoid having a dull cone shape
We need another noise for the surface elevation, in the example above I went for a slow perlin noise to simulate rolling hills
And we need a third noise for the rocky surface for the parts below made of dirt
Some other islands use additional noise to add or remove terrain, create rocky soil, etc.
Tools
I created a series of tool inside the Unity Editor to test and debug the voxel engine. This allowed me to generate any type of island, and build on them. It generates everything from the terrain to the props, lighting, pathfinding and AIs.
This is very useful to test atomic functions, stress test the engine, and inspect voxels to make sure everything is going according to plan.
Modifying The Terrain
When the terrain is modified, meshes are re-generated and light is re-propagated. All happening in less than 1ms! This is why the world needs to be split into chunks and sections, so that we only re-generate very small parts of the world, hopefully just one section or two.
Part of the mesh generation and light propagation algorithms can be multi-threaded and streamed over a few frames if needed. Which is something I do when entire islands made of millions of voxels are generated in real-time.
Light
The light propagation model I used is quite simple. Light comes vertically from the sky and tries to propagate to neighbouring voxels, slowly losing intensity.
The complicated part is when we modify the terrain in real-time because we cannot re-propagate the light of every voxel, it would be too costly. We need to decide on which sections (and voxels) to re-compute the light, and this can be a bit tricky because in the worst case just a small hole into a roof can bring light into large areas.
The per-voxel light information is then stored per-vertex in the generated mesh and used by the terrain shader to lighten and darken areas.
Castle Creative Process
To finish this article I wanted to share some bits from the creative process to make the Castle Island.
Voxel Engine Programming - Alexis Bacot
3D Art - Robert Heng & Reynald Bayeux
2015