/* Eric Zimmerman description: This shader was used for the surface of the fish in my animation. It creates a stylized scale pattern and bricks it out using the floor function. parameters: The "freq" parameter controls the frequency (and thus size) of the scale pattern. The other parameters are standard plastic shader variables. */ #include "rmannotes.sl" surface ex2(float Ka = .8, Kd = .6, Ks = .9, roughness = .05, freq = 2; color specularcolor = 1) { color paper, ink; float opac; float tile_s, tile_t; float tile_i, tile_j; float fuzz, lw; float x, d, r, circ1, circ2; float d2, d3, line1, line2, line3, lines; point center, Nf, V; float box; Nf = faceforward(normalize(N), I); V = normalize(-I); /* perform bricking function */ tile_i = floor (s * freq); tile_j = floor (t * freq); x = mod(tile_j, 2); if (x == 1) s = s + .25; tile_s = repeat (s, freq); tile_t = repeat (t, freq); /* draw light blue half-circle */ paper = color (.042, .17, .161); fuzz = .051; r = .5; center = (.1, .5, 0); d = distance (center, (tile_s, tile_t, 0)); circ2 = 1 - smoothstep (r - fuzz, r + fuzz, d); box = intersection (pulse (tile_s, .05, .95, fuzz), pulse (tile_t, .05, .95, fuzz)); ink = color (.110, .326, .451); opac = intersection (circ2, box); paper = mix (paper, ink, opac); /* draw pale yellow crescent as the intersection of two circles */ fuzz = .01; r = .45; center = (.5, .5, 0); d = distance (center, (tile_s, tile_t, 0)); circ1 = 1 - smoothstep (r - fuzz, r + fuzz, d); r = .46; center = (.35, .5, 0); d = distance (center, (tile_s, tile_t, 0)); circ2 = 1 - smoothstep (r - fuzz, r + fuzz, d); ink = color (.775, .8, .556); opac = difference (circ1, circ2); paper = mix (paper, ink, opac); /* draw three violet lines radiating out from left */ fuzz = .06; lw = .03; d = ptlined((.08, .5, 0), (.4, .5, 0), (tile_s, tile_t, 0)); line1 = 1-smoothstep(lw - fuzz, lw + fuzz, d); d2 = ptlined((.08, .68, 0), (.35, .78, 0), (tile_s, tile_t, 0)); line2 = 1-smoothstep(lw - fuzz, lw + fuzz, d2); d3 = ptlined((.08, .32, 0), (.35, .22, 0), (tile_s, tile_t, 0)); line3 = 1-smoothstep(lw - fuzz, lw + fuzz, d3); lines = union (line2, line3); ink = color (.190, .015, .230); opac = union (lines, line1); opac *= .75; paper = mix (paper, ink, opac); Ci = Oi * (paper * (Ka * ambient() + Kd * diffuse(Nf)) + specularcolor * Ks * specular(Nf, V, roughness)); }