/************************************************************ * file: rockcolor.sl * author: Peter Stuart * date: 11/16/2002 * $Id: rockcolor.sl,v 1.4 2003/01/27 04:32:48 ophi Exp $ * description: Accompanies the rockdisp shader. * * ---- 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 * tipcolor: color at the voronoi cell boundaries * sidecolor: color in the center of the cell ************************************************************/ #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) surface rockcolor(float freq = 10; float twist = 1; float seed = 192; color tipcolor = color(1,1,1); color sidecolor = color(0,0,0);) { color layer_color, layer_opac, surface_color; float dist, posx, posy; float factor = 0.5; vector Nn = normalize(N); surface_color = Cs; /******* 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; /* use dist^2 to get rounded concavities */ layer_color = blend(sidecolor, tipcolor, dist); layer_opac = smoothstep(0,1,dist); surface_color = blend(surface_color, layer_color, layer_opac); Ci = surface_color*diffuse(normalize(N)); }