Upper and Lower shapes in Perlin Noise Generated Terrain

125 Views Asked by At

I am trying to learn about Perlin Noise and procedural generation. I am reading through an online tutorial about generating landscapes with noise, but I don't understand part of the author's explanation.

On this webpage under the "islands" section there is the text

Design a shape that matches what you want from islands. Use the lower shape to push the map up and the upper shape to push the map down. These shapes are functions from distance d to elevation 0-1. Set e = lower(d) + e * (upper(d) - lower(d)).

I want to do this, but I'm not sure what the author means when they're talking about upper and lower shapes.

What does the author mean by "Use the lower shape to push the map up and the upper shape to push the map down"?

1

There are 1 best solutions below

1
On BEST ANSWER

It's a little confusing because the author uses little pictographs instead of equations. Basically, we can think of a 3D container $C$ that holds the our noise landscape ($W\times H\times E$, where $E$ is the depth or elevation axis). Within this container, we have our elevation map/surface $e(x,y)$. Define $d(x,y)$ to be the distance from the center (wrt the $W$ and $H$ axes).

Now the idea is to create an island, where the boundaries are under water (high $d$) and the middle (low $d$) is on land. We will basically threshold the map elevations $e$ so that points $p\in\mathbb{R}$ are under water if $e(p)<T$. But how can we guarantee that the middle of the map is above water, while the edges are underwater? Well, we could just arbitrarily set $e(p) = T-\delta\;\forall\;p: \text{nearBoundary}(p)$, i.e. force all the positions near the boundaries to be underwater, and then also maybe add some constant to $e$ away from the boundary so at least most of it is above water. However, this (1) requires some tuning to guarantee the middle is above water and (2) the edges of the island can have many strange looking cliffs where the water will suddenly appear. Coasts are often a little lower in elevation than more inland areas. So the idea is to apply a function that pushes the elevations near the boundaries down, but the elevations near the middle up.

To do so, we define two functions, which each map distance $d$ to a real number in $[0,1]$: the lower and upper functions $L,U : \mathbb{R}\rightarrow[0,1]\subset\mathbb{R}$. We will combine these functions to create a new function that alters the elevation. We then set the new elevation to be $$ e_n(p) = L(d(p)) + e(p)[U(d(p)) - L(d(p))] $$ which is the author's e = lower(d) + e * (upper(d) - lower(d)).

What does this do? Assume $e,d\in[0,1]$. Notice when $e=0$, we get $e_n(p)=L(d(p))$ and when $e=1$, we get $e_n(p)=U(d(p))$. At each point/position $p=(x,y)$, we are interpolating between the lower and upper values for that distance, based on the existing elevation value. In other words, $L$ and $U$ control the range of new elevations $e_n$ that are possible at a given distance $d$, and you choose which value within that range to use via the original value, $e$.

For example, if $L(d)=1-d$ and $U(d)=1-d$, we get $e_n(p) = 1-d(p) $, meaning the entire elevation map becomes a hill or pyramid (depending on the metric used), and we lose our original elevation map entirely. Another example is if $L(d)=(1-d)/2$ and $U(d)=1 + d/2$, we get $e_n(p) = (1+e-d)/2 $, which is exactly what the author calls the "simplest shape", in which case $d=0$ implies $e_n\geq 1/2$ and $d=1$ implies $e_n\leq 1/2$, meaning it "guarantees the middle is on land and the edges are in water" as you can simply choose $T=1/2$. Last example: try $L=0$ and $U(d)=1-\alpha d^2$ with $\alpha\in[0,1]$. (This is basically the author's first example with the line on the bottom and the parabola on top.) Then $e_n=e(1-\alpha d^2)$. Notice that there us no threshold $T$ guaranteed to keep the middle ($d=0$) above water, because $e_n$ has actually shrunk at all positions (there is no $L$ lower bound to guarantee it stays above a particular value).

The author likes to view this is a reshaping of the container $C$. His pictographs are slices through $C$ (for some fixed $w$ or $h$ value), where height is the elevation axis. Then $d=0$ at the center of slice (where $e_n$ should be largest) and $d=1$ at the two ends of the slice (where $e_n$ should be smallest). Personally, I view it as a distance-dependent rescaling of the elevation map. Really, any map $e_n(p) = e(p)f_1(d(p)) + f_2(d(p))$ or even $e_n(p) = f(e(p),d(p))$ could be used; this one just as a nice and simple form as a distance-dependent linear interpolation between lower and upper elevation values. It think the reason why he says

Use the lower shape to push the map up and the upper shape to push the map down.

is because $L$ determines the lower bound on the output elevation (so even at high distances $e_n$ or low elevations $e$, you could use $L$ to ensure $e_n$ is high, thus pushing it up), while $H$ determines its upper-bound, so even if $e$ is very high, you can use $U$ to force it to nothing at large distances (thus pushing it down).

Anyway, hopefully that helps, rodent-san; sorry it's so long. :)