/* cubes.sl */ #include "rmannotes.sl" surface cubes(float Ka = 0.2, Kd = 0.4, Ks = 0.6, roughness = 0.1, r = 0.5, freq = 6) { color surface_color=1, layer_color, layer_opac; normal Nf = faceforward(normalize(N), I); vector V = -normalize(I); point PP = transform("shader", P); /* transform P to shader space */ float x = xcomp(PP), y = ycomp(PP), z = zcomp(PP); float xx = repeat(x,freq); float yy = repeat(y,freq); float zz = repeat(z,freq); /* float d = max(abs(xx)-r, abs(yy)-r, abs(zz)-r); */ float d = (xx-0.5)*(xx-0.5)+(yy-0.5)*(yy-0.5)+(zz-0.5)*(zz-0.5) - r*r; if(d>0) { surface_color = color (1,0,0); } else { surface_color = color (0,0,1); } surface_color = surface_color * (Ka * ambient() + Kd * diffuse(Nf)) + Ks * specular(Nf, V, roughness); /* output */ Oi = Os; Ci = Os * surface_color; }