surface diffuse_test(float Kd = 1; output varying float __shadow = 0; output varying float __inshadow = 0; output varying color __no_shadow_ci) { color surfcolor = 1; normal n = normalize(N); vector nf = faceforward(n, I); Oi = Os; color diffusecolor = 0; float shad = 0; color totalLightColor = 0; illuminance(P, n, PI) { //Query the current light for the value //of it's output parameter if(lightsource("__inshadow",shad) == 1) __shadow += shad; // Same again for the light color that was //not darkened by a shadow color cl = 0; if(lightsource("__cl_noshadow", cl) == 1) totalLightColor += cl * normalize(L).n; //Are we in the "self shadowing" part //of the surface?? float dot = n.normalize(-L); if(dot >= 0) __shadow = 1; diffusecolor += Cl * normalize(L).n; } diffusecolor *= Kd; Ci = Oi * Cs * surfcolor * diffusecolor; __no_shadow_ci = Oi * Cs * surfcolor * totalLightColor * Kd; }