/* Written by Malcolm Kesson April 2001 modified 10 July 2001 */ surface combo(float Ks = 0.7, /* specularity */ Kd = 0.5, /* diffuse */ Ka = 1, /* ambient */ roughness = .1, /* small is very smooth */ decalblend = 0, /* mixture of decal with texture */ envblend = 0, /* contribution of the environment map */ smovetex = 0, /* shift the texture in "s" */ tmovetex = 0, /* shift the texture in "t" */ smovetra = 0, /* shift the transparency map in "s" */ tmovetra = 0, /* shift the transparency map in "t" */ smovedecal = 0, /* shift the decal map in "s" */ tmovedecal = 0, /* shift the decal map in "t" */ smovedecalmask = 0, /* shift the decalmask in "s" */ tmovedecalmask = 0; /* shift the decalmask in "t" */ color specularcolor = 1; /* color of the reflection */ string texname = "", /* name of the texture map */ traname = "", /* name of the transparency map */ decalname = "", /* name of the decal map */ decalmask = "", /* name of the decal mask */ envname = "", /* name of the environment/reflection map */ specname = "", /* name of the specular map */ roughname = "") { float mask = 1, spec = Ks, ruf = roughness; color texColor = Cs, decalColor = Cs, finalColor = Cs; normal Nf = faceforward(normalize(N),I); vector V = -normalize(I); /* Environment variables */ vector Rray, Tray, R, T, N2; if (texname != "") texColor = color texture(texname, s + smovetex, t + tmovetex); if (traname != "") Oi = float texture(traname, s + smovetra, t + tmovetra); else Oi = Os; if(decalmask != "") mask = float texture(decalmask, s + smovedecalmask, t + tmovedecalmask); if(decalname != "") { decalColor = color texture(decalname, s + smovedecal, t + tmovedecal); finalColor = mix(decalColor, texColor, mask); finalColor = mix(finalColor, texColor, decalblend); } else finalColor = texColor; if(envname != "") { /* find direction of refracted ray */ Rray = reflect(-V,Nf); Rray = transform("world",point "world" (0,0,0) + Rray); finalColor = mix(finalColor, color environment(envname, Rray), envblend); } if(specname != "") spec = texture(specname) * Ks; if(roughname != "") ruf = texture(roughname) * roughness; Ci = Oi * ( Cs * finalColor * (Ka*ambient() + Kd*diffuse(Nf)) + specularcolor * spec * specular(Nf,V,ruf) ); }