Graphics Reference
In-Depth Information
B.6 Randomness
Introducing controlled randomness in both modeling and animation can often produce more interest-
ing, realistic, natural-looking imagery. Noise and turbulence functions are often used in textures but
also can be used in modeling natural phenomena such as smoke and clouds. The code for noise and
turbulence that follows is from Peachey's chapter in Ebert [ 3 ] . Random perturbations are also useful
in human-figure animation to make the motion less “robotic” looking. There are various algorithms
proposed in the literature for generating random numbers; Gasch's [ 6 ] is presented at the end of this
section.
B.6.1 Noise
The noise function uses a table of pseudorandom numbers between
1 to represent the integer
lattice values. The table is created by valueTableInit the first time that noise is called. Lattice coordi-
nates are used to index into a table of pseudorandom numbers. A simple function of the coordinates,
such as their sum, is used to compute the index. However, this can result in unwanted patterns. To help
avoid these artifacts, a table of random permutation values is used to modify the index before it is used.
A four-point spline is used to interpolate among the lattice pseudorandom numbers ( FPspline ).
1 and
þ
#define TABSIZE
256
#define TABMASK
(TABSIZE-1)
#define PERM(x)
perm[(x)&TABMASK]
#define INDEX(ix,iy,iz)
PERM((ix) þ PERM((iy) þ PERM(iz)))
#define FLOOR(x)
(int)(x)
/* PERMUTATION TABLE */
static unsigned char perm[TABSIZE] ¼ {
225, 155, 210, 108, 175, 199, 221, 144, 203, 116, 70, 213, 69, 158, 33, 252, 5, 82, 173,
133, 222, 139, 174, 27, 9, 71, 90, 246, 75, 130, 91, 191, 169, 138, 2, 151, 194, 235, 81, 7,
25, 113, 228, 159, 205, 253, 134, 142, 248, 65, 224, 217, 22, 121, 229, 63, 89, 103, 96,
104, 156, 17, 201, 129, 36, 8, 165, 110, 237, 117, 231, 56, 132, 211, 152, 20, 181, 111,
239, 218, 170, 163, 51, 172, 157, 47, 80, 212, 176, 250, 87, 49, 99, 242, 136, 189, 162,
115, 44, 43, 124, 94, 150, 16, 141, 247, 32, 10, 198, 223, 255, 72, 53, 131, 84, 57, 220,
197, 58, 50, 208, 11, 241, 28, 3, 192, 62, 202, 18, 215, 153, 24, 76, 41, 15, 179, 39, 46,
55, 6, 128, 167, 23, 188, 106, 34, 187, 140, 164, 73, 112, 182, 244, 195, 227, 13, 35, 77,
196, 185, 26, 200, 226, 119, 31, 123, 168, 125, 249, 68, 183, 230, 177, 135, 160, 180, 12,
1, 243, 148, 102, 166, 38, 238, 251, 37, 240, 126, 64, 74, 161, 40, 184, 149, 171, 178, 101,
66, 29, 59, 146, 61, 254, 107, 42, 86, 154, 4, 236, 232, 120, 21, 233, 209, 45, 98, 193, 114,
78, 19, 206, 14, 118, 127, 48, 79, 147, 85, 30, 207, 219, 54, 88, 234, 190, 122, 95, 67, 143,
109, 137, 214, 145, 93, 92, 100, 245, 0, 216, 186, 60, 83, 105, 97, 204, 52
};
#define RANDNBR ww (((float)rand())/RAND_MASK)
float valueTab[TABSIZE];
/* ¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼¼ */
/* VALUE TABLE INIT */
/* initialize the table of pseudorandom numbers */
void valueTableInit(int seed)
Search WWH ::




Custom Search