|
surface
carpaint_basic(
color inputcolor = color (0.337,0.521,0.933);
float Kd = .6;
float refLevel = 0.8; //reflection layer settings
color upperClamp = 0.9;
float refShellacOffset = 0.0;
color shellacLevel = 0.6; //"shellac" spec settings
float shellacRoughness = 0.2;
float paintChipTiling = 1000; //"rough spec" settings
float specRoughnessMult = 1;
float K_RoughGlowSpecMult = 0.4;)
{
//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
color finalDiffuse = inputcolor * fr * diffuseValue;
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 calcRefShellac = (refLevel * envColor * (1-fr)) - refShellacOffset; //shellac layer calc
color finalRefShellac = color clamp(color calcRefShellac, minC, maxC); //clamp it
//"shellac" layer:
color specShellac = specular(nf, i, shellacRoughness);
color finalSpecShellac = specShellac * shellacLevel * fr;
//"rough spec" layer:
float proceduralRoughness = noise(s*paintChipTiling,t*paintChipTiling);
color roughSpec = specular(nf, i, proceduralRoughness / specRoughnessMult);
color clampedRoughSpec = color clamp(color roughSpec, minC, maxC);
color finalRoughSpec = clampedRoughSpec * fr * K_RoughGlowSpecMult;
Oi = Os;
Ci = Oi * Cs * finalDiffuse + finalRefShellac + finalSpecShellac + finalRoughSpec; //final maths
}
|