# 加载中...

• 博客等级：
• 博客积分：0
• 博客访问：196,040
• 关注人气：46
• 获赠金笔：0支
• 赠出金笔：0支
• 荣誉徽章：

## 柏林噪声

(2012-08-08 11:21:50)

### 杂谈

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

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

ft = x * 3.1415927
f = (1 - cos(ft)) * .5

return  a*(1-f) + b*f end of function

V0 =点
V1
V2 = B
V3 = b 之后点
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

function Noise(x)
.
.
end function

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

2维光滑噪声

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

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
end function

2维柏林噪声伪

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
end function

2维

3维

4维

0

• 评论加载中，请稍候...

发评论

以上网友发言只代表其个人观点，不代表新浪网的观点或立场。

< 前一篇2012年08月08日

新浪BLOG意见反馈留言板　电话：4000520066 提示音后按1键（按当地市话标准计费）　欢迎批评指正

新浪公司 版权所有