/* Code based on a shader by Larry Gritz */ displacement DisplacementMap (float Km = 1; string disp_space = "object", mapname="";) { point Psh, Nsh; if (mapname != "") { /* get P, N in object (or whatever) space */ Psh = transform (disp_space, P); Nsh = normalize (ntransform (disp_space, N)); /* displace in object space */ Psh += Km * texture (mapname) * Nsh; /* transform back */ P = transform (disp_space, "current", Psh); N = calculatenormal (P); } }