汇总自各网站(随时更新)
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_noiseSimplex 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_noiseWorley noise
wiki:http://blog.csdn.net/wolf96?viewmode=contents
Others
一个随机数算法
- <span style="font-size:14px;">float scale = 0.5;
- float magic = 3571.0; float2 random = ( 1.0 / 4320.0 ) * position + float2( 0.25, 0.0 ); random = frac( dot( random * random, magic ) );
- random = frac( dot( random * random, magic ) );
- return -scale + 2.0 * scale * random;</span>
一个棋盘算法
in unity
- <span style="font-size:14px;"> float scale = 0.25;
- float2 positionMod = float2(uint2(i.uv_MainTex*10) & 1);
- return (-scale + 2.0 * scale * positionMod.x) *
- (-1.0 + 2.0 * positionMod.y);
- </span>
- float scale = 0.25;
- float2 positionMod = float2(uint2(i.uv_MainTex*10) & 1);
- return (-scale + 2.0 * scale * positionMod.x) *
- (-1.0 + 2.0 * positionMod.y) +
- 0.5 * scale * (-1.0 + 2.0 * _frameCountMod);//<span style="font-size:14px;"></span><pre name="code" class="cpp">//_frameCountMod参数实现对棋盘的控制
another
- <span style="font-size:14px;">float scale = 0.25;
- float2 positionMod = float2( uint2( sv_position ) & 1 );
- return ( -scale + 2.0 * scale * positionMod.x ) *
- ( -1.0 + 2.0 * positionMod.y );
- </span>
InterleavedGradient Noise
float3 magic = float3( 0.06711056, 0.00583715,52.9829189 );
return -scale + 2.0 * scale * frac( magic.z * frac(dot( sv_position, magic.xy ) ) );
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 );
{ -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 },