/* * metallic.sl * * Lawson Wade * * A surface shader that simulates a shiny metal surface * using either a texture map (environmental mapping), or, * if no texture map is specified, a noisy index into * a color spline. */ #include "rmannotes.sl" #include "colors.sl" surface metallic( string texturemap = ""; float Ka = 1, Ks = 1, Kr = 1, roughness = 0.1; ) { point Nf, V; point R; color surface_color, surface_opac; color layer_color; float ss, tt; float phi, theta; float d; Nf = faceforward(normalize(N), I); V = normalize(I); R = reflect(V, Nf); if (texturemap != "") { /* index into texturemap */ R = transform("world", point "world" (0, 0, 0) + R); layer_color = Kr * color environment(texturemap, R); } else { R = transform("world", point "world" (0, 0, 0) + R); R = normalize(R); phi = acos(R . point "world" (0, 1, 0)); theta = atan(zcomp(R), xcomp(R)); phi = phi / PI; theta = mod(theta + 2 * PI, 2 * PI) / (2 * PI); d = noise(phi * 13.2173, theta * 7.9351); d = clamp(d, 0, 1); layer_color = spline(phi, Red, Red, White, White, Blue, Blue); /* Tan2, Tan2, Tan2, Tan2, Tan2, Black, Black, Black, Tan2, Red3, Yellow2, AntiqueWhite3, Black, Black, Black, Red3, Black, Blue, OrangeRed2, Tan2, White, Black, Black, Red3, Black, Black, AntiqueWhite3, Red3, White, Black, Black, Black, Black); */ } surface_opac = Os; surface_color = Cs * (Ka * ambient() + Ks * specular(Nf, -V, roughness) + layer_color); Oi = surface_opac; Ci = surface_opac * surface_color; }