使用 Perlin 噪声程序生成具有明显更高海拔的区域

Procedurally generating areas with distinctly higher elevations with Perlin Noise

我正在尝试了解 Perlin Noise 和程序生成。我正在阅读有关生成带有噪声的景观的在线教程,但我不理解作者关于制作更高海拔区域的部分解释。

this webpage 的 "islands" 部分下有文本

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)).

我想做这个,但我不知道作者说的上下形状是什么意思。

作者 "Use the lower shape to push the map up and the upper shape to push the map down" 是什么意思?

代码示例:

from __future__ import division
import numpy as np
import math
import noise


def __noise(noise_x, noise_y, octaves=1, persistence=0.5, lacunarity=2):
    """
    Generates and returns a noise value.

    :param noise_x: The noise value of x
    :param noise_y: The noise value of y
    :return: numpy.float32
    """

    value = noise.pnoise2(noise_x, noise_y,
                          octaves, persistence, lacunarity)

    return np.float32(value)


def __elevation_map():
    elevation_map = np.zeros([900, 1600], np.float32)

    for y in range(900):

        for x in range(1600):

            noise_x = x / 1600 - 0.5
            noise_y = y / 900 - 0.5

            # find distance from center of map
            distance = math.sqrt((x - 800)**2 + (y - 450)**2)
            distance = distance / 450

            value = __noise(noise_x, noise_y,  8, 0.9, 2)
            value = (1 + value - distance) / 2

            elevation_map[y][x] = value

    return elevation_map

作者的意思是您应该根据点到中心 d 的距离来描述点的 最终 高程 fe,以及初始高度,e,这可能是由噪音产生的。

因此,例如,如果您希望您的地图看起来像一个碗,但又要保持原始生成地形的嘈杂特征,您可以使用以下函数:

def lower(d):
    # the lower elevation is 0 no matter how near you are to the centre
    return 0

def upper(d):
    # the upper elevation varies quadratically with distance from the centre
    return d ** 2

def modify(d, initial_e):
    return lower(d) + initial_e * (upper(d) - lower(d))

请特别注意以 "How does this work?" 开头的段落,我发现它很有启发性。