6

I'd like to implement a procedural generation of a terrain. After a thorough research I came up with a conclusion that it should be implemented with one of the gradient (coherent) noise generation algorithms, for instance Perlin Noise algorithm. However, I don't want the generation to be completely random. I'd like to apply some constraints (like where should be a mountain range, or where should be a lowland etc.).

Question:

For example I have a curve which represents some landscape element. The curve is an array of points.

  • How can I improve the Perlin Noise algorithm, so that along this curve the noise will have a preferred range of values (or, for simplicity, value 0)?
  • Alternatively, if I have a texture which is an output of Perlin Noise algorithm (2d array), how can I transform it to the desired noise (influenced by the curve)?
4

1 回答 1

12

如何改进 Perlin 噪声算法,以便沿着这条曲线,噪声将具有首选的值范围(或者,为简单起见,值为 0)?

这可以通过一个简单的p -> f(p)数学函数转换地图中的每个像素来实现。

考虑一个函数,它将紫色线映射到蓝色曲线 - 它强调较低的定位高度以及非常高的定位高度,但使它们之间的过渡更陡峭(这个例子只是一个余弦函数,使曲线不太平滑会使转型更加突出)。

余弦值变换

您也可以只使用曲线的下半部分,使峰更锐利,较低的区域更平坦(因此更具可玩性)。

余弦值变换 II

曲线的“锐度”可以很容易地用功率(使效果更加戏剧化)或平方根(降低效果)来调制。

在此处输入图像描述

实现这一点实际上非常简单(特别是如果您使用余弦函数) - 只需将函数应用于地图中的每个像素。如果函数在数学上不是那么微不足道,那么查找表就可以正常工作(表值之间的三次插值,线性插值会产生伪影)。

(从我的回答复制到另一个问题

如果您只需要将生成的噪声转换为已知值范围(如 -1.0 - 1.0),请使用以下算法:

function scaleValuesTo(heightMap, newMin, newMax)
{
    var min = min(heightMap);
    var range = max(heightMap) - min;
    var newRange = newMax - newMin;

    for each coordinate x, y do:
        hrightMap[x, y] = newMin + (heightMap[x, y] - min) * newRange / range;
    end for
}

我想应用一些限制(比如哪里应该是山脉,或者哪里应该是低地等)。

这有点复杂,因为您需要指定山脉的位置。最简单的解决方案是使用所需地形的粗略形状创建一个单独的高度图(您可以通过程序执行此操作,也可以从位图加载它,这无关紧要),然后将其与噪声图一起添加。有几件事情要记住:

1) 确保模板地图上没有锋利的边缘(这些边缘在组合地图上非常明显)。框模糊通常足以达到此目的,尽管像高斯模糊这样的更复杂的过滤器可以提供更好的结果(在某些情况下,框模糊会在地图上保留一些锐利的边缘)。

2) 您可能希望在较高海拔的噪声图上给予较高的优先级,而在较低海拔的情况下给予较低的优先级。这可以通过执行以下操作轻松实现:combinedMap[x, y] = templateMap[x, y] + (0.2 + 0.8 * templateMap[x, y]) * noiseMap[x, y].

您可以在此图上看到这种方法:

http://matejz.wz.cz/scheme.jpg

(我为自己的地形生成项目做了这个)

于 2014-04-25T07:50:54.070 回答