/* * Barnacle displacement shader * Peter Stuart * $Id: barndisp.sl,v 1.3 2003/11/18 19:01:40 ophi Exp $ * description: Displaces barnacles. Accompanies barncolor.sl * * ---- common parameters ---------------- * ncones: number of bulges in barnacle. * sfreq, tfreq: number of barnacles in s and t * sparse: control sparseness of barnacles across surface. The value is * interpreted as follows: * 0 - appear all over surface * 0.5 - appear with density determined by the density function * 1 - appear nowhere * values in between are interpolated. * variation: controls the frequency of a simple perlin noise function * that controls the density of the barnacles. * seed: controls random attributes * * ---- displacement parameters ---------- * max_height: height of barnacles. Adjusted automatically based on frequency. * spikiness: length of spikes on top ridge of barnacle */ #include "sl2vex.h" #include "barnacle.h" /************** set up bombing ******************************/ #define bomb_params uniform float max_height, ncones, spikiness, \ sparse, variation, seed; output float barn_disp; #define use_bomb_params max_height, ncones, spikiness, \ sparse, variation, seed, barn_disp void barnacledisp(float s, t, sfreq, tfreq, col, row, bomb; bomb_params) { float xs, xt; float layer_disp; float barnrad1 = 0.5; float barnrad2 = 0.1; if (test_and_xform(s, t, sfreq, tfreq, col, row, bomb, sparse, variation, seed, xs, xt) != 0) { layer_disp = draw_barnacle_displace(ncones, spikiness, barnrad2, barnrad1, 0.05, (seed+RN(299287)) * noise(col+RN(42), row+RN(42)), xs, xt); barn_disp = max(max_height*layer_disp/max(sfreq, tfreq), barn_disp); } } #define bomb_func barnacledisp #include "bomber.h" /******************* shader **************************************/ displacement barndisp(float max_height=0.2, ncones=6, spikiness=0.5; float sfreq=20, tfreq=10; float sparse=0, variation=5; float seed = 1299) { float barn_disp = 0; /********** barnacles ****************************/ bomber(s, t, sfreq, tfreq, use_bomb_params); /* barnacle displacement */ vector Nn = normalize(N); P += Nn * (barn_disp / length(shader_space(Nn))); N = calculatenormal(P); }