Procedural Planet Generation

Recently I have developed a technique to generate random planets, with the plan to use the generated planets in a game I am developing in Unity. The generated planets look like this:

Random Planets

These planets are created by first generating a random  spherical mesh. This is done by choosing a start position, then creating a set number of vertices around this start point at any given radius. To randomize the position of each vertex in a way to avoid overlap with neighboring vertices, the vertices are moved a random amount on the line that represents its direction from the start point. So essentially, they are either moved randomly closer or further from the start point. Once the vertices are in place they can be used to create a mesh. However I found only having one set of vertices from the center point to the radius of the planet created problems later when I was trying to use a shader to fade towards the edge. To create a mesh that I could work with more easily in a shader I repeated the first process many times, creating sub layers within the mesh that connected to each other.

Generated Mesh

UV’s for the mesh could be calculated fairly simply by comparing the vertices position to the start position. To generate the texture used on the planets I came up with a technique that makes use of Cellular Automata. The idea is to generate multiple layers of the texture, that only consisted of two colors on each layer.¬†I devised two different Cellular Automatons rule sets that would be used. The first would try and create small isolated sections of the layer color on the texture, then switch to the second rule set that would try and grow these isolated blobs outwards. To create more diverse layers the rules were randomized in several ways, for example the number of cycles before switching rule sets is randomized, as well as the actual rules that affect how cells die and live. An example of what an individual layer looks like can be seen in the picture below:

Texture Layers

To combine the layers into one texture, each layer is added incrementally, averaging the color of each pixel in its texture with the value of the corresponding pixel already on the combined texture. The result of combining 4 layers (which is the amount used in the picture at the top of this blog) looks like the following:

Combined Texture

To create the fade effect a simple shader is used to blend the texture with the polygons color alpha, which gives the final result.

Final Result

I feel the results so far are pretty good but there is still a bit of work I would like to try and do, for example experimenting with ways to make the edge of the asteroid more apparent and possibly finding a better technique for the fade to edge that is already in place.