/* pattern.sl * * creates a single tile with a horizontal yellow bar crossing * a vertical white bar on whatever the surface color is. * */ #include "rmannotes.sl" /* #define pulse(a,b,fuzz,x) (smoothstep((a)-0.5*(fuzz),(a)+0.5*(fuzz),(x)) - \ smoothstep((b)-0.5*(fuzz),(b)+0.5*(fuzz),(x))) */ surface pattern( float Ks = .5, Kd = .5, Ka = 1, roughness = .1; color specularcolor = 1) { point Nf, V; color surface_color, layer0_color, layer1_color, layer2_color; float surface_opac, layer0_opac, layer1_opac, layer2_opac; float fuzz = 0.001; float ss, tt, freq; float x, y, r, theta; float row, col; float d, d0, d1, d2, d3; float hue, hue1, hue2, hue3; float arc, arc1, arc2, arc3; /* compute the large circle layer */ freq = 2; ss = repeat(s, freq); tt = repeat(t, freq); d0 = distance((0, 0, 0), (ss, tt, 0)); d1 = distance((0, 1, 0), (ss, tt, 0)); d2 = distance((1, 0, 0), (ss, tt, 0)); d3 = distance((1, 1, 0), (ss, tt, 0)); d = min(min(d0, d1), min(d2, d3)); layer0_opac = pulse(0.484, 0.505, fuzz, d); layer0_color = color "hsv" (0.0, 0.8, 0.8); /* compute the small circle layer */ freq = 4; ss = repeat(s, freq); tt = repeat(t, freq); d = distance((0.5, 0.5, 0), (ss, tt, 0)); layer1_opac = pulse(0.46, 0.52, fuzz, d); layer1_color = color (0.9, 0.9, 0.9); /* compute the arc layer */ freq = 8; ss = repeat(s, freq); tt = repeat(t, freq); if (even(freq)) { col = whichtile(s, freq); row = whichtile(t, freq); } else { col = whichtile(s, freq); row = whichtile(t, freq); } /* upper left arc */ topolar2d(ss, tt, r, theta); arc1 = pulse(0.4, 0.6, fuzz, r); hue1 = (theta + PI) / (2 * PI); /* lower left arc */ topolar2d(ss, 1.0 - fuzz - tt, r, theta); arc2 = pulse(0.4, 0.6, fuzz, r); hue2 = (theta + PI) / (2 * PI); /* lower right arc */ topolar2d(1.0 - fuzz - ss, 1.0 - fuzz - tt, r, theta); arc3 = pulse(0.4, 0.6, fuzz, r); hue3 = (theta + PI) / (2 * PI); /* combine the arcs */ if (arc1 + arc2 + arc3 > 0.0) hue = (hue1 * arc1 + hue2 * arc2 + hue3 * arc3) / (arc1 + arc2 + arc3); else hue = 0.0; /* color and opacity for arc layer */ layer2_opac = union(union(arc1, arc2), arc3); layer2_color = color "hsv" (hue, 1, 1); /*** background layer ***/ Nf = faceforward(normalize(N), I); V = normalize(-I); surface_opac = union(layer0_opac, union(layer1_opac, layer2_opac)); surface_color = Os * (Cs * (Ka * ambient() + Kd * diffuse(Nf)) + specularcolor * Ks * specular(Nf, V, roughness)); /* combine the layers in overlapping fashions */ if (even(row) && odd(col)) { /* add the arc layer */ surface_color = mix(surface_color, layer2_color, layer2_opac); /* add the large circle layer */ surface_color = mix(surface_color, layer0_color, layer0_opac); /* add the small circle layer */ surface_color = mix(surface_color, layer1_color, layer1_opac); } else if (odd(row) && even(col)) { /* add the large circle layer */ surface_color = mix(surface_color, layer0_color, layer0_opac); /* add the small circle layer */ surface_color = mix(surface_color, layer1_color, layer1_opac); /* add the arc layer */ surface_color = mix(surface_color, layer2_color, layer2_opac); } else { /* add the small circle layer */ surface_color = mix(surface_color, layer1_color, layer1_opac); /* add the arc layer */ surface_color = mix(surface_color, layer2_color, layer2_opac); /* add the large circle layer */ surface_color = mix(surface_color, layer0_color, layer0_opac); } /* output */ Oi = surface_opac; Ci = surface_opac * surface_color; }