/* * polka-dot - squres distributed on a card evenly. * */ #define blend(a,b,x) ((a) * (1 - (x)) + (b) * (x)) #define repeat(x,freq) (mod((x) * (freq), 1.0)) #define whichtile(x,freq) (floor((x) * (freq))) #define intersection(a,b) ((a) * (b)) #define even(x) (mod((x), 2) == 0) #define pulse(a,b,fuzz,x) (smoothstep((a)-(fuzz),(a),(x)) - \ smoothstep((b)-(fuzz),(b),(x))) surface lab7() { color surface_color, layer_color; color layer_opac; float ss, tt, p; float row; float fuzz = 0.05; /* float freq = 4; */ float freq = 2; surface_color = Cs; /* shift even rows 1/2 tile */ ss = repeat(s, freq); tt = repeat(t, freq); row = whichtile(t, freq); p = ss + 0.5; if (even(row)) ss = mod(p,1); /* squares */ layer_color = color (0.3, 0.0, 0.3); layer_opac = intersection(pulse(0.35, 0.65, fuzz, ss), pulse(0.35, 0.65, fuzz, tt)); surface_color = blend(surface_color, layer_color, layer_opac); /* output */ Ci = surface_color; }