surface smoothcolor3(float Ka = 1, Kd = 0.5, min_s = 0.1, max_s = 0.8, min_t = 0.1, max_t = 0.8, fuzz = 0.1; color color1 = color(1,0,0), color2 = color(1,1,0)) { normal nf, n; color ambientcolor, diffusecolor, surfcolor; /* STEP 1 - make a copy of the surface normal one unit in length */ n = normalize(N); nf = faceforward(n, I); /* STEP 2 - set the apparent surface opacity */ Oi = Os; /* STEP 3 - calculate the lighting components */ ambientcolor = Ka * ambient(); diffusecolor = Kd * diffuse(nf); /* STEP 4 - calculate the color blending factor and mix the colors appropriately */ float blend = smoothstep(min_s, min_s + fuzz, s) * (1 - smoothstep(max_s, max_s + fuzz, s)) * smoothstep(min_t, min_t + fuzz, t) * (1 - smoothstep(max_t, max_t + fuzz, t)); surfcolor = mix(color1, color2, blend); /* STEP 5 - calculate the apparent surface color */ Ci = Oi * Cs * surfcolor * (ambientcolor + diffusecolor); }