一些随机噪波函数(随时更新)

汇总自各网站(随时更新)

Gradient noise

wiki:https://en.wikipedia.org/wiki/Gradient_noise

Perlin noise

伪代码:

<span style="font-size:14px;">// Function to linearly interpolate between a0 and a1
 // Weight w should be in the range [0.0, 1.0]
 function lerp(float a0, float a1, float w) {
     return (1.0 - w)*a0 + w*a1;
 }
 
 // Computes the dot product of the distance and gradient vectors.
 function dotGridGradient(int ix, int iy, float x, float y) {
 
     // Precomputed (or otherwise) gradient vectors at each grid point X,Y
     extern float Gradient[Y][X][2];
 
     // Compute the distance vector
     float dx = x - (double)ix;
     float dy = y - (double)iy;
 
     // Compute the dot-product
     return (dx*Gradient[iy][ix][0] + dy*Gradient[iy][ix][1]);
 }
 
 // Compute Perlin noise at coordinates x, y
 function perlin(float x, float y) {
 
     // Determine grid cell coordinates
     int x0 = (x > 0.0 ? (int)x : (int)x - 1);
     int x1 = x0 + 1;
     int y0 = (y > 0.0 ? (int)y : (int)y - 1);
     int y1 = y0 + 1;
 
     // Determine interpolation weights
     // Could also use higher order polynomial/s-curve here
     float sx = x - (double)x0;
     float sy = y - (double)y0;
 
     // Interpolate between grid point gradients
     float n0, n1, ix0, ix1, value;
     n0 = dotGridGradient(x0, y0, x, y);
     n1 = dotGridGradient(x1, y0, x, y);
     ix0 = lerp(n0, n1, sx);
     n0 = dotGridGradient(x0, y1, x, y);
     n1 = dotGridGradient(x1, y1, x, y);
     ix1 = lerp(n0, n1, sx);
     value = lerp(ix0, ix1, sy);
 
     return value;
 }</span>
wiki:https://en.wikipedia.org/wiki/Perlin_noise

Simplex noise


wiki:https://en.wikipedia.org/wiki/Simplex_noise


OpenSimplex noise

wiki:https://en.wikipedia.org/wiki/OpenSimplex_noise



Value noise

wiki:https://en.wikipedia.org/wiki/Value_noise

Pink noise

wiki:https://en.wikipedia.org/wiki/Pink_noise

Worley noise

wiki:http://blog.csdn.net/wolf96?viewmode=contents

Others

一个随机数算法

  1. <span style="font-size:14px;">float scale = 0.5;  
  2. float magic = 3571.0; float2 random = ( 1.0 / 4320.0 ) * position +     float2( 0.25, 0.0 ); random = frac( dot( random * random, magic ) );  
  3. random = frac( dot( random * random, magic ) );  
  4. return -scale + 2.0 * scale * random;</span>  


一个棋盘算法

in unity

  1. <span style="font-size:14px;">                float scale = 0.25;  
  2.                 float2 positionMod = float2(uint2(i.uv_MainTex*10) & 1);  
  3.                 return (-scale + 2.0 * scale * positionMod.x) *  
  4.                     (-1.0 + 2.0 * positionMod.y);  
  5. </span>  
  1. float scale = 0.25;  
  2. float2 positionMod = float2(uint2(i.uv_MainTex*10) & 1);  
  3. return (-scale + 2.0 * scale * positionMod.x) *  
  4.     (-1.0 + 2.0 * positionMod.y) +  
  5.     0.5 * scale * (-1.0 + 2.0 * _frameCountMod);//<span style="font-size:14px;"></span><pre name="code" class="cpp">//_frameCountMod参数实现对棋盘的控制  


another
  1. <span style="font-size:14px;">float scale = 0.25;  
  2. float2 positionMod = float2( uint2( sv_position ) & 1 );  
  3. return ( -scale + 2.0 * scale * positionMod.x ) *  
  4.     ( -1.0 + 2.0 * positionMod.y );  
  5. </span>  





InterleavedGradient Noise

Experimentingand optimizing a noise generator, we found a noise function that we couldclassify as being half way between dithered and random, and that we calledInterleavedGradient Noise:

float3 magic = float3( 0.06711056, 0.00583715,52.9829189 );

return -scale + 2.0 * scale * frac( magic.z * frac(dot( sv_position, magic.xy ) ) );

Used to rotatethe samples:

sincos( 2.0 * PI *InterleavedGradientNoise( sv_position),rotation.y,rotation.x );

float2x2 rotationMatrix = { rotation.x, rotation.y,-rotation.y, rotation.x};

...

float2 sampleOffset= mul( offsets[i], rotationMatrix );

Best of both worlds:
Produces a rich range of values, similar to randomnoise
Produces temporally coherent results, similar todithered schemes

This noiseproduces interleaved gradients
This meansthat objects moving at a constant speed will rotate the samples smoothly
To make itwork for static images, scroll the horizontal position
sv_position.x += scale * time

Snippet:

{ -0.7071,  0.7071 },

{ -0.0000,-0.8750},

0.5303,  0.5303 },

{ -0.6250,-0.0000},

0.3536, -0.3536 },

{ -0.0000, 0.3750 },

{ -0.1768, -0.1768 },

0.1250,  0.0000 },









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值