/* Web.sl */ /* Author: Jeremy S. De Bonet jsd@ai.mit.edu */ /* * WebShade() : Shades a surface to look like a spider web * WebDisp() : Displaces a surface to simulate the effects of gravity on a spider web */ float sqr(float x) { return x*x; } float dist (float x,y) { return (sqrt(sqr(x)+sqr(y))); } float Gaussian(float x,m,s) { return (exp(-sqr((x)-(m))/sqr(s)));} #define PI 3.14 surface WebShade( float cRadialWebs = 7; float cCrossWebs = 10; float rWebDiam = .01; float rWebCenterT = 0, rWebCenterS = 0) { float T=(t-rWebCenterT); float S=(s-rWebCenterS); float rRadius = dist(S,T); float rAngle=atan(S,T); float rAngleStep=2*PI/cRadialWebs; float rDist; float rAccum=0; float cRadSeg; float cCrossSeg; /* Calculate which radial section its in */ cRadSeg=floor(rAngle/rAngleStep); /* Color Radial Webs */ rAccum+=Gaussian(rAngle, cRadSeg*rAngleStep, rWebDiam / rRadius); rAccum+=Gaussian(rAngle, mod((cRadSeg+1),cRadialWebs)*rAngleStep, rWebDiam / rRadius); rDist=(S * cos((cRadSeg+.5)*rAngleStep) + T * sin((cRadSeg+.5)*rAngleStep)); /* Calculate which cross section its in */ cCrossSeg=floor(rDist * cCrossWebs / 2); /* Color Tangential Webs */ rAccum+=Gaussian(rDist, cCrossSeg/cCrossWebs * 2, rWebDiam / rRadius); rAccum+=Gaussian(rDist, (cCrossSeg+1)/cCrossWebs*2, rWebDiam / rRadius); /* clamp to [0,1] */ rAccum=clamp(rAccum,0,1); Ci=Os * mix( color(0,0,0), Cs, rAccum); Oi =Os * rAccum; } displacement WebDisp( float cRadialWebs = 7; float cCrossWebs = 10; float rWebCenterT = .0, rWebCenterS = .0) { float T=(t-rWebCenterT); float S=(s-rWebCenterS); float rRadius = dist(S,T); float rAngle=atan(S,T); float rAngleStep=2*PI/cRadialWebs; float rDist; float rAccum=0; float cRadSeg; float cCrossSeg; /* Calculate which radial section its in */ cRadSeg=floor(rAngle/rAngleStep); /* Inter-radial Web sag */ rAccum+=Gaussian(rAngle, (cRadSeg+.5)*rAngleStep, rAngleStep/2.5); /* Radial Web sag */ rAccum+=1-Gaussian(rRadius, 0, 1.5); P+=rAccum/10 * normalize(N); N=calculatenormal(P); }