technologies/reference/musgrave.c
double 
RidgedMultifractal( Vector point, double H, double lacunarity,
                    double octaves, double offset, double gain )
{
      double           result, frequency, signal, weight, Noise3();
      int              i;
      static int       first = TRUE;
      static double    *exponent_array;

      /* precompute and store spectral weights */
      if ( first ) {
            /* seize required memory for exponent_array */
            exponent_array =
                        (double *)malloc( (octaves+1) * sizeof(double) );
            frequency = 1.0;
            for (i=0; i<=octaves; i++) {
                  /* compute weight for each frequency */
                  exponent_array[i] = pow( frequency, -H );
                  frequency *= lacunarity;
            }
            first = FALSE;
      }

      /* get first octave */
      signal = Noise3( point );
      /* get absolute value of signal (this creates the ridges) */
      if ( signal < 0.0 ) signal = -signal;
      /* invert and translate (note that "offset" should be ~= 1.0) */
      signal = offset - signal;
      /* square the signal, to increase "sharpness" of ridges */
      signal *= signal;
      /* assign initial values */
      result = signal;
      weight = 1.0;

      for( i=1; i<octaves; i++ ) {
            /* increase the frequency */
            point.x *= lacunarity;
            point.y *= lacunarity;
            point.z *= lacunarity;

            /* weight successive contributions by previous signal */
            weight = signal * gain;
            if ( weight > 1.0 ) weight = 1.0;
            if ( weight < 0.0 ) weight = 0.0;
            signal = Noise3( point );
            if ( signal < 0.0 ) signal = -signal;
            signal = offset - signal;
            signal *= signal;
            /* weight the contribution */
            signal *= weight;
            result += signal * exponent_array[i];
      }

      return( result );

}
/* Ridged multifractal terrain model.
 *
 * Copyright 1994 F. Kenton Musgrave 
 *
 * Some good parameter values to start with:
 *
 *      H:           1.0
 *      offset:      1.0
 *      gain:        2.0
 */
Ridged multifractal terrain model.
Copyright 1994 F. Kenton Musgrave

Some good parameter values to start with.


Ridged multifractal terrain model . Copyright 1994 F . Kenton Musgrave Some good parameter values to start with .
double 
RidgedMultifractal( Vector point, double H, double lacunarity,
                    double octaves, double offset, double gain )
{
      double           result, frequency, signal, weight, Noise3();
      int              i;
      static int       first = TRUE;
      static double    *exponent_array;
      if ( first ) {
            exponent_array =
                        (double *)malloc( (octaves+1) * sizeof(double) );
            frequency = 1.0;
            for (i=0; i<=octaves; i++) {
                  exponent_array[i] = pow( frequency, -H );
                  frequency *= lacunarity;
            }
            first = FALSE;
      }
      signal = Noise3( point );
      if ( signal < 0.0 ) signal = -signal;
      signal = offset - signal;
      signal *= signal;
      result = signal;
      weight = 1.0;
      for( i=1; i<octaves; i++ ) {
            point.x *= lacunarity;
            point.y *= lacunarity;
            point.z *= lacunarity;
            weight = signal * gain;
            if ( weight > 1.0 ) weight = 1.0;
            if ( weight < 0.0 ) weight = 0.0;
            signal = Noise3( point );
            if ( signal < 0.0 ) signal = -signal;
            signal = offset - signal;
            signal *= signal;
            signal *= weight;
            result += signal * exponent_array[i];
      }
      return( result );
}
double RidgedMultifractal ( Vector point , double H , double lacunarity , double octaves , double offset , double gain ) { double result , frequency , signal , weight , Noise3 ( ) ; int i ; static int first = TRUE ; static double * exponent_array ; if ( first ) { exponent_array = ( double * ) malloc ( ( octaves + 1 ) * sizeof ( double ) ) ; frequency = 1.0 ; for ( i = 0 ; i <= octaves ; i ++ ) { exponent_array [ i ] = pow ( frequency , - H ) ; frequency *= lacunarity ; } first = FALSE ; } signal = Noise3 ( point ) ; if ( signal < 0.0 ) signal = - signal ; signal = offset - signal ; signal *= signal ; result = signal ; weight = 1.0 ; for ( i = 1 ; i < octaves ; i ++ ) { point . x *= lacunarity ; point . y *= lacunarity ; point . z *= lacunarity ; weight = signal * gain ; if ( weight > 1.0 ) weight = 1.0 ; if ( weight < 0.0 ) weight = 0.0 ; signal = Noise3 ( point ) ; if ( signal < 0.0 ) signal = - signal ; signal = offset - signal ; signal *= signal ; signal *= weight ; result += signal * exponent_array [ i ] ; } return ( result ) ; }
Ridged multifractal terrain model.
Ridged multifractal terrain model .
/* precompute and store spectral weights */ /* seize required memory for exponent_array */ /* compute weight for each frequency */ /* get first octave */ /* get absolute value of signal (this creates the ridges) */ /* invert and translate (note that "offset" should be ~= 1.0) */ /* square the signal, to increase "sharpness" of ridges */ /* assign initial values */ /* increase the frequency */ /* weight successive contributions by previous signal */ /* weight the contribution */