由 ChildPark » 14日 1月 2004年, 10:05
草坪
displacement disgrass(
float amplitude = 0.02,
urepeat = 75,
vrepeat = 80,
uoffset = 0.5,
voffset = 0.6,
crowd = 10;
)
{
float useu, usev, rndrad, offsetu, offsetv, indu, indv, dst,
shiftu, shiftv, compare, onoff, height, bmp;
uniform float i;
bmp = 0;
for( i=0; i<crowd; i+=1 ) {
shiftu = float cellnoise( i * 875) * 10;
shiftv = float cellnoise( i * 32) * 10;
useu = (s + uoffset) * urepeat + shiftu;
usev = (t + voffset) * vrepeat + shiftv;
rndrad = float cellnoise( useu, usev) * 0.05 + 0.55;
offsetu = (2 * float cellnoise( useu+66, usev-12 ) - 1) *
(0.5 - rndrad);
offsetv = (2 * float cellnoise( useu-226, usev+565 ) - 1) *
(0.5 - rndrad);
indu = mod(useu,1)-0.5-offsetu;
indv = mod(usev,1)-0.5-offsetv;
dst = min( sqrt(indu*indu+indv*indv)/rndrad, 1 ) * PI/2;
compare = float cellnoise( useu + 44, usev - 20 );
onoff = step( 0.5, compare );
height = float cellnoise( useu+331, usev-99 ) * 0.4 + 0.6;
bmp = max( bmp, onoff * height * cos(dst) );
}
P += amplitude * bmp * -normalize(N);
N = calculatenormal(P);
}