surface
bombed(float Ks=.5, Kd=.5, Ka=1, roughness=.1;
color specularcolor=1;
float Hfreq = 3, Vfreq = 3)

#define udn(x,lo,hi) (smoothstep(.25, .75, noise(x)) * ((hi) - (lo)) + (lo))
#define whichtile(x,freq) (floor((x) * (freq)))
#define pulse(a,b,fuzz,x) (smoothstep((a)-(fuzz),(a),(x)) - \
smoothstep((b)-(fuzz),(b),(x)))
{
normal Nf;
vector V;
color Cfg = (1,1,1);
color Cbg = (0,0,0);
float ss, tt, row, col;
float x, y, radius, noiz, z, offset;
float value = 0;
float matte = 0;
point center;

/* tile the surface & find row, colum*/

ss = mod(s*Hfreq,1.0);
tt = mod(t*Vfreq,1.0);
row = whichtile(s,Hfreq);
col = whichtile(t,Vfreq);

/* move center randomly and adjust radius*/

x = udn((row+col+.46),(-0.1),(0.1));
y = udn((row+col+1.54),(-0.1),(0.1));

center = point ( 0.5 + x, 0.5 + y,0);
radius = 0.4 - max (x,y);

/* Randomly make a matte of circles or squares & then */
/* Randomly make a smaller circle or square inside */
/* only if figure is drawn */

for (z = 1; z < 3 ;z += 1){

noiz = noise (col*10*z+0.5,row*10*z+0.5);

if (noiz<0.55){
if (noiz<0.45){

/* generate circle */
value = 1 -
smoothstep((radius-0.05),(radius+0.05),
distance (point (ss,tt,0), center));
}
else {

/* generate square */
value = smoothstep ((0.45+-radius),
(0.55-radius),min(ss-x,tt-y))
* (1 - smoothstep((0.45+radius),
(0.55+radius),max(ss-x,tt-y)));
}
/* resize radius for figure inside figure*/
radius = radius/2;
}
else value = 0;

if (z == 2) matte = 1 - value;
else matte = value;

/* end loop if not inside figure */
if(value<1.0){z=3;}
}

/* define three colors */
color c1 = (0.528,0.387,0.134);
color c2 = (0.733,1.0,0.76);
color c3 = (0.724,0.178,0.259);

/* calculate background line pattern with noise */
noiz = (noise (s*Vfreq,t*Hfreq) * 0.1);
offset = (x * pulse (0.5,1.0,0.5,tt)) + (noiz * (1-pulse (0.5,1.0,0.5,tt)));
value = pulse (0.5+offset, 0.6+offset, 0.1, ss);
offset = (y * pulse (0.5,1.0,0.5,ss)) + (noiz * (1-pulse (0.5,1.0,0.5,ss)));
value = clamp ((value + pulse (0.5+offset, 0.6+offset, 0.1, tt)),(0.0),(1.0));

Cbg = spline (value, c1, c1, c2, c3, c3);

/* make Foreground color to fill squares & circles */
noiz = udn ((row*col*Hfreq*Vfreq+0.5), 0.1, 0.8);
Cfg = spline (noiz, c3, c3, c2, c1, c1);

/* if (noiz<0.45) Cfg = c1;
else if (noiz<0.55) Cfg = c2;
else Cfg = c3;*/

Nf = faceforward( normalize(N), I );
V = -normalize(I);

Oi = Os;
/* Ci = Os * ( Csnew * (Ka*ambient() + Kd*diffuse(Nf)) +
specularcolor * Ks * specular(Nf,V,roughness) );*/

Ci = mix(Cbg, Cfg, matte);
}
[BACK]