public static double gradientNoise3D ( double fx , double fy , double fz , int ix , int iy , int iz , int seed ) { // Randomly generate a gradient vector given the integer coordinates of the // input value. This implementation generates a random number and uses it // as an index into a normalized-vector lookup table. int vectorIndex = ( X_NOISE_GEN * ix + Y_NOISE_GEN * iy + Z_NOISE_GEN * iz + SEED_NOISE_GEN * seed ) ; vectorIndex ^= ( vectorIndex >> SHIFT_NOISE_GEN ) ; vectorIndex &= 0xff ; double xvGradient = Utils . RANDOM_VECTORS [ ( vectorIndex << 2 ) ] ; double yvGradient = Utils . RANDOM_VECTORS [ ( vectorIndex << 2 ) + 1 ] ; double zvGradient = Utils . RANDOM_VECTORS [ ( vectorIndex << 2 ) + 2 ] ; // Set up us another vector equal to the distance between the two vectors // passed to this function. double xvPoint = ( fx - ix ) ; double yvPoint = ( fy - iy ) ; double zvPoint = ( fz - iz ) ; // Now compute the dot product of the gradient vector with the distance // vector. The resulting value is gradient noise. Apply a scaling and // offset value so that this noise value ranges from 0 to 1. return ( ( xvGradient * xvPoint ) + ( yvGradient * yvPoint ) + ( zvGradient * zvPoint ) ) + 0.5 ; }
Generates a gradient - noise value from the coordinates of a three - dimensional input value and the integer coordinates of a nearby three - dimensional value .