#include "M:/vsfx419/shader_src/LightingUtils.h" surface subsurf2(float Kd = 0.5, /* basic brightness */ Ks = 0.7, /* hilite brightness */ subKa = 1, /* ditto sub-surf */ subKd = .5, /* ditto sub-surf */ subKs = 0.7, /* ditto sub-surf */ Km = 15, /* sub-surf bumpiness */ Kenv = 0, /* environ contribution */ Ktop = 0.5, /* scales the top color */ Ksub = 0.5; /* scales the sub color */ color hicolor = 1, /* top hilite color */ locolor = 1, /* sub-surf hilite color */ subCs = 1, /* sub-surf color */ c1 = (0,0,1), /* color 1 */ c2 = (0,1,1), /* color 2 */ c3 = (1,0,1); /* color 3 */ string envname = "", envspace = "world") { vector Nnorm = normalize(N); vector Inorm = normalize(I); vector myVector = (1,0,0); vector myCamera = transform ("object", "camera", myVector); // 1 Save copies of the "true" surface point oldP = P; normal oldN = N; Oi = Os; // 2 Obtain the environment lighting and the "top" layer color 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)); // 3 Apply a displacemnt and calculate a "fake" normal float hump = noise(s * 125, t * 200); P = P - hump * normalize(N) * Km; N = calculatenormal(P); // 4 Repeat the lighting (without environment mapping) with // the fake normal 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; // 5 Restore the true surface values P = oldP; N = oldN; // 6 Combine the top and sub-surface lighting Ci = Oi * Cs*(subcolor + topcolor + envcolor); }