forked from varkenvarken/osl-shaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stones.osl
55 lines (51 loc) · 1.47 KB
/
stones.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
shader stones(
point p = P,
vector Scale = 1,
float w = 0.02,
float s = 2,
output float Fac = 0
){
point Pos = p * Scale;
float bot = floor(Pos[1]-1)+cellnoise(Pos[1]-1);
float lev = floor(Pos[1])+cellnoise(Pos[1]);
float top = floor(Pos[1]+1)+cellnoise(Pos[1]+1);
if( Pos[1]<lev ){
Pos[0] += s*cellnoise(Pos[1]);
}else{
Pos[0] += s*cellnoise(Pos[1]+1);
}
float left = floor(Pos[0]-1)+cellnoise(Pos[0]-1);
float mid = floor(Pos[0])+cellnoise(Pos[0]);
float right = floor(Pos[0]+1)+cellnoise(Pos[0]+1);
if(
((Pos[0] > left+w) && ( Pos[0] < mid - w ))
||
((Pos[0] > mid+w ) && ( Pos[0] < right - w))
){
if(
((Pos[1] > bot+w) && ( Pos[1] < lev - w ))
||
((Pos[1] > lev+w ) && ( Pos[1] < top - w))
){
int stoneindex=0;
float seeda = left;
float seedb = bot;
float bounda = mid;
float boundb = lev;
if( Pos[0]>mid ){ stoneindex += 2; seeda = mid; bounda = right; }
if( Pos[1]>lev ){ stoneindex += 1; seedb = lev; boundb = top; }
int pattern = (int)floor(cellnoise(seeda,seedb)*4);
if( pattern == 0 ){
// horizontally halved
float nlev = (seedb + boundb)/2;
if( (Pos[1] > nlev - w) && (Pos[1] < nlev + w) ){
Fac = 0;
} else {
Fac = cellnoise(vector(seeda,seedb,Pos[1]>nlev));
}
} else {
Fac = cellnoise(vector(seeda,seedb,-1));
}
}
}
}