青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

醬壇子

專注C++技術 在這里寫下自己的學習心得 感悟 和大家討論 共同進步(歡迎批評?。。。?/p>

  C++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
  66 Posts :: 16 Stories :: 236 Comments :: 0 Trackbacks
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.

公告

王一偉 湖南商學院畢業 電子信息工程專業

常用鏈接

留言簿(19)

我參與的團隊

搜索

  •  

積分與排名

  • 積分 - 389620
  • 排名 - 64

最新隨筆

最新評論

閱讀排行榜

評論排行榜

Perlin Noise


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.

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.

To create a Perlin noise function, you will need two things, a Noise Function, and an Interpolation Function.

Introduction To Noise Functions

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.

Here is a graph showing an example noise function. A random value between 0 and 1 is assigned to every point on the X axis.

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.

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

Sin Wave

Noise Wave


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.
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.
Take the following Noise Functions

Add them together, and this is what you get.

You can, of course, do the same in 2 dimensions.
Some noise functions are created in 2D
Adding all these functions together produces a noisy pattern.

Persistence

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.

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:


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.

Frequency12481632
Persistence = 1/4+++++=
Amplitude:11/41/161/641/2561/1024result
Persistence = 1/2+++++=
Amplitude:11/21/41/81/161/32result
Persistence = 1 / root2+++++=
Amplitude:11/1.4141/21/2.8281/41/5.656result
Persistence = 1+++++=
Amplitude:111111result


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

Making your noise functions

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.

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 and 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

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 and 1. 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 and 1, it returns some value between a and b.

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.

Linear Interpolation:

  function Linear_Interpolate(a, b, x)
	return  a*(1-x) + b*x
  end of function

Cosine Interpolation:

  function Cosine_Interpolate(a, b, x)
	ft = x * 3.1415927f = (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. These are:
v0 = the point before a
v1 = the point a
v2 = the point b
v3 = the point after b
  function Cubic_Interpolate(v0, v1, v2, v3,x)
	P = (v3 - v2) - (v0 - v1)
	Q = (v0 - v1) - PR = v2 - v0S = 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.
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.

1-dimensional Smooth Noise
  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

  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) ) / 16sides   = ( Noise(x-1, y)  +Noise(x+1, y)  +Noise(x, y-1)  +Noise(x, y+1) ) /  8center  =  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.
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.

1-dimensional Perlin Noise Pseudo code

  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_Xv1 = SmoothedNoise1(integer_X)
      v2 = SmoothedNoise1(integer_X + 1)

      return Interpolate(v1 , v2 , fractional_X)

  end function


  function PerlinNoise_1D(float x)

      total = 0p = persistencen = Number_Of_Octaves - 1

      loop i from 0 to nfrequency = 2iamplitude = pitotal = 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:

2-dimensional Perlin Noise Pseudocode

  function Noise1(integer x, integer y)
    n = x + y * 57n = (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) ) / 16sides   = ( Noise(x-1, y)  +Noise(x+1, y)  +Noise(x, y-1)  +Noise(x, y+1) ) /  8center  =  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_Xinteger_Y    = int(y)
      fractional_Y = y - integer_Yv1 = 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 = 0p = persistencen = Number_Of_Octaves - 1

      loop i from 0 to nfrequency = 2iamplitude = pitotal = total + InterpolatedNoisei(x * frequency, y * frequency) * amplitude

      end of i loop

      return total

  end function


Applications of Perlin Noise

Now that you have this fantastic function, what can you do with it? Well, as the cliche goes, you're limited only by your imagination. Perlin Noise has so many applications that I can't think of them all, but I'll have a go.

1 dimensional

Living objects rarely stay still for very long (except students). Use perlin noise to constantly adjust the joint positions of a virtual human player, in a game for example, to make it look like it's more alive.

Computer drawn lines are always totally straight, which can make them look unnatural and unfriendly. You can use Perlin Noise to introduce a wobblyness to a line drawing algorithm to make it appear as if it's been drawn by hand. You can also draw wobbly circles and boxes. Some research has been done on making a Sketchy User Interface.
See: Creating Informal Looking Interfaces.

Controlling virtual beings:
Drawing sketched lines:


2 dimensional

These are a perfect application for 2D Perlin Noise. Unlike the subdivision method, you do not have to store the landscape anywhere in memory, the height of any point on the landscape can be calculated easily. What's more, the land stretches indefinitely (almost), and can be calculated to minute detail, so it's perfect of variable level of detail rendering. The properties of the landscape can be defined easily too.
Again, cloud rendering is well suited to Perlin Noise.
All sorts of textures can be generated using Perlin Noise. See the table below for some examples. The textures generated can go on for ages before repeating (if ever), which makes them much more pleasant to look at than a repeating tiled texture map.
Landscapes:
Clouds:
Generating Textures:


3 dimensional

You can, of course, produce volumetric clouds. You'll probably have to use some sort of ray tracing to visualise them.
You can produce animated 2 dimensional clouds with 3D Perlin Noise, if you consider one dimension to be time.
Some rendering / raytracing programs, like POVray, apply texture to objects by literally carving them from a 3-dimensional texture. This was, the textures do not suffer from the warping usually associated with mapping 2D textures onto (non-flat) 3D objects.
3D Clouds:
Animated Clouds:
Solid Textures:


4 dimensional

Moving into higher dimensions, you can easily produce animated clouds and solid textures. Just consider the extra dimension to be time.
Animated 3D Textures and Clouds:



Copyright Matt Fairclough 1998
The land, clouds and water in this picture were all mathematically generated with Perlin Noise, and rendered with Terragen.
The clouds in this demo are animated with 3D perlin Noise. The algorithm had to be modified slightly to be able to produce Perlin Noise in real time. See the Clouds Article for more info on how this was done.


Generating Textures with Perlin Noise

Perlin is fantastic for generating textures. You can produce textures that are (for all practical purposes) infinitely large, but take up almost no memory. You can create marble, wood, swirly patterns, probably anything if you try hard. You can also define a 3D texture. You can think of this as a solid block of material, from which you can 'carve' an object. This allows you to produce textures which can be applied to any shaped object without distortion. It can take a lot of imagination, thought and experimentation to get a texture to look really good, but the results can be very impressive indeed.

Play around as much as you like. Use several Perlin functions to create a texture, try different persistences and different frequencies in different dimensions. You can use one Perlin function to affect the properties of another. Apply functions to their output. Do whatever you want, there's almost certainally a way to produce almost any texture you can dream up.

The following textures were made with 3D Perlin Noise

Standard 3 dimensional perlin noise. 4 octaves, persistence 0.25 and 0.5
Low persistence. You can create harder edges to the perlin noise by applying a function to the output.
To create more interesting and complicated textures, you should try mixing several Perlin functions. This texture was created in two parts. Firstly a Perlin function with low persistence was used to define the shape of the blobs. The value of this function was used to select from two other functions, one of which defined the stripes, the other defined the blotchy pattern. A high value chose more of the former, a low value more of the latter. The stripes were defined by multiplying the first Perlin Function by some number (about 20) then taking the cosine.
A marbly texture can be made by using a Perlin function as an offset to a cosine function.


    texture = cosine( x + perlin(x,y,z) )
Very nice wood textures can be defined. The grain is defined with a low persistence function like this:

    g = perlin(x,y,z) * 20
    grain = g - int(g)
The very fine bumps you can see on the wood are high frequency noise that has been stretched in one dimension.

    bumps = perlin(x*50, y*50, z*20)
    if bumps < .5 then bumps = 0  else bumps = 1t


posted on 2006-10-16 08:40 @王一偉 閱讀(1618) 評論(0)  編輯 收藏 引用 所屬分類: 2. 3D渲染

只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲激情社区| 免费在线亚洲欧美| 久久裸体视频| 欧美影院久久久| 亚洲欧美在线网| 欧美在线综合| 欧美a级一区二区| 欧美激情1区2区3区| 亚洲国产精品热久久| 久久三级视频| 亚洲高清三级视频| 99成人在线| 国产精品99久久久久久久女警| 亚洲午夜激情免费视频| 欧美伊人精品成人久久综合97| 久久久999精品| 欧美成人免费小视频| 国产精品qvod| 好看不卡的中文字幕| 最新69国产成人精品视频免费| 99视频国产精品免费观看| 宅男精品视频| 欧美一区二区三区免费观看视频| 久久一区二区三区国产精品 | 久久综合久久综合久久| 欧美顶级大胆免费视频| 一本一本久久| 久久久午夜视频| 亚洲国产成人久久| 99re在线精品| 久久国产高清| 欧美午夜片在线观看| 国产一区美女| 亚洲美女av电影| 久久精品国产第一区二区三区最新章节 | 亚洲国产精品ⅴa在线观看| 宅男66日本亚洲欧美视频| 久久青草福利网站| 亚洲天堂免费观看| 欧美日韩一区二区三区在线视频| 国产日产亚洲精品系列| 亚洲高清不卡在线观看| 午夜精品成人在线| 亚洲片区在线| 久久网站免费| 国产一区二区三区最好精华液| 一本色道久久88综合亚洲精品ⅰ| 六月婷婷一区| 欧美制服第一页| 国产欧美精品va在线观看| 一区二区三区欧美| 最新成人在线| 欧美成人免费全部| 亚洲经典在线看| 欧美777四色影视在线| 亚洲在线成人精品| 欧美日韩久久久久久| 亚洲二区免费| 久久视频一区二区| 午夜精品久久久久久久99樱桃| 欧美日韩在线播放一区二区| 亚洲人成7777| 欧美刺激性大交免费视频| 欧美精品性视频| 亚洲欧美另类中文字幕| 国产精品老牛| 亚洲欧美电影院| 一区二区三区福利| 欧美午夜精品理论片a级按摩 | 欧美高潮视频| 亚洲精品久久久久| 亚洲国产精品欧美一二99| 欧美国产综合视频| 亚洲精品一二区| 日韩亚洲精品电影| 欧美日韩精品| 亚洲一区二区三区四区在线观看| 日韩午夜剧场| 国产精品亚洲一区二区三区在线| 午夜精品福利视频| 欧美一级久久久久久久大片| 国产欧美日韩综合| 久久在线观看视频| 欧美99在线视频观看| 日韩午夜av| 中文在线不卡| 一区二区三区在线观看视频| 欧美不卡激情三级在线观看| 欧美电影免费观看高清| 一区二区三区四区蜜桃| 宅男噜噜噜66一区二区| 国产精品一区免费观看| 久久综合五月| 欧美日韩ab片| 久久久人成影片一区二区三区| 老司机午夜精品视频| 99精品国产在热久久下载| 亚洲午夜精品一区二区| 亚洲破处大片| 久热精品在线视频| 欧美激情视频在线播放 | 亚洲男人的天堂在线观看| 黄色成人在线免费| 亚洲人体1000| 国产亚洲欧美日韩美女| 最新中文字幕一区二区三区| 国产精品美女久久| 麻豆精品网站| 国产精品久久久久久一区二区三区 | 亚洲夜晚福利在线观看| 久久久福利视频| 亚洲视频视频在线| 久久一区二区三区av| 午夜精品久久久久久久久久久久久| 久久米奇亚洲| 久久国产精品久久久久久| 欧美日韩国产精品| 蜜桃av噜噜一区| 国产女主播在线一区二区| 亚洲国产精品久久久| 国产亚洲欧洲| 亚洲午夜激情网站| 亚洲一区二区久久| 欧美激情一区二区三区全黄| 久久久久久久欧美精品| 欧美日韩亚洲激情| 亚洲激情在线激情| 亚洲国产一区二区三区a毛片| 午夜一区二区三视频在线观看| 一区二区三区日韩欧美精品| 久久亚洲风情| 久久手机免费观看| 国内外成人在线| 性色av一区二区怡红| 亚洲免费视频观看| 欧美日韩国产精品自在自线| 亚洲大胆人体视频| 亚洲电影免费观看高清| 久久精品一区二区三区不卡牛牛| 亚洲一区二区在线看| 欧美日韩国产经典色站一区二区三区| 久久久蜜臀国产一区二区| 欧美国产精品中文字幕| 欧美a一区二区| 亚洲国产片色| 久久尤物视频| 快播亚洲色图| 亚洲国产成人久久| 欧美搞黄网站| 亚洲美女电影在线| 亚洲欧美日韩精品久久| 国产精品亚洲精品| 欧美影院成人| 老色鬼久久亚洲一区二区| 在线高清一区| 欧美国产日韩一区二区三区| 最新国产成人在线观看| 亚洲视频在线一区观看| 一区二区三区高清在线| 亚洲日本中文字幕区| 亚洲精品午夜精品| 欧美午夜不卡| 亚洲在线视频观看| 国产区欧美区日韩区| 亚洲激情在线观看视频免费| 亚洲性人人天天夜夜摸| 亚洲一级在线观看| 麻豆视频一区二区| 亚洲成人在线网站| 亚洲一区www| 亚洲国产日韩在线一区模特| 亚洲一区二区三区在线视频| 久久精品国产精品亚洲| 久久久国产午夜精品| 亚洲欧洲精品一区| 欧美一级片久久久久久久| 欧美成人一区二区在线| 韩日欧美一区二区三区| 亚洲国产一区二区a毛片| 久久久www成人免费毛片麻豆| 亚洲精一区二区三区| 欧美1区免费| 亚洲黄色天堂| 久久综合狠狠综合久久激情| 一区二区三区四区五区精品| 久久久久久久91| 国产欧美韩日| 欧美一区二区精品| 夜夜精品视频| 欧美日韩另类视频| 日韩一级在线观看| 亚洲日本电影| 男人插女人欧美| 亚洲国产精品传媒在线观看| 亚洲影院色在线观看免费| 国产精品一区二区久久精品| 亚洲欧美日本在线| 性欧美xxxx大乳国产app| 亚洲国内精品在线| 久久精品免视看|