Procedural Asteroids – Part 1

Procedural Asteroids – Part 1

Recently i started working on a spacegame. One of the goals is to create as much as possible procedurally, so an unlimited number of different universes can be created. In the end, the player should only set a seed, and then the whole game world will be created based upon this number.

I can move through epic, endless space!
… too bad there isn’t anything to visit…

After creating a simple playership (it’s a visually stunning shipmodel, simple and elegant: a cube) with smooth movement and rudimentary physics, i was in need of objects to fill the scene with.
Before giving planets a try (not just spheres, but actual, real size planets you can land on), i first began working on procedural asteroids. Below is a shot of my very first try and the current state. The whole thing took me two days.

firstAndCurrent

A (more or less) step by step guide

The first thing to do is creating a cube. We won’t use a sphere, as we want to make use of (useable) texcoords and a tileable texture. A cube is the simplest form to achieve that.
After we have our cube, we subdivide it, so we can spherify it in the next step. A very simple subdivision algorithm is used, which just quadruples each face and does not do any smoothing (in comparision to Catmull Clark for example). This way we have total control of the result and can create both spikey and smooth asteroids instead of just smooth asteroids. This is especially important for the later steps (generating LOD meshes, asteroid-blueprints, etc).

subdividesubdivCube

Next, the cube is spherified by using the cube’s normals (which are the normalized vertex positions) as vertex positions. The resulting vertices are then scaled by a radius.

cubeToSphere

Alright, now that we have a spherified cube, it’s time to transform it into an asteroid. We do this by simply adding noise to each vertex. Again, we are using the vertex normals to make sure we are pushing the vertices in the right direction. In this example, Simplex Noise was used.

noiseSphere

This step is optional: We can now smoothen our resulting mesh, which can be used to create different forms of asteroids (blocky, spikey, potato…y) and fine-tune the result. The basic algorithm for the smoothing is quite simple:

sphereSmooth

Now that we have our basic asteroid, it’s time to make it look good. Apart from using normalmaps we can also make use of vertex ambient occlusion which will give the asteroid more “depth”. I won’t go into detail here on how to create AO, but you can have a look here, here and here for some code samples.

ao1

Ugh, that doesn’t look too good: Thats because the AO is very low resolution/per vertex (and we don’t have much vertices). We can use a cheap trick in the asteroidshader though, to give it some additional detail.

ao2

The picture above does not look like it, but you can now create some pretty asteroids already. Just subdivide the cube a bit more in the beginning, throw in a normal- and diffusemap und you get results like the ones below.

In the next part we will have a look at how to create more interesting shapes as well as level of detail (LOD) meshes.

example2example3example_allexample_lighting