#include #include #include "cloud.h" /* * The QAEB procedural ray tracing routine. * * Fractal functions module. * * This is mostly bunch of C code for terrain models that appears in the book * "Textures and Modeling: A Procedural Approach," Ebert et al, Academic Press, * 1998. * * Copyright 1998 F. Kenton Musgrave * All rights reserved */ extern CameraType camera; extern OptionsType options; extern double octaves_scalar; extern double Noise2(); extern double Noise3(); /* * Ridged multifractal - FKM 4/94 * * Some good parameter values to start with: * * H: 0.9 * offset: 1 * gain: 2 */ double RidgedMultifractal( Vector point, double H, double lacunarity, double octaves, double offset, double threshold ) { double result, frequency, signal, weight, Noise2(); int i; static first = TRUE; static double exponent_array[MAX_OCTAVES]; /* precompute and store spectral weights */ if ( first ) { /* compute weight for each frequency */ for (i=0; i0.001 && i 1.0 ) weight = 1.0; if ( weight < 0.0 ) weight = 0.0; signal = Noise2( point ); if ( signal < 0.0 ) signal = -signal; signal = offset - signal; signal *= signal; /* weight the contribution */ signal *= weight; result += signal * exponent_array[i]; } return( result ); } /* RidgedMultifractal() */ /* * Stats-by-Position multifractal - FKM 4/94 * * Some good parameter values to start with: * * H: 0.25 * offset: .7 * gain: 1 */ double HybridMultifractal( Vector point, double H, double lacunarity, double octaves, double offset, double gain ) { double frequency, value, signal, weight, remainder, Noise2(); int i; static first = TRUE; static double exponent_array[MAX_OCTAVES]; /* precompute and store spectral weights */ if ( first ) { /* compute weight for each frequency */ for (i=0; i0.001 && i 1.0 ) weight = 1.0; /* get next higher frequency */ signal = ( Noise2( point ) + offset ) * exponent_array[i]; /* add it in, weighted by previous freq's local value */ value += weight * signal; /* update the (monotonically decreasing) weighting value */ weight *= gain * signal; point.x *= lacunarity; point.y *= lacunarity; point.z *= lacunarity; } /* for */ /* take care of remainder in "octaves" */ remainder = octaves - (int)octaves; if ( remainder ) /* "i" and spatial freq. are preset in loop above */ value += remainder * Noise2( point ) * exponent_array[i]; return( value ); } /* HybridMultifractal() */ /* * Heterogeneous procedural terrain fucntion: stats by altitude method. * Evaluated at "point"; returns value stored in "value". * * Parameters: * "H" is the fractal increment * "lacunarity" is the gap between successive frequencies * "octaves" is the number of frequencies in the fBm * "offset" raises the terrain from Ôsea levelÕ */ double Hetero_Terrain( Vector point, double H, double lacunarity, double octaves, double offset ) { double value, increment, frequency, remainder, Noise2(); int i; static first = TRUE; static double exponent_array[MAX_OCTAVES]; /* precompute and store spectral weights */ if ( first ) { /* compute weight for each frequency */ for (i=0; i