|
surface
carpaint_complex(
color inputcolor = color (0.317,0.584,0.843);
float Kd = 0.6;
float basicRaytraceMult = 0.35;
color maxBasicRaytraceClamp = 1.0;
float basicRaytraceFacingOffset = 0.02;
float glossyRaytraceSwitch = 1; //glossy rim raytrace parameters
color glossyRaytraceColor = color (0.541,0.811,0.933);
float glossyRaytraceMult = 0.3;
color maxGlossyClamp = 1.1;
float glossyFacingOffset = 0.01;
float samples = 16;
float samplecone = 0.1;
float metallicRaytraceSwitch = 1; //metallic raytrace hl parameters
color metallicHighlightColor = color (0.541,0.831,0.901); //metallic highlight color
float metallicRaytraceMult = 0.15;
float metalFlakeSamples = 18;
float metalFlakeSampleCone = 0.5;
color maxMetallicClamp = 0.8;
//the following are the old basic shader parameters, they only work for point/spot light sources
string refMap = "Give me a map please."; //fake refmap layer settings
float refLevel = 0.0;
color upperClamp = 1.1;
float refShellacOffset = 0.01;
color shellacLevel = 0.4; //"shellac" spec settings
float shellacRoughness = 0.0;
float paintChipTiling = 2000; //"rough spec" settings
float specRoughnessMult = 1;
float K_RoughGlowSpecMult = 0.35;)
{
//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
//RAYTRACING:
//////////////////////////////////////////////////////////////////
//****basic reflection
color reflectcolor = 0;
reflectcolor = trace(P, reflect(I, nf));
reflectcolor *= basicRaytraceMult; //mult
color basicReflectionClamped = color clamp(color reflectcolor, minC, maxBasicRaytraceClamp); //clamp it
color finalBasicRaytraceReflection = basicReflectionClamped * ((1-fr) - basicRaytraceFacingOffset);
//****glossy reflection
color hitc = 0;
color cumulativeGather = 0;
float numhits = 0;
color cumulativeGatherFinal = 0;
if(glossyRaytraceSwitch == 1) //test for switch
{
//we should really test to see if normals are facing the right way etc but this will do instead
gather("illuminance", P, reflect(I, nf), samplecone, samples, "surface:Ci", hitc)
{
cumulativeGather += hitc;
numhits += 1;
}
cumulativeGather /= numhits; //average glossy rays
cumulativeGather *= glossyRaytraceMult; //multiply brightness
color cumulativeGatherClamped = color clamp(color cumulativeGather, minC, maxGlossyClamp); //clamp it
cumulativeGatherFinal = cumulativeGatherClamped * glossyRaytraceColor * (1-fr) - glossyFacingOffset;
}
//****metallic flakes (do the forward facing "glowy" glossy reflection and multiply with some noise)
hitc = 0;
cumulativeGather = 0;
numhits = 0;
color cumulativeMetallicFinal = 0;
if(metallicRaytraceSwitch == 1) //add in a switch function
{
//again, we should test for normals, but myeh.
gather("illuminance", P, reflect(I, nf), metalFlakeSampleCone, metalFlakeSamples, "surface:Ci", hitc)
{
cumulativeGather += hitc;
numhits += 1;
}
cumulativeGather /= numhits; //average glossy rays
cumulativeGather *= metallicRaytraceMult; //multiply brightness
color cumulativeMetallicGatherClamped = color clamp(color cumulativeGather, minC, maxMetallicClamp); //clamp it
cumulativeMetallicFinal = cumulativeMetallicGatherClamped * cumulativeMetallicGatherClamped * metallicHighlightColor * fr; //squared and multiplied with HL colour to accentuate colour.
}
//////////////////////////////////////////////////////////////////
//**** Basic shader parameters (only valid for point/spot lights, not IBL or raytraced reflections)
//Fake refmap:
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(refMap, 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 + cumulativeMetallicFinal + finalBasicRaytraceReflection + cumulativeGatherFinal; //final maths
}
|