Posted March 08, 2023 by MianenCZ
Procedurally generated terrain is must-have if I want to claim that the majority of content is procedurally generated. Here we are making the first step toward that goal, and also it was my homework. Now I present to you, how I proceeded.
My assignment was to create a noise-based terrain generator and biomes, where each biome has different parameters. Originally I was supposed to work on provided Minecraft project, but I struggled with Java therefore I’ve eventually returned to Unity.
First, I needed to create basic terrain with fixed parameters. From the task, I was recommended to use Perlin noise, which is embedded in the Unity Mathf library. Then I applied it to Unity mesh. That was nothing new to me. The only thing that was a bit hard, was scaling properly the output mesh 4 times to get a larger space with the same computation cost. I struggled with vector transformations.
The results were not good enough. Therefore, the next step was to smooth it out. I applied octaves. They are additional layers of Perlin noises that are decreasing in amplitude (value) and increasing in frequency. Also to get a further variance, an extremely large random number is generated to offset each octave. The result of this process is a smooth texture as you can see in the image up top.
Octave math comes something like this:
for (int o = 0; o < settings.Octaves; o++)
{
var perlin = Mathf.PerlinNoise(
frequency * x + settings.OctaveOffsets[o].x,
frequency * y + settings.OctaveOffsets[o].y
);
height += amplitude * perlin;
amplitude *= settings.Persistance;
frequency *= settings.Lacunarity;
}
To achieve universality, I needed to scale the result to receive a value from 0 to 1 at the end.
Also, all scalings, offsets, and multiplications had to be parametrized to be changed dynamically later.
Noice settings contained:
I prepared noise generation and now I need to create biomes. You can see them in the image up top as terrain color, but I will get more deeply into that topic in the next post.
Thank you for reading and if you want, buy me a coffee.