/* * Barnacle color shader * Peter Stuart * $Id: barncolor.sl,v 1.2 2003/11/18 19:01:39 ophi Exp $ * description: Colors barnacles. The barnacles are drawn on a crappy * "wood-like" background. The shading model used is similar to plastic * with Kd=0.8, Ks=0.3, and spec=0.05. * Accompanies barndisp.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 * * ---- surface parameters ---------------- * basecolor: color of background "wood-like" shader (used instead of Cs) * Ka: ambient value */ #include "sl2vex.h" #include "barnacle.h" #pragma hint "basecolor" color /************** set up bombing ******************************/ #define bomb_params uniform float ncones, sparse, variation, seed; \ output color barn_color; output float barn_opac; #define use_bomb_params ncones, sparse, variation, seed, barn_color, barn_opac void barnaclecolor(float s, t, sfreq, tfreq, col, row, bomb; bomb_params) { float xs, xt; color layer_color; float layer_opac; 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_color = draw_barnacle_color(ncones, barnrad2, barnrad1, 0.05, (seed+RN(299287))*noise(col+RN(42), row+RN(42)), xs, xt, layer_opac); barn_color = blend(barn_color, layer_color, layer_opac); barn_opac = union(layer_opac, barn_opac); } } #define bomb_func barnaclecolor #include "bomber.h" /******************* shader **************************************/ surface barncolor(float ncones=6; float sfreq=20, tfreq=10; float sparse=0, variation=5; float seed = 1299; color basecolor = 1; float Ka = 0.1;) { color layer_color, surface_color; float layer_opac, barn_opac; color barn_color; barn_color = 0; barn_opac = 0; surface_color = 0; normal Nf = faceforward (normalize(N),I); /********* base **********************************/ surface_color = basecolor; /* layer_color = basecolor; */ /* HACK: for some reason either shaderdl or vcc will have a problem seeing that the following code is a float, and casting doesn't work in both cases. */ /* float bloody_hack = (t+snoise(s*40 + RN(44251)))*20 + RN(6672); */ /* layer_opac = noise(bloody_hack); */ /* layer_color = layer_color * (Ka*ambient() + 0.3*diffuse(Nf)) */ /* + 0.8*layer_opac*specular(Nf, -normalize(I), 0.05); */ /* surface_color = blend(surface_color, layer_color, layer_opac); */ /********** barnacles ****************************/ bomber(s, t, sfreq, tfreq, use_bomb_params); /* barnacle lighting */ barn_color = barn_color * (Ka*ambient() + 0.5*diffuse(Nf)) + 0.5*specular(Nf, -normalize(I), 0.1); surface_color = blend(surface_color, barn_color, barn_opac); Ci = surface_color; }