/* * stripes.sl -- Surface shader for a stripe pattern. * * DESCRIPTION: * Makes a stripe pattern consisting of two colors on any surface. * A very simple shader. * * PARAMETERS: * numhori number of horizontal stripes * numvert number of vertical stripes * c1 the color of one stripe * c2 the color of the other stripe * Ka,Kd,Ks the usual * roughness roughness of surface * specularcolor used for specular reflection * * AUTHOR: written by Eric Heng Chih Lee, cs184-av * * */ surface stripes (float numhori=4; float numvert=4; color c1 = color "rgb" (0.7,0.2,0.3); color c2 = color "rgb" (0.3,0.7,0.1); float Ka=0.5; float Kd=0.3; float Ks=0; float roughness=0.1; color specularcolor=1;) { normal Nf; color Ct; float chori,cvert; float rhori,rvert; chori = 2.0/numhori; cvert = 2.0/numvert; rhori = chori/30.0; rvert = cvert/30.0; if ( ((mod((s+1.0),chori) > (0.5*chori-rhori)) && (mod((s+1.0),chori) < (0.5*chori+rhori))) || ((mod((t+1.0),cvert) > (0.5*cvert-rvert)) && (mod((t+1.0),cvert) < (0.5*cvert+rvert))) ) Ct = c1; else Ct = c2; Nf = faceforward (normalize(N),I); Oi = Os; Ci = Os * Ct*(Ka*ambient()+Kd*diffuse(Nf)+ specularcolor*Ks*specular(Nf,-normalize(I),roughness)); }