更新时间:2023-12-09 13:52
Perlin噪声 ( Perlin noise )指由Ken Perlin发明的自然噪声生成算法 。
术语简介
一个噪声函数基本上是一个种子随机发生器。它需要一个整数作为参数,然后根据这个参数返回一个随机数。如果你两次都传同一个参数进来,它就会产生两次相同的数。这条规律非常重要,否则柏林函数只是生成一堆垃圾。
Here is a graph showing an example noise function. A random value between 0 and1 is assigned to every
point on the X axis.
这里的一张图展现了噪声函数的一个例子。X轴上每个点被赋予一个0到1之间的随机数。
By smoothly interpolating between the values, we can define a continuous function that takes a non-integer as a parameter. I will discuss various ways of interpolating the values later in this article.
通过在值之间平滑的插值,我们定义了一个带有一个非整参数的连续函数。我们将会在后面的内容中讨论多种插值方式
Definitions
定义
Before I go any further, let me define what I mean by amplitude and frequency. If you have studied physics, you may well have come across the concept of amplitude and frequency applied to a sin wave.
当我们准备深入之前,让我定义下什么是振幅(amplitude)和频率(frequency)。如果你学过物理,你可能遇到过在正弦波中振幅(amlitude)和频率(frequency)的概念。
Sin Wave
The wavelength of a sin wave is the distance from one peak to another. The amplitude is the height of the wave. The frequency is defined to be 1/wavelength.
正弦波
正弦波的波长(wavelength)是两个波峰只间的距离。振幅是此波的高度。频率我们定义为 1/波长(wavelength)。
Noise Wave
In the graph of this example noise function, the red spots indicate the random values defined along the dimension of the function. In this case, the amplitude is the difference between the minimum and maximum values the function could have. The wavelength is the distance from one red spot to the next. Again frequency is defined to be 1/wavelength.
噪声波
这个噪声波的例子中,红点表示定义沿着在函数维上的随机值。在这种情况下,振幅是这个函数的最大值与最小值的差值。波长(wavelength)是两个红点之间的距离。同样的频率(frequency)定义为1/波长(wavelength).
Creating the Perlin Noise Function
创建柏林噪声函数
Now, if you take lots of such smooth functions, with various frequencies and amplitudes, you can add them all together to create a nice noisy function. This is the Perlin Noise Function.
如果你使用很多平滑函数,分别拥有各种各样的频率和振幅,你可以把他们叠加在一起来创建一个漂亮的噪声函数。这个就是柏林噪声函数。
Take the following Noise Functions
使用以下的噪声函数
Add them together, and this is what you get.
将他们叠加起来,你将会得到:-
You can see that this function has large, medium and small variations. You may even imagine that it looks a little like a mountain range. In fact many computer generated landscapes are made using this method. Of course they use 2D noise, which I shall get onto in a moment.
你能发现这个函数拥有大的,中的和小的变化。你甚至可以它已经有点像山的轮廓了。事实上很多电脑生成地形景观也是使用了这种方法,当然那使用的是2D的噪声,我们将过一下来研究这个。
You can, of course, do the same in 2 dimensions.
你当然同样的可以在二维下也这么做。
Some noise functions are created in 2D
一些2D的噪声函数
Adding all these functions together produces a noisy pattern.
把这些函数叠加起来产生的噪声样式。
When you're adding together these noise functions, you may wonder exactly what amplitude and frequency to use for each one. The one dimensional example above used twice the frequency and half the amplitude for each successive noise function added. This is quite common. So common in fact, that many people don't even consider using anything else. However, you can create Perlin Noise functions with different characteristics by using other frequencies and amplitudes at each step. For example, to create smooth rolling hills, you could use Perlin noise function with large amplitudes for the low frequencies , and very small amplitudes for the higher frequencies. Or you could make a flat, but very rocky plane choosing low amplitudes for low frequencies.
当你把噪声函数叠加的时候,你可能想了解每次具体使用了什么振幅和频率。上面一维的例子对于每个连续叠加的噪声函数使用了两倍的频率和二分之一倍的振幅。这个太普通了,事实上太普通,以至于很多人甚至从来都没有考虑过使用其他什么。尽管如此,你可以通过在每步使用其他的频率和振幅来创建不同特征的柏林噪声函数。例如,为了创建一个平滑滚动的丘陵,你可以使用大的振幅和小的频率的柏林噪声函数,同时小的振幅和高的频率,你可以创建一个平地,另外要创建非常颠簸的平面,应该选择小的振幅和低的频率。
在渲染中的应用:
1.在凸凹贴图它能很好地模拟火焰、云彩、奇形怪状的岩石,以及树木和大理石表面等;
2.做特效地模拟火焰、云彩等。