/*
* Polka-dot shader with programmable circle and background color,
* as well as size and spacing of dots.
*/
surface
polkadot (
color backcolor;
color circlecolor;
float spacing = 0.5, radius = .25;
float Ka = 1, Kd = 1)
{
normal Nf;
float space = radius*2+spacing;
float frequency = 10;
float ss = mod(s*frequency, space);
float tt = mod(t*frequency, space);
float center = space/2;
ss = ss - center;
tt = tt - center;
if ((ss*ss + tt*tt) < pow(radius,2)) {
Oi = 1;
Nf = faceforward (normalize(N),I);
Ci = Os * ( circlecolor * (Ka*ambient() + Kd*diffuse(Nf)));
} else {
Oi = 1;
Ci = backcolor;
}
}