-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspd.sl
35 lines (31 loc) · 890 Bytes
/
spd.sl
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
surface
spd (float Ka = 1;
float Kd = .5;
float Ks = .5;
float roughness = .1;
color specularcolor = 1;
float reflected = 0.;
float transmitted = 0.;
float index = 1.0;)
{
point Nf;
color r = 0, tr = 0;
point Rfldir, Rfrdir;
point IN;
Nf = faceforward (normalize(N),I);
if (reflected > .001 || transmitted > .001) {
/* Construct a normalized incident vector */
IN = normalize (I);
if (reflected > .001) {
Rfldir = normalize(reflect(IN, Nf));
r = reflected * trace (P, Rfldir);
}
if (transmitted > .001) {
Rfrdir = normalize(refract(IN, Nf, index));
tr = transmitted * trace (P, Rfrdir);
}
}
Oi = Os;
Ci = Os * ( Cs * (Ka*ambient() + Kd*diffuse(Nf) + r + tr) +
specularcolor * Ks*specular(Nf,-normalize(I),roughness));
}