surface carpaint_basic( float Kd = 1; float shellac = 0.6; float shellacOffset = 0.01; color upperClamp = 1.2; color inputcolor = color (0.337,0.521,0.933);) { //set clamping values color minC = color(0,0,0); color maxC = color(1,1,1); //set up normals, vectors etc normal n = normalize(N); vector i = normalize(-I); normal nf = faceforward(n, I); float fr = abs(n.normalize(I)); //calc facing ratio color diffuseValue = Kd * diffuse(nf); //add in some diffuse vector rRay = reflect(i*N,N); //get reflected vector color calcEnvColor = environment("uffizi.tex", rRay); //use the env function to calc env reflection color envColor = color clamp(color calcEnvColor, minC, upperClamp); //clamp it color calcShellac = (shellac * envColor * (1-fr)) - shellacOffset; //shellac layer calc color finalShellac = color clamp(color calcShellac, minC, maxC); //clamp it Oi = Os; Ci = Oi * Cs * inputcolor * fr * diffuseValue + finalShellac; //final maths }