-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathRivets.osl
43 lines (39 loc) · 925 Bytes
/
Rivets.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
int incircle(float px, float py, float cx, float cy, float r){
return hypot(px-cx,py-cy)<r;
}
shader rivets(
point Pos=P,
int Rivets=5,
float Size=0.05,
float Height=0.05,
float PosVariance=0,
float Wear=0,
output float Fac=0,
output float Bump=0,
output float Gloss=0.2
){
point p = Pos + PosVariance*(vector)noise(Pos*20);
float cx,cy,x=p[0],y=p[1];
x=p[0]>0.5?1-p[0]:p[0];
y=p[1]>0.5?1-p[1]:p[1];
float d=1.0/(2.0*Rivets);
for(int c=0; c<Rivets; c++){
cx = (float)c/Rivets + d;
cy = d;
if(incircle(x,y, cx,cy, Size)){
Fac = 1;
break;
}
cy = (float)c/Rivets + d;
cx = d;
if(incircle(x,y, cx,cy, Size)){
Fac = 1;
break;
}
}
if(Fac>0){
float dist=hypot(x-cx, y-cy)/Size;
Bump = Height * sqrt(1 - dist*dist) + Wear * noise("uperlin", p);
Gloss = 0.2 * (1 - Wear * (1 - dist));
}
}