/* tooledsteel.sl written 9/99 by Ivan DeWolf
* ivan AT martian -tools.com
* feel free to copy, distribute, hack and/or abuse this code
* in any way you see fit, but please leave my name near the top
*
* a combination of IDbrushedmetal.sl and the Worley-esque
* F1 from bubbly.sl adapted to happen in parameter space.
* A vector is computed from the gradient of the distance function,
* and then used as the vector of anisotropy. works best on parametric
* surfaces where you don't care about the seams.
* (like that'll ever happen...)
* thanks to Jos Stam whose animated cube motivated this thing.
*
*
* PARAMETERS:
* mult - multiples of swirls per unit
* Nzscale - scale of the noise that randomizes the location of
* the swirls. set this to zero for a perfect grid.
* Ks - coefficient of specular
* Kd - coefficient of diffuse
* Ka - coefficient of ambient
* Kr - coefficient of reflectivity
* specwidth - the width of the specular stripe
* maxes out at 10
* specspread - the spread of the specular stripe
* maxes out at .5
* mapspread - the spread of the reflection map streaking
* maxes out at .5
* twist - allows you to twist the direction of anisotropy
* angle in radians (i.e. PI*.5 = 90 degrees)
* mapname - name of the environment map
* specularcolor - color of the specular hilight
*/
vector
getvec(float mult; float Nzscale)
{
extern point P;
extern vector dPdu;
extern vector dPdv;
extern float s;
extern float t;
vector udir = vector(1,0,0);
vector vdir = vector(0,1,0);
float a,b,c;
float dist, shortest=10000;
float valu,valv;
point Po = point(s*mult,t*mult,0);
point Pou = Po +(udir*.01);
point Pov = Po +(vdir*.01);
/*true cell center, surrounding cell centers, noised cell center*/
point trucell, surrcell, nzcell;
vector offset, nzoff, out;
float chu, chv;
float ncells = floor(mult);
float cellsize = 1/ncells;
setxcomp(trucell,floor(xcomp(Po))+.5);
setycomp(trucell,floor(ycomp(Po))+.5);
setzcomp(trucell,0);
c = 0;
/*what is the shortest distance to a noised cell center?*/
for(a = -1; a<= 1; a+=1){
for(b = -1; b<=1; b += 1){
offset = vector(a,b,c);
surrcell = trucell+offset;
nzoff = ((vector cellnoise(surrcell)-.5)*Nzscale);
setzcomp(nzoff,0);
nzcell = surrcell + nzoff;
dist = distance(Po,nzcell);
if(dist