柏林噪聲

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.做特效地模擬火焰、雲彩等。

相關詞條

熱門詞條

聯絡我們