Follow

The function below uses Perlin noise octaves to calculate the height of a vertex based on its coordinates and the number of octaves to be applied. It is a slightly modified version of the original code introduced on TTG’s generation step 3. The values of the base frequency, persistence and lacunarity are constant for demonstration purposes.

static float GetHeight(float x, float y, uint octaves, Vector2[] offsets)
{
float height = 0;
var amplitude = 1f;
var frequency = 0.055f;
const float persistence = 0.5f;
const float lacunarity = 2.5f;
for (var i = 0; i < octaves; i++)
{
var offset = offsets[i];
var filterX = x * frequency + offset.x;
var filterY = y * frequency + offset.y;
var noise = Mathf.PerlinNoise(filterX, filterY);
height += amplitude * noise;
frequency *= lacunarity;
amplitude *= persistence;
}

return height;
}

A fairly similar function is used in TTG’s code, with parameterized values instead of hard-coded ones.

The outcome

The GIF below displays the usage of Perlin noise octaves, with four terrains: the terrain we’ve been using as an example in this section, and three other ones; each one with an increasing number of Perlin noise octaves, from 1 to 3 (check the left bottom corner of the image for octave count). All terrains were generated with a persistence of 0.375 and a lacunarity of 2.52.

The value of the octaves is clear: they add detail without changing the scale of the terrain, delivering a more natural-looking outcome. That’s exactly what we were looking for.

Perlin noise octaves are a simple, yet quite satisfactory solution for adding more detail to terraced terrains. This feature shipped as part of TTG 1.2.0, where both the API and the helper component were updated to support Perlin noise octaves. On the next release, I plan to add added (2.0.0) spheres as a basic terrain shape, allowing terraced planets to be created using TTG.

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.