#include "rmannotes.sl" surface experiment(float tile = 4, radius = 0.35, width = 0.25, pivot = 0.5; float Ka = 0.5, Kd = 0.5; float Ks = 0.5, roughness = 0.009; color specularcolor = 1.0) { color paper, ink, ink1; float ss, tt,w, x, ink_opac, paper_opac; float fuzz = 0.01; float c1, c2, c3, c4, d; point center, Nf, V; /* init */ paper = color (t, s, .6); paper_opac = 0.2; Nf = faceforward(normalize(N), I); V = -normalize(I); center = (.6, .4, 0); ss = s; tt = t; s = repeat(s, tile); t = repeat(t, tile); d = distance(center, (s, t, 0)); /* layer 1 */ ink_opac = pulse(radius - width /2, radius + width / 2, fuzz, d); ink = color (s, t, 1); paper = mix(paper, ink, ink_opac); s = ss; t = tt; ink1 = color (s, t, 0); rotate2d(s, t, radians(90), pivot, pivot, ss,tt); ss = repeat(ss, tile); tt = repeat(tt, tile); s = repeat(s, tile); t = repeat(t, tile); c3 = smoothstep(ss-fuzz, ss+fuzz, tt); c4 = smoothstep(w-fuzz, w+fuzz, x); /* w and x work by magic! */ c1 = smoothstep(t + 0.2-fuzz, t + 0.2 + fuzz,s); c2 = smoothstep(tt + 0.2-fuzz, tt + 0.2 + fuzz,ss); /* layer 2 */ ink_opac = union(intersection(c1,c2),intersection(c3,c4)); paper_opac = union(paper_opac, ink_opac); paper = paper * Ka * ambient() + paper * Kd * diffuse(Nf) + specularcolor * Ks * specular(Nf, V, roughness); Ci = paper * mix(ink, ink1, ink_opac) * paper_opac; }