/************************************************************ * file: rockdisp.sl * author: Peter Stuart * date: 11/16/2002 * $Id: rockdisp.sl,v 1.5 2003/01/27 04:32:48 ophi Exp $ * description: displaces an object to make it look more rock-like. * It uses a 2d voronoi function similar to the voronoi functions used * in the Advanced RenderMan book. * * ---- surface parameters ---------- * freq: number of cells along the s and t directions * twist: twists the voronoi regions along s and t. Good values * depend on frequency. * seed: controls random parameters * Km: amplitude of displacement ************************************************************/ #include "voronoi.sl" #include "rmannotes.sl" /* ---- macro to help seed random numbers ------ * it serves two purposes: * - allows easy searching to ensure non-repeating numbers * - automatically uses seed */ #define RN(x) (seed+(x)+0.5) displacement rockdisp(float freq = 10; float twist = 1; float seed = 192; float Km = 0.1;) { float surface_disp, layer_disp; float dist, posx, posy; vector Nn = normalize(N); surface_disp = 0; /******** main voronoi layer **********/ float ss = s + 0.1*snoise2(s*twist*5+RN(1452), t*twist*5+RN(1459)); float tt = t + 0.1*snoise2(s*twist*5+RN(1552), t*twist*5+RN(1559)); voronoi_f1_2d(ss, tt, freq, 1, dist, posx, posy); dist *= dist; /* used dist^2 to get rounded concavities */ layer_disp = smoothstep(0, 1, dist) + 1/30*noise(s*300,t*300); surface_disp += layer_disp; /******** edgy voronoi layer **********/ voronoi_f1_2d(ss+RN(1091), tt+RN(10928), 2*freq, 1, dist, posx, posy); dist *= dist; layer_disp = 1/freq*smoothstep(0, 1, dist); surface_disp += layer_disp; P += Nn * (Km*surface_disp / length(vtransform("shader", Nn))); N = calculatenormal(P); }