displacement Inside_Out_Displace(float Km = 0.1, blend = 0; string OutSideTxt = "", InSideTxt = "") { float hump1 = 0, hump2 = 0, F_Hump = 0, switch = 1; /* STEP 1 - make a copy of the surface normal one unit in length */ normal n = normalize(N); normal nf = faceforward(n, I); /* STEP 2 - calculate an appropriate value for the displacement */ if (OutSideTxt != "" || InSideTxt != "") if (switch == 1 && n == nf) { hump1 = texture(OutSideTxt); hump2 = texture(InSideTxt); } else if (switch == 1 && n != nf) { hump1 = texture(InSideTxt); hump2 = texture(OutSideTxt); } F_Hump = mix(hump1, hump2, blend); /* STEP 3 - calculate the new position of the surface point */ /* "P" based on the value of hump */ P = P - n * F_Hump * Km; /* STEP 4 - calculate the new orientation of the surface normal */ N = calculatenormal(P); }