surface smoothcolor2(float Ka = 1, Kd = 0.5, min = 0.1, max = 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, min + fuzz, s) * (1 - smoothstep(max, max + fuzz, s)); surfcolor = mix(color1, color2, blend); /* STEP 5 - calculate the apparent surface color */ Ci = Oi * Cs * surfcolor * (ambientcolor + diffusecolor); }