top of page

Procedural Terrain Generation

  • Writer: Sage Dupuy
    Sage Dupuy
  • Jun 14, 2020
  • 5 min read

I learned how to do terrain generation and it's so cool! Through this small post you can see how it works and view some interesting biomes more in depth than the short video. Though if you don't care about how it works and just wanna see some cool visuals you can head out after this video.

Now that we have that out of the way let's get into how it's done. We'll start with something called a noise map. You know, just like how when a TV get's static and it's all grainy and black and white.

ree

Now if we put that onto a 3D model, or mesh as I'll be referring to it, it would look horrifying...

ree

That, looks like the most effective sonic spike trap ever! So now that we know that doesn't work let's talk about Perlin Noise. Perlin Noise works by having each value be affected by the value before it. So each new value can't be too far off of the value that it just generated. Now this by itself isn't too powerful, though can be used very effectively where it was originally invented for. So in order to make a system that allows vast variability and customization we'll introduce octaves. Octaves is basically determining how much detail you want your Perlin Noise to have. AKA how many runs of Perlin Noise should be overlayed onto the previous one. Since each run will continue to be adding more detail the higher the octave number the more detailed and specific it'll be. Let's take a look with different octave values.

ree

This image shows octave values starting at 1 on the left and going to 4 on the right. As you can see there's a lot more detail the higher up the value is. Let's put this on a mesh and see how it looks, to see if we're closer to what we're looking for.

ree

Well that looks a little more terrain like, but there's definitely a bit too much movement still. Well here's where I come clean. In the previous image that showed the octaves, I messed with another value called scale. Now it seems pretty obvious what it does, it scales the noise. I had to increase the value of the scale to 10 because otherwise you would never actually see the detail the octaves were introducing, it'd just be too small to see on a single pixel. To sum it up scale allows us to directly control the distance that we're viewing the noise map from. Now that we can mess with that value again let's set the scale to 100 and see what it looks like.

ree

That looks a lot better and very much like real terrain. Let's dig just a little deeper and talk about persistence and lacunarity. For every single one of the images above the persistence level has been 0.5. What that determines is how much is each pixel affected by each new layer of noise. So with a value of 0.5 it's kind of in the middle. If the value was 0 it has to exactly match the next layer of noise, which is sometimes you want if your octave value is high enough to still create detail. Now if it was 1 it doesn't need to match it at all so it can go all crazy. The last value we can directly mess with is lacunarity. This value determines how much detail should be added to the areas of the places that are similar. So if it's at 6 that means it'll add 6 times the amount of detail in the octave layer that it's set to. So let's put this all together and see what it looks like. With a scale of 100, an octave value of 6, a persistence value of 0.3 and lacunarity value of 3.

ree

Doesn't look half bad now. Now there's one more thing that we need to look at before we move on to the colors and textures. This is something that's more possible thanks to Unity's tools. With something called an Animation Curve we can evaluate the numbers on the mesh and increase their value base on where they fall on that curve. This is how we're able to get those spikes in Needle Valley. Here's what the Animation Curve looks like for that biome.

ree

When a value of 1 is passed into the animation curve for evaluation before it's mapped to the mesh. It more or less isn't affected, but when that gets basically any higher it'll sky rocket in height all the way up to 2.45. Also with this Animation Curve we can set what height the water should be. If we make the curve completely flat where we want to water to be it'll clamp any value lower than it to be the same. With this knowledge, now we can start to make a very funky looking terrain biome.

ree

Looks funky and layered, it looks Funkly. That's what we'll call this biome, Funkly. Well now that we have our biome we can start to choose where we want our textures or colors to be. I'm gonna skip over this part a bit because it's really just a lot of math. If we want to add some color onto the biome, the simplest way is just to put it on where ever a specific height is. So if we want the higher parts to be yellow we just tell the mesh to color the places that are higher than 1 as yellow. Then we can just add multiple colors and textures using MATH.

ree

That looks... great. Well now that have a pretty realistic looking terrain system. Making new types of terrain is as easy as copying some values and then just tweaking them until it looks nice.

I hope through out this process of explanation you were able to somewhat grasp something about terrain generation if you didn't know anything. To those that know terrain generation I hope you at least understood all of my ramblings. This is an extremely fun project to work on and I highly recommend anyone that is a programmer that hasn't tackled this to at least mess around with it. I'm currently in the process of allowing user editing of the terrain to make it available for you to download on the playtest page. Look forward to that in the future and if you'd like to know more about Perlin noise or terrain generation here are some more resources for you.


Perlin Noise in depth explanation:


Simple pure perlin noise terrain generation (This is what I started with):


The full tutorial I followed for more instruction and detailed explinations:

 
 
 

Comments


bottom of page