#include "M:/vsfx419/shader_src/LightingUtils.h" surface carrust(float Kd = .1, /* basic brightness for carpaint */ kd2 = .8, /* basic brightness for rust */ Ka = 1, Ks = 0.6, /* hilite brightness */ subKa = 1, /* ditto sub-surf */ subKd = .5, /* ditto sub-surf */ subKs = 0.7, /* ditto sub-surf */ Km = .1, /* sub-surf bumpiness */ Kenv = .1, /* environ contribution */ Ktop = 0.5, /* scales the top color */ bumpvar = .1, Ksub = 0.5, /* scales the sub color */ min = 0.1, max = 0.5, rustedge = 0, /* intensity of hole */ layerblend = .97; /* edge blend for rust */ color hicolor = 1, /* top hilite color */ locolor = 1, /* sub-surf hilite color */ subCs = 1, /* sub-surf color */ c1 = (0.0,0.070,0.576), /* color 1 */ c2 = (0.015,0.035,0.231), /* color 2 */ c3 = (0.015,0.0,0.156), /* color 3 */ lt_rust = color(0.705,0.447,0.192), dk_rust = color(0.313,0.086,0.047); string envname = "", texname = "", envspace = "world") { float layer = texture(texname[3]); float redchan = texture(texname[0]), greenchan = texture(texname[1]), bluechan = texture(texname[2]), crackchan = texture(texname[3]); //######CARPAINT LAYER if (layer != 1){ vector Nnorm = normalize(N); vector Inorm = normalize(I); vector myVector = (1,0,0); vector myCamera = transform ("object", "camera", myVector); point oldP = P; normal oldN = N; Oi = Os; color envcolor = envmapping(N, I, envname, envspace, Kenv); color topcolor = plastic(N, I, 0, Kd, Ks, 0.1, hicolor) * Ktop; color fakecolor = (spline((1-abs(Nnorm.Inorm)),c1,c2,c3)); float hump = (noise(s * 550, t * 550)*bumpvar); P = P - hump * normalize(N) * Km; N = calculatenormal(P); color subCs =(mix(c1, c3, (1-abs(Nnorm.Inorm)))) ; color sublight = plastic(N, I, subKa, subKd, subKs, 0.1, locolor) * Ksub; color subcolor = sublight * subCs; P = oldP; N = oldN; Ci = Oi * Cs*(subcolor + topcolor + envcolor); } color firstsurf=Ci*layerblend; //########RUST LAYER if (texture(texname) > rustedge){ normal nf, n; color ambientcolor, diffusecolor; n = normalize(N); nf = faceforward(n, I); color surfcolor = 1; Oi = Os; ambientcolor = Ka * ambient(); diffusecolor = kd2 * diffuse(nf); if(texname != "") { float blend = smoothstep(min,max,redchan); float redc = (100-(redchan*100))/100+.2; float greenc = (100-(redchan*100))/220; if(redchan > rustedge) surfcolor = ((redc*.8), greenc,0); surfcolor = (mix((firstsurf), surfcolor, blend))*.8; Ci = Oi * Cs * surfcolor * (ambientcolor + diffusecolor); } } //#### DROP OPACITY WHEN GREEN, ADD CRACKS TO CHANNEL 4 if(crackchan > .2) Ci = mix(color(0.294,0.294,0.294),Ci,.2); if(greenchan > .05) Ci = (Os*0); }