float square(float x, y, minx, maxx, miny, maxy, taper) { return smoothstep(minx, minx + taper, x) * (1 - smoothstep(maxx, maxx + taper, x)) * smoothstep(miny, miny + taper, y) * (1 - smoothstep(maxy, maxy + taper, y)); } surface staggeredcolor(float Ka = 1, Kd = 0.5, min_s = 0.05, max_s = 0.95, min_t = 0.05, max_t = 0.95, fuzz = 0.1, s_repeats = 3, t_repeats = 3; color color1 = color(1,0,0), color2 = color(1,1,0)) { color ambientcolor, diffusecolor, surfcolor; normal n = normalize(N); normal nf = faceforward(n, I); Oi = Os; ambientcolor = Ka * ambient(); diffusecolor = Kd * diffuse(nf); float ss = mod(s * s_repeats, 1); float tt = mod(t * t_repeats, 1); float row = floor(t * t_repeats); /* The row is an "even" number */ if(mod(row, 2) == 0) ss = mod((s + 0.5) * s_repeats, 1); float blend = square(ss, tt, min_s, max_s, min_t, max_t, fuzz); surfcolor = mix(color1, color2, blend); Ci = Oi * Cs * surfcolor * (ambientcolor + diffusecolor); }