-
Notifications
You must be signed in to change notification settings - Fork 5
/
FBM_Noise.osl
73 lines (63 loc) · 1.82 KB
/
FBM_Noise.osl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Ported to OSL and compiled by Mads Drøschler
// 5.6.2018
// License CC3.0
float random (vector st)
{
return mod((sin(dot(st,vector(12.9898,78.233,0)))*43758.5453123),1.0);
}
float Noise (vector st)
{
vector i = floor(st);
vector f = mod(st,1.0);
float a = random(i);
float b = random(i + vector(1.0,0.0,0));
float c = random(i + vector(0.0,1.0,0));
float d = random(i + vector(1.0,1.0,0));
vector u = f*f*(3.0-2.0*f);
return mix(a,b,u[0])+(c-a)*u[1]*(1.0-u[0])+(d-b)*u[0]*u[1];
}
float fbm (vector st, int Octaves)
{
float value = 0.;
float amplitude = 1.;
float frequency = 2.;
for (int i = 0; i < Octaves; i++)
{
value += amplitude * Noise(st);
st *= 3.;
amplitude *= .5;
}
return value;
}
float fbmWarp2 ( vector st, vector q, vector r, float t, int Octaves)
{
q[0] = fbm(st + vector(0.0,0.0,0.0),Octaves);
q[1] = fbm(st + vector(5.2,1.3,0.0), Octaves);
r[0] = fbm( st + 4.0*q + vector(1.7,9.2,0.0) + 0.7*t,Octaves);
r[1] = fbm( st + 4.0*q + vector(8.3,2.8,0.0) + 0.7*t,Octaves);
return fbm( st + 4.0*r,Octaves);
}
vector hsb2rgb(vector c )
{
vector rgb = clamp(abs(mod(c[0]*6.0+vector(0.0,4.0,2.0),6.0)-3.0)-1.0,0.0,1.0 );
rgb = rgb*rgb*(3.0-2.0*rgb);
return c[2] * mix(vector(1.0,0.0,0.0), rgb, c[1]);
}
shader FBM_Noise(
point Po = P,
float Time = 1.0,
int Octaves = 16,
output vector Out = 0,
)
{
point Pos = Po;
vector st = Pos;
vector Col = vector(0);
vector q = vector(0);
vector r = vector(0);
float height = fbmWarp2 ( st*10., q, r,Time,Octaves);
Col += hsb2rgb(vector(0.3,1.0 - (0.5*sin(Time) + 0.5),height));
Col = mix(Col, hsb2rgb(vector(0.0,q[0],0.2 + (0.2*sin(0.7*Time) + 0.2))), length(q));
Col = mix(Col, hsb2rgb(vector(0.58,r[0],0.0 + (0.25*sin(0.3*Time) + 0.25))), r[1]);
Out = Col;
}