/* Pete Hriso Assignment #6 a */ #include "rmannotes.sl" surface phriso1(float Ks=.5, Kd=.5, freq = 6, fuzz = .05, turbfreq = 2; float Ka=1, roughness=.1; color specularcolor=1) { color paper, ink; float paper_opac, ink_opac; float ss, tt, x, y; color black = color (0, 0, 0); color white = color (1, 1, 1); color violet4 = color (.815, .125, .564); point center, PP; float col, row, radius, ring, box, box1, box2, box3; float d, pixelsize, twice, scale, turb ; float width, left, top, bottom, right; point Nf, V, noi; float noifreq = 5; float noiscale = 0.4; PP = transform("shader", P) * turbfreq; pixelsize = sqrt(area(PP)); twice = pixelsize * 2; turb = 0; for (scale = 1; scale > twice; scale /= 2) turb += abs(noise(PP / scale) - 0.5) * scale; turb = turb * 2; /* init */ paper = black; paper_opac = 0; Nf = faceforward( normalize(N), I); V = -normalize(I); PP= transform("shader", P) * 2; PP = P * 2; PP = PP + (noise(PP) * 2 - 1) * .5; y = repeat(ycomp(PP), 3); x = repeat(xcomp(PP), 3); /* perturb ss, tt */ col = whichtile(s, freq); row = whichtile(t, freq); noi = noise(col * 5 + 0.5, row * 5 + 0.5); ss = repeat(x, freq) + udn(noi * 1183, -0.35, 0.35); tt = repeat(y, freq) + udn(noi * 999, -0.35, 0.35); /* ring */ center = (0.5, 0.5, 0); radius = .35; width = 0.23; d = distance(center, (ss, tt, 0)); ring = pulse(radius - width / 2, radius + width / 2, fuzz, d); /* first box */ left = .3; right = .7; top = 0; bottom = 1; box2= pulse(left, right, fuzz, ss) * pulse(top, bottom, fuzz, tt); box3= pulse(left +.1, right - .1, fuzz, ss) * pulse(top + .1, bottom - .1, fuzz, tt); box = union(difference(box2,box3), difference(box3,box2)); /* second box */ left = 0; right = 1; top = .3; bottom = .7; box2= pulse(left, right, fuzz, ss) * pulse(top, bottom, fuzz, tt); box3= pulse(left +.1, right - .1, fuzz, ss) * pulse(top + .1, bottom - .1, fuzz, tt); box1 = union(difference(box2,box3), difference(box3,box2)); /* union of boxes and ring */ if (udn(noi * 444, 0, 567) > 0) { ink= color "hsv" (udn(noi * 8181, 0, 1), .5, 1); ink_opac = union(difference(box1, ring), difference(box, ring)); paper = mix(paper, ink, ink_opac); paper_opac = union(ink_opac, paper_opac); } /* plastic illum for all layers */ paper = paper * Ka * ambient() + paper * Kd * diffuse(Nf) + specularcolor * Ks * specular(Nf, V, roughness); /* output */ Oi = paper_opac; Ci = paper_opac * paper; }