Asteroid Generation

Posted by Adam on 3 January 2022 at 12:23 pm

Something I usually do is have an idea and commit to creating a full product for it. The ideas don't stop coming though, and when you commit all your time to one idea, there's an opportunity cost in not being able to work on other ideas. While regaining my game development knowledge following my two and a half year hiatus, rather than lock myself into a game, I'm going to spend it creating proofs of concepts instead. When I have an idea, I'll strip it down to the bare concept, and build it, write about it, and then continue on.

Today's post is about an idea I had for randomly generated asteroids. I have an idea for a whole space-based roguelike, but for now that'll remain just a potential game, and instead, I've plucked one aspect of it out.

Sebastian Lague has a great video series on planet generation and it seemed to me that I could adopt some of that to work for asteroids. There wouldn't need to be any height-based terrain colouring or custom shaders, but his idea of using a cube and setting the vertices to normalised vectors to create a sphere, and then applying noise over this was really smart.

I did something similar, and while not perfect (the seems are visible at lower resolution), I was able to create an asteroid class that generates random asteroids with varying levels of resolution and shape. At a resolution of 4, that's 9 quads per side, or 108 triangles per asteroid, which gives quite a blocky look.

Randomly generated asteroid with a resolution of 4

At a resolution of 8, you have 49 quads per side, or 588 triangles in total.

Randomly generated asteroid with a resolution of 8

At a resolution of 16, you have 225 quads per side, or 2,700 triangles in total.

Randomly generated asteroid with a resolution of 16

At a resolution of 32, you have 961 quads per side, or 11,532 triangles in total.

Randomly generated asteroid with a resolution of 32

At a resolution of 64, you have 3,969 quads per side, or 47,628 triangles in total.

Randomly generated asteroid with a resolution of 64

At a resolution of 128, you have 16,129 quads per side, or 193,548 triangles in total.

Randomly generated asteroid with a resolution of 128

At a resolution of 256, you have 65,025 quads per side, or 780,300 triangles in total.

Randomly generated asteroid with a resolution of 256

Personally, I quite like the look of the 8 and 16 resolutions, for that low fidelity look. Here are a few other examples using a resolution of 8. The first example has the same settings as the above asteroid, but with a different random seed for the generator.

Randomly generated asteroid with a resolution of 8 using a different seed

Using a set of three separate layers of noise generation, it's possible to generate asteroids that look quite different, like the following which is at a resolution of 8 still, but with different roughness settings.

Randomly generated asteroid with a resolution of 8 using different settings

There are more things which could be done to enhance the asteroids. Of course, there's no post processing on these, but also the lighting could be improved, there could be some ambient occlusion to make the deeper recessing darker, for example. Perhaps I'll revisit this at a later date with enhance lighting.