• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            曠野的呼聲

            路漫漫其修遠(yuǎn)兮 吾將上下而求索

            常用鏈接

            統(tǒng)計(jì)

            最新評(píng)論

            柏林噪聲 perlin noise

            Perlin Noise  在wikipia上,可以查到定義,這里不多說了,http://freespace.virgin.net/hugo.elias/models/m_perlin.htm 上有完整的英文,http://www.azure.com.cn/article.asp?id=291 是帶有翻譯的英文, 看來這篇文章是原始作者的大作了。轉(zhuǎn)帖過來

            柏林噪聲(Perlin Noise)(譯)
            原文鏈接:http://freespace.virgin.net/hugo.elias/models/m_perlin.htm
            翻譯:azure

            Many people have used random number generators in their programs to create unpredictability, make the motion and behavior of objects appear more natural, or generate textures. Random number generators certainly have their uses, but at times their output can be too harsh to appear natural. This article will present a function which has a very wide range of uses, more than I can think of, but basically anywhere where you need something to look natural in origin. What's more it's output can easily be tailored to suit your needs.
            很多人在他們的程序中使用隨機(jī)數(shù)生成器去創(chuàng)造不可預(yù)測(cè),使物體的行為和運(yùn)動(dòng)表現(xiàn)的更加自然,或者生成紋理。隨機(jī)數(shù)生成器當(dāng)然是有他們的用途的,但是它們似乎過于苛刻。這篇文章將會(huì)展示一個(gè)用途十分廣泛的功能,甚至其用途比我想到的還要廣泛,其結(jié)果可以輕易的適合你的需求。

            If you look at many things in nature, you will notice that they are fractal. They have various levels of detail. A common example is the outline of a mountain range. It contains large variations in height (the mountains), medium variations (hills), small variations (boulders), tiny variations (stones) . . . you could go on. Look at almost anything: the distribution of patchy grass on a field, waves in the sea, the movements of an ant, the movement of branches of a tree, patterns in marble, winds. All these phenomena exhibit the same pattern of large and small variations. The Perlin Noise function recreates this by simply adding up noisy functions at a range of different scales.
            如果你觀察自然界中很多事物,你會(huì)注意到它們是分形的。它們有著很多層次細(xì)節(jié)。最平常的例子是山峰輪廓。它包含著高度上的很大變化(山峰),中等變化(丘陵),小的變化(礫石),微小變化(石頭)...你可以繼續(xù)想象。觀察幾乎所有事物:片狀分布于田間草,海中的波浪,螞蟻的運(yùn)動(dòng)方式,樹枝的運(yùn)動(dòng),大理石的花紋,風(fēng)。所有這些現(xiàn)象表現(xiàn)出了同一種的大小的變化形式。柏林噪聲函數(shù)通過直接添加一定范圍內(nèi),不同比例的噪聲函數(shù)來重現(xiàn)這種現(xiàn)象。

            To create a Perlin noise function, you will need two things, a Noise Function, and an Interpolation Function.
            為了創(chuàng)建一個(gè)柏林噪聲函數(shù),我們需要兩個(gè)東西,一個(gè)噪聲函數(shù)和一個(gè)插值函數(shù)。

            Introduction To Noise Functions
            噪聲函數(shù)介紹

            A noise function is essentially a seeded random number generator. It takes an integer as a parameter, and returns a random number based on that parameter. If you pass it the same parameter twice, it produces the same number twice. It is very important that it behaves in this way, otherwise the Perlin function will simply produce nonsense.
            一個(gè)噪聲函數(shù)基本上是一個(gè)種子隨機(jī)發(fā)生器。它需要一個(gè)整數(shù)作為參數(shù),然后返回根據(jù)這個(gè)參數(shù)返回一個(gè)隨機(jī)數(shù)。如果你兩次都傳同一個(gè)參數(shù)進(jìn)來,它就會(huì)產(chǎn)生兩次相同的數(shù)。這條規(guī)律非常重要,否則柏林函數(shù)只是生成一堆垃圾。




            Here is a graph showing an example noise function. A random value between 0 and1 is assigned to every
            point on the X axis.
            這里的一張圖展現(xiàn)了噪聲函數(shù)的一個(gè)例子。X軸上每個(gè)點(diǎn)被賦予一個(gè)0到1之間的隨機(jī)數(shù)。


            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.
            通過在值之間平滑的插值,我們定義了一個(gè)帶有一個(gè)非整參數(shù)的連續(xù)函數(shù)。我們將會(huì)在后面的內(nèi)容中討論多種插值方式

            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.
            當(dāng)我們準(zhǔn)備深入之前,讓我定義下什么是振幅(amplitude)和頻率(frequency)。如果你學(xué)過物理,你可能遇到過在正玄波中振幅(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.
            正玄波
            正玄波的波長(zhǎng)(wavelength)是兩個(gè)波峰只間的距離。振幅是此波的高度。頻率我們定義為 1/波長(zhǎng)(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.
            噪聲波
            圖中這個(gè)噪聲波的例子中,紅點(diǎn)表示定義沿著在函數(shù)維上的隨機(jī)值。在這種情況下,振幅是這個(gè)函數(shù)的最大值與最小值的差值。波長(zhǎng)(wavelength)是兩個(gè)紅點(diǎn)之間的距離。同樣的頻率(frequency)定義為1/波長(zhǎng)(wavelength).

            Creating the Perlin Noise Function
            創(chuàng)建柏林噪聲函數(shù)

            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.
            現(xiàn)在,如果你使用很多平滑函數(shù),分別擁有各種各樣的頻率和振幅,你可以把他們疊加在一起來創(chuàng)建一個(gè)漂亮的噪聲函數(shù)。這個(gè)就是柏林噪聲函數(shù)。

            Take the following Noise Functions
            使用以下的噪聲函數(shù)



            Add them together, and this is what you get.
            將他們疊加起來,你將會(huì)得到:-)


            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.
            你能發(fā)現(xiàn)這個(gè)函數(shù)擁有大的,中的和小的變化。你甚至可以它已經(jīng)有點(diǎn)像山的輪廓了。事實(shí)上很多電腦生成地形景觀也是使用了這種方法,當(dāng)然那使用的是2D的噪聲,我們將過一下來研究這個(gè)。

            You can, of course, do the same in 2 dimensions.
            你當(dāng)然同樣的可以在二維下也這么做。

            Some noise functions are created in 2D
            一些2D的噪聲函數(shù)




            Adding all these functions together produces a noisy pattern.
            把這些函數(shù)疊加起來產(chǎn)生的噪聲樣式。



            Persistence
            持續(xù)度

            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.
            當(dāng)你把噪聲函數(shù)疊加的時(shí)候,你可能想了解每次具體使用了什么振幅和頻率。上面一維的例子對(duì)于每個(gè)連續(xù)疊加的噪聲函數(shù)使用了兩倍的頻率和二分之一倍的振幅。這個(gè)太普通了,事實(shí)上太普通,以至于很多人甚至從來都沒有考慮過使用其他什么。盡管如此,你可以通過在每步使用其他的頻率和振幅來創(chuàng)建不同特征的柏林噪聲函數(shù)。例如,為了創(chuàng)建一個(gè)平滑滾動(dòng)的丘陵,你可以使用大的振幅和小的頻率的柏林噪聲函數(shù),同時(shí)小的振幅和高的頻率,你可以創(chuàng)建一個(gè)平地,另外要?jiǎng)?chuàng)建非常顛簸的平面,應(yīng)該選擇小的振幅和低的頻率。

            To make it simpler, and to avoid repeating the words Amplitude and Frequency all the time, a single number is used to specify the amplitude of each frequency. This value is known as Persistence. There is some ambiguity as to it's exact meaning. The term was originally coined by Mandelbrot, one of the people behind the discovery of fractals. He defined noise with a lot of high frequency as having a low persistence. My friend Matt also came up with the concept of persistence, but defined it the other way round. To be honest, I prefer Matt's definition. Sorry Mandelbrot. So our definition of persistence is this:
            為了讓這些更簡(jiǎn)單易懂,同時(shí)為了避免重復(fù)振幅和頻率這兩個(gè)詞,我們用一個(gè)數(shù)來表示每個(gè)頻率下的振幅,這個(gè)數(shù)就是持續(xù)度(Persistence)。這里的詞和它的真實(shí)意義有些歧異。這個(gè)術(shù)語原本是Mandelbrot提出的,他是發(fā)現(xiàn)分形現(xiàn)象的人中的一個(gè)。他定義噪聲擁有大量的高頻率將體現(xiàn)出低的持續(xù)度。我的朋友Matt也想出了持續(xù)度的概念,但是是通過另外一種方式定義它的。誠然,我更喜歡Matt的定義方式。對(duì)不起了,Mandelbrot. 所以我們這樣定義持續(xù)度(persistence):
            frequency = 2i
            amplitude = persistencei
            Where i is the ith noise function being added. To illustrate the effect of persistence on the output of the Perlin Noise, take a look at the diagrams below. They show the component noise functions that are added, the effect of the persistence value, and the resultant Perlin noise function.
            i 是表示第i個(gè)被疊加的噪聲函數(shù)。為了展示柏林函數(shù)在輸出上持續(xù)度的表現(xiàn)效果,請(qǐng)看下下面的圖表。他們展示了疊加的每個(gè)組成部分,持續(xù)度的效果和最終的柏林函數(shù)。



            Octaves
            倍頻

            Each successive noise function you add is known as an octave. The reason for this is that each noise function is twice the frequency of the previous one. In music, octaves also have this property.
            每個(gè)你所疊加的噪聲函數(shù)就是一個(gè)倍頻。因?yàn)槊恳粋€(gè)噪聲函數(shù)是上一個(gè)的兩倍頻率。在音樂上,倍頻也有著這項(xiàng)屬性。

            Exactly how many octaves you add together is entirely up to you. You may add as many or as few as you want. However, let me give you some suggestions. If you are using the perlin noise function to render an image to the screen, there will come a point when an octave has too high a frequency to be displayable. There simply may not be enough pixels on the screen to reproduce all the little details of a very high frequency noise function. Some implementations of Perlin Noise automatically add up as many noise functions they can until the limits of the screen (or other medium) are reached.
            具體多少倍頻你疊加在一起,這完全取決于你。你可以疊加很多也可以很少。盡管如此,還是讓我給你一些建議吧。如果你正使用柏林噪聲函數(shù)在屏幕上渲染圖象的話,如果倍頻頻率太高將會(huì)使縮成一個(gè)點(diǎn)以至于不能顯示,這就是因?yàn)槟闫聊坏姆直媛什粔?。一些柏林噪聲函?shù)的實(shí)現(xiàn)會(huì)自動(dòng)疊加噪聲函數(shù)直到達(dá)到屏幕分辨率的極限。

            It is also wise to stop adding noise functions when their amplitude becomes too small to reproduce. Exactly when that happens depends on the level of persistence, the overall amplitude of the Perlin function and the bit resolution of your screen (or whatever).
            當(dāng)振幅變的很小的時(shí)候,也應(yīng)該明智的停止再疊加噪聲函數(shù)。屆時(shí)當(dāng)發(fā)生依靠持續(xù)度的等級(jí),柏林函數(shù)整體的振幅和屏幕的分辨率(翻譯的爛)。

            Making your noise functions
            創(chuàng)造你的噪聲函數(shù)

            What do we look for in a noise function? Well, it's essentially a random number generator. However, unlike other random number generators you may have come across in your programs which give you a different random number every time you call them, these noise functions supply a random number calculated from one or more parameters. I.e. every time you pass the same number to the noise function, it will respond with the same number. But pass it a different number, and it will return a different number.
            我們需要什么樣的噪聲函數(shù)?好,基本上就是一個(gè)隨機(jī)數(shù)發(fā)生器。盡管如此,它不像你在程序中遇到的那中每次調(diào)用它都返回不同的隨機(jī)數(shù)的隨機(jī)函數(shù),這些噪聲函數(shù)生成一個(gè)隨機(jī)數(shù)是通過一個(gè)或者多個(gè)參數(shù)計(jì)算而來。例如,每次你傳入一個(gè)相同的數(shù)到噪聲函數(shù)里,它將每次也返回相同的隨機(jī)數(shù)。但是如果傳入一個(gè)不同的數(shù),那么它又將返回一個(gè)不同的數(shù),

            Well, I don't know a lot about random number generators, so I went looking for some, and here's one I found. It seems to be pretty good. It returns floating point numbers between -1.0 and1.0.
            好,我對(duì)隨機(jī)數(shù)生成器并不懂太多,所以我去找了一些,這里我找到了一個(gè),好象很好用。它返回一個(gè)浮點(diǎn)數(shù),范圍是-1.0到1.0
            function IntNoise(32-bit integer: x)      

            x = (x<<13) ^ x;
            return ( 1.0 - ( (x * (x * x * 15731 + 789221) + 1376312589) & 7fffffff) / 1073741824.0);
            end IntNoise function
            Now, you'll want several different random number generators, so I suggest making several copies of the above code, but use slightly different numbers. Those big scarey looking numbers are all prime numbers, so you could just use some other prime numbers of a similar size. So, to make it easy for you to find random numbers, I have written a little program to list prime numbers for you. You can give it a start number and an end number, and it will find all the primes between the two. Source code is also included, so you can easily include it into your own programs to produce a random prime number. Primes.zip
            現(xiàn)在,你將要需要幾個(gè)不同的隨機(jī)數(shù)生成器,所以我建議把上面的代碼復(fù)制幾個(gè)拷貝,然后稍微修改下里面的參數(shù)。那些可怕的數(shù)字都是質(zhì)數(shù),所以你可以改成其他差不多大小的質(zhì)數(shù)(讓我想起了 hash key生成),為了讓你輕松的找的隨機(jī)數(shù),我已經(jīng)寫了一個(gè)小程序來為你列出質(zhì)數(shù)。你只用輸入一個(gè)起始值和一個(gè)結(jié)束值,它找到所有在兩值之間的質(zhì)數(shù)。源代碼也提供,所以你可以輕松的包含到你自己的程序中來生成隨機(jī)的質(zhì)數(shù).Primes.zip

            Interpolation
            插值

            Having created your noise function, you will need to smooth out the values it returns. Again, you can choose any method you like, but some look better than others. A standard interpolation function takes three inputs, a and b, the values to be interpolated between, and x which takes a value between 0 and1. The Interpolation function returns a value between a and b based on the value x. When x equals 0, it returns a, and when x is 1, it returns b. When x is between 0 and1, it returns some value between a and b.
            當(dāng)創(chuàng)建了你的噪聲函數(shù),你將需要平滑下他的返回值。再次,你可以選擇任何你喜歡的方式,但是有一些效果更好。一個(gè)標(biāo)準(zhǔn)的插值函數(shù)需要三個(gè)輸入,a 和 b, 需要在a和b之間進(jìn)行插值,還有x,它取值范圍是0到1。插值函數(shù)返回a到b之間取決與x的一個(gè)值。當(dāng)x等于0,它返回a,當(dāng)x等于1時(shí),它返回b。當(dāng)x 是0到1之間時(shí),它將返回a到b之間的某值。

            Linear Interpolation:
            線性插值

            Looks awful, like those cheap 'plasmas' that everyone uses to generate landscapes. It's a simple algorithm though, and I suppose would be excusable if you were trying to do perlin noise in realtime.
            看起來很齷齪的,像那些每個(gè)人用來生成地形的廉價(jià)'plasmas'一樣,它是一個(gè)簡(jiǎn)單的算法,如果你想實(shí)時(shí)的使用柏林噪聲函數(shù),這種插值方式是一個(gè)選擇。

            function Linear_Interpolate(a, b, x)
              return a*(1-x) + b*x
            end of function
            Cosine Interpolation:
            余玄插值

            This method gives a much smother curve than Linear Interpolation. It's clearly better and worth the effort if you can afford the very slight loss in speed.
            這個(gè)方法線性插值生成了更平滑的曲線。它當(dāng)然有著更好的效果,如果你愿意稍微損失點(diǎn)速度的話。

            function Cosine_Interpolate(a, b, x)
              ft = x * 3.1415927
              f = (1 - cos(ft)) * .5

              return a*(1-f) + b*f
            end of function
            Cubic Interpolation:
            立方插值:

            This method gives very smooth results indeed, but you pay for it in speed. To be quite honest, I'm not sure if it would give noticeably better results than Cosine Interpolation, but here it is anyway if you want it. It's a little more complicated, so pay attention. Whereas before, the interpolation functions took three inputs, the cubic interpolation takes five. Instead of just a and b, you now need v0, v1, v2 and v3, along with x as before.
            這個(gè)方法的確是生成了非常平滑的結(jié)果,但是你付出的代價(jià)就是速度。老實(shí)說,我不那么確定它能給你比余玄插值好很多的效果,但是如果你無論如何要使用它的話,它有一點(diǎn)點(diǎn)的復(fù)雜,所以這里請(qǐng)注意,之前,插值函數(shù)只需要三個(gè)參數(shù),但是立方插值需要五個(gè),取代了a和b,現(xiàn)在你需要v0,v1,v2,v3,x和以前一樣也需要。


            這些是:
            v0 = a 前面一點(diǎn)
            v1 = a 點(diǎn)
            v2 = b 點(diǎn)
            v3 = b 后面一點(diǎn)


            function Cubic_Interpolate(v0, v1, v2, v3,x)
              P = (v3 - v2) - (v0 - v1)
              Q = (v0 - v1) - P
              R = v2 - v0
              S = v1

              return Px3 + Qx2 + Rx + S
            end of function
            Smoothed Noise
            平滑的噪聲

            Aside from Interplolation, you can also smooth the output of the noise function to make it less random looking, and also less square in the 2D and 3D versions. Smoothing is done much as you would expect, and anyone who has written an image smoothing filter, or fire algorithm should already be familiar with the process.
            Rather than simply taking the value of the noise function at a single coordinate, you can take the average of that value, and it's neighbouring values. If this is unclear, take a look at the pseudo code below.
            除了插值,你也可以平滑噪聲函數(shù)的輸出來使它看起來不那么隨機(jī),和讓2D和3D的版本少一點(diǎn)方塊。平滑的結(jié)果和你所想的差不多,只要是寫過平滑過濾或者火焰算法的人都應(yīng)該相當(dāng)熟悉此過程。相比在一個(gè)單獨(dú)的坐標(biāo)上取得噪聲值,你可以取平均的噪聲值,和它臨近的值。如果你不清楚這個(gè),可以看看下面的偽代碼。

            On the right, you can see a little diagram illustrating the difference between smoothed noise, and the same noise function without smoothing. You can see that the smooth noise is flatter, never reaching the extremes of unsmoothed noise, and the frequency appears to be roughly half. There is little point smoothing 1 dimensional noise, since these are really the only effects. Smoothing becomes more useful in 2 or three dimensions, where the effect is to reduce the squareness of the noise. Unfortunately it also reduces the contrast a little. The smoother you make it, obviously, the flatterthe noise will be.
            在右面(這里看下面),你可以看見一個(gè)小的圖展示了不同平滑函數(shù)的區(qū)別,和同樣的一個(gè)噪聲但未進(jìn)行平滑處理。你可以看見平滑函數(shù),從來都沒有到底那個(gè)未平滑函數(shù)的極限值,并且頻率顯得只有大約一半。那里有小點(diǎn)平滑一維的噪聲,只有這一個(gè)效果。平滑過程在二維和三維中,顯得更有用處,那就是它減少了噪聲大方塊。不幸的是它也降低了一點(diǎn)對(duì)比度。你讓它越平滑,這個(gè)噪聲就會(huì)越平坦。



            1-dimensional Smooth Noise
            一維噪聲函數(shù)
            function Noise(x)
            .
            .
            end function

            function SmoothNoise_1D(x)

            return Noise(x)/2 + Noise(x-1)/4 + Noise(x+1)/4

            end function
            2-dimensional Smooth Noise
            二維噪聲函數(shù)
            function Noise(x, y)
            .
            .
            end function

            function SmoothNoise_2D(x>, y)

            corners = ( Noise(x-1, y-1)+Noise(x+1, y-1)+Noise(x-1, y+1)+Noise(x+1, y+1) ) / 16
            sides = ( Noise(x-1, y) +Noise(x+1, y) +Noise(x, y-1) +Noise(x, y+1) ) / 8
            center = Noise(x, y) / 4

            return corners + sides + center

            end function
            Putting it all together
            把它們組合在一起

            Now that you know all that, it's time to put together all you've learned and create a Perlin Noise function. Remember that it's just several Interpolated Noise functions added together. So Perlin Noise it just a function. You pass it one or more parameters, and it responds with a number. So, here's a simple 1 dimensional Perlin function.
            既然你知道了全部這些,現(xiàn)在是時(shí)候把他們組合在一起了,你將學(xué)會(huì)并創(chuàng)建一個(gè)柏林函數(shù)。記住這知識(shí)幾個(gè)插值的噪聲函數(shù)疊加在一起。所以柏林函數(shù)只是一個(gè)函數(shù)。你傳入一個(gè)或多個(gè)參數(shù),然后它返回一個(gè)數(shù)給你。所以很簡(jiǎn)單,一維的柏林函數(shù)是這樣。

            The main part of the Perlin function is the loop. Each iteration of the loop adds another octave of twice the frequency. Each iteration calls a different noise function, denoted by Noisei. Now, you needn't actually write lots of noise functions, one for each octave, as the pseudo code seems to suggest. Since all the noise functions are essentially the same, except for the values of those three big prime numbers, you can keep the same code, but simply use a different set of prime numbers for each.
            柏林函數(shù)重要的部分是那個(gè)循環(huán)。每次循環(huán)跌代疊加另一個(gè)兩倍頻率的倍頻。每次跌代調(diào)用一個(gè)不同的噪聲函數(shù),稱做Noisei。當(dāng)然,你并不需要真的寫為每個(gè)倍頻很多噪聲函數(shù),偽代碼中好象只是建議這么做。既然所有的噪聲函數(shù)實(shí)際上都是相同的,除了那三個(gè)大質(zhì)數(shù)不同除外,你可以使用同樣的代碼,只是每個(gè)代碼改用不同的質(zhì)數(shù)。

            1-dimensional Perlin Noise Pseudo code
            一維柏林噪聲函數(shù)偽代碼
            function Noise1(integer x)
            x = (x<<13) ^ x;
            return ( 1.0 - ( (x * (x * x * 15731 + 789221) + 1376312589) & 7fffffff) / 1073741824.0);
            end function

            function SmoothedNoise_1(float x)
            return Noise(x)/2 + Noise(x-1)/4 + Noise(x+1)/4
            end function

            function InterpolatedNoise_1(float x)

            integer_X = int(x)
            fractional_X = x - integer_X

            v1 = SmoothedNoise1(integer_X)
            v2 = SmoothedNoise1(integer_X + 1)

            return Interpolate(v1 , v2 , fractional_X)

            end function

            function PerlinNoise_1D(float x)

            total = 0
            p = persistence
            n = Number_Of_Octaves - 1

            loop i from 0 to n

            frequency = 2i
            amplitude = pi

            total = total + InterpolatedNoisei(x * frequency) * amplitude

            end of i loop

            return total

            end function
            Now it's easy to apply the same code to create a 2 or more dimensional Perlin Noise function:
            現(xiàn)在可以輕松的使用同樣的代碼創(chuàng)建二維或者多維的柏林噪聲函數(shù)了:

            2-dimensional Perlin Noise Pseudocode
            二維柏林噪聲函數(shù)偽代碼
            function Noise1(integer x, integer y)
            n = x + y * 57
            n = (n<<13) ^ n;
            return ( 1.0 - ( (n * (n * n * 15731 + 789221) + 1376312589) & 7fffffff) / 1073741824.0);
            end function

            function SmoothNoise_1(float x, float y)
            corners = ( Noise(x-1, y-1)+Noise(x+1, y-1)+Noise(x-1, y+1)+Noise(x+1, y+1) ) / 16
            sides = ( Noise(x-1, y) +Noise(x+1, y) +Noise(x, y-1) +Noise(x, y+1) ) / 8
            center = Noise(x, y) / 4
            return corners + sides + center
            end function

            function InterpolatedNoise_1(float x, float y)

            integer_X = int(x)
            fractional_X = x - integer_X

            integer_Y = int(y)
            fractional_Y = y - integer_Y

            v1 = SmoothedNoise1(integer_X, integer_Y)
            v2 = SmoothedNoise1(integer_X + 1, integer_Y)
            v3 = SmoothedNoise1(integer_X, integer_Y + 1)
            v4 = SmoothedNoise1(integer_X + 1, integer_Y + 1)

            i1 = Interpolate(v1 , v2 , fractional_X)
            i2 = Interpolate(v3 , v4 , fractional_X)

            return Interpolate(i1 , i2 , fractional_Y)

            end function

            function PerlinNoise_2D(float x, float y)

            total = 0
            p = persistence
            n = Number_Of_Octaves - 1

            loop i from 0 to n

            frequency = 2i
            amplitude = pi

            total = total + InterpolatedNoisei(x * frequency, y * frequency) * amplitude

            end of i loop

            return total

            end function

            本文來自CSDN博客,轉(zhuǎn)載請(qǐng)標(biāo)明出處:http://blog.csdn.net/anywn1314/archive/2007/10/15/1825765.aspx

            posted on 2009-09-12 21:15 董波 閱讀(1968) 評(píng)論(0)  編輯 收藏 引用


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            久久久久久久97| 久久精品日日躁夜夜躁欧美| 久久本道久久综合伊人| 久久久久亚洲精品无码蜜桃| 久久婷婷五月综合97色| 天天躁日日躁狠狠久久| Xx性欧美肥妇精品久久久久久| 国产精品美女久久久网AV| 东方aⅴ免费观看久久av| 久久香蕉国产线看观看精品yw| 国产精品久久久久jk制服| 99久久伊人精品综合观看| 一本久久知道综合久久| 久久久久久亚洲精品无码| 久久国产精品99精品国产| 日韩久久久久中文字幕人妻| 久久99久久99小草精品免视看| 午夜天堂av天堂久久久| 思思久久精品在热线热| 亚洲国产天堂久久久久久| 久久国产午夜精品一区二区三区| 免费国产99久久久香蕉| 国内精品久久人妻互换| 精品国产91久久久久久久| 久久精品国产亚洲av水果派| 色婷婷久久综合中文久久蜜桃av| 中文字幕久久精品| 潮喷大喷水系列无码久久精品| 国产99久久精品一区二区| 国产呻吟久久久久久久92| 青青青青久久精品国产h久久精品五福影院1421 | 久久夜色精品国产网站| 久久99久久99精品免视看动漫| 久久九九有精品国产23百花影院| 欧美日韩中文字幕久久伊人| 精品久久久久久国产牛牛app| 欧洲性大片xxxxx久久久| 狼狼综合久久久久综合网| 久久电影网2021| 高清免费久久午夜精品| 久久成人国产精品免费软件|