In our post about generating terrain, we talked about how the terrain within each cave will be generated procedurally. The same concepts apply to actually creating the caves as well.
The way we do this is using an algorithm called “Perlin Noise.” Perlin Noise is pseudo-random, and as such has two important features that we use:
1) one seed will create the one result: so no matter how many times you re-generate, as long as you use the same number to start, the result will be the same. That means that if we want to create a huge length of cave and can only do so in pieces, the pieces will fit together.
2) Perlin Noise can generate noise infinitely, in every direction, forever. If we want to, we can extend our cave system in any direction we want, and each cave will still be new.
So the way we actually create the caves is by following this guy’s suggestions. To paraphrase, we start with a solid cube of many many voxels. From there, we run it through a Perlin Noise filter, getting something awkard like the image on the left.
Next, those awkward lumps get subtracted from the solid, so you get something that looks like the image on the right: a solid area riddled with caves and things you can explore. As a note, he has added hills and such on the top of this area – we don’t do that because the player spends his/her time inside the caves.
So above are images from the walkthrough (seriously, check it out – he covers it really well), and below are some of our own results, as shown from inside the caves.
From here, we’ll be able to manually
modify the caves so they work better for our puzzles, and then we will apply the smoothing algorithms, then the same noise algorithms to the surfaces themselves to give the cave a rough, natural look.
More on that later!