/* ------------------------------------------------------ * polkadot.sl - a polka dot surface shader * * Parameters * Kd, Ka : usual values for diffuse and ambient light * frequency : frequency of dots * radius : size of each dot (ranges from 0.0 to 1.0) * backcolor : the background color * * the color of the polka dots is the current color * - specify in .rib file with: Color [r g b] * * author : nima oreizy (cs184-aj) * date : 11 Nov 1998 * assignment: lab 7 * ------------------------------------------------------ */ surface polkadot ( float Kd = .5, Ka = .4, frequency=.9, radius = 0.8; color backcolor = color(0,0,0);) { float length; float smod = mod(s * frequency, 1); float tmod = mod(t * frequency, 1); smod = smod - 0.5; tmod = tmod - 0.5; length = sqrt(smod*smod + tmod*tmod); if (length < (radius / 2)) Ci = Cs; else Ci = backcolor; Oi = Os; Ci = Oi*Ci*(Ka*ambient() + Kd*diffuse(faceforward(normalize(N),I))); }