/* experimental.sl "improved version" * Tom Suchan Assignment5: 1a. * multi-layer experimental shader * user can set parmeters for the "scale" and backgound wash colors */ #include "rmannotes.sl" surface experimental(string wash = ""; string scale = ""; float Ka = .5, Kd = .5, Ks = 1, roughness = 0.5; color specularcolor = 1;) { color paper, ink, one, two; float paper_opac, ink_opac; float fuzz = 0.05; float ss, tt; point center; float radius, d; float freq = 5; float row, col; float circle1, circle2; point Nf, V; /* paper */ paper_opac = 1; Nf = faceforward(normalize(N), I); V = -normalize(I); if(wash == "RG"){ /* a vertical wash from violet to green */ one = color(1, 0, 1); two = color(0, 1, 0); } else if(wash == "WY"){ /* a horizontal wash from white to yellow */ one = color(1, 1, 1); two = color(1, 1,0); } else{ one = color(.3, .6, .2); two = color(0, 1, .5); } paper = mix(one, two, t ); /* repeat pattern */ tt = repeat(t, freq); ss = repeat(s, freq); col = whichtile(s, freq); row = whichtile(t, freq); rotate2d(s, t, radians(45), 0.5, 0.5, ss, tt); /* vertical bar */ if (even(row) && odd(col) || even(col) && odd(row)) { ink = color (1, 1, 0); ink_opac = pulse(0.35, 0.65, fuzz, ss); paper = mix(paper, ink, ink_opac); /* horizontal bar */ ink = color (1, 0, 0); ink_opac = pulse(0.35, 0.65, fuzz, tt); paper = mix(paper, ink, ink_opac); } else{ /*disk*/ ink = color(0, 0, 1); center = (0.5, 0.5, 0); radius = 0.35; d = distance(center, (ss, tt, 0)); ink_opac = 1 - smoothstep(radius - fuzz, radius + fuzz, d); paper = mix(paper, ink, ink_opac); } /*scale layer*/ radius = 0.45; if(scale == "W") /* white scales */ ink = color(1,1,1); else if(scale == "B") /* black scales */ ink = color(0, 0,0); else ink = color(.3, 1, .4); /* first circle */ ss = repeat(s, freq); tt = repeat(t, freq); center = (.5, .5, 0); d = distance(center, (ss, tt, 0)); circle1 = 1 - smoothstep(radius - fuzz, radius + fuzz, d); /* second circle */ ss = repeat(s, freq); tt = repeat(t, freq); center = (.65, .5, 0); d = distance(center, (ss, tt, 0)); circle2 = 1 - smoothstep(radius - fuzz, radius + fuzz, d); /* use difference of two circles to create moon */ ink_opac = difference(circle1, circle2); paper = mix(paper, ink, ink_opac); /* mini_disc */ radius = 0.10; ink = color(1,1,1); ss = repeat(s, freq); tt = repeat(t, freq); center = (.8, .5, 0); d = distance(center, (ss, tt, 0)); ink_opac = 1 - smoothstep(radius - fuzz, radius + fuzz, d); paper = mix(paper, ink, ink_opac); /* illumination */ paper = paper * Ka * ambient() + paper * Kd * diffuse(Nf) + specularcolor * Ks * specular(Nf, V, roughness); /* output */ Oi = paper_opac; Ci = paper_opac * paper; }