Beispiel #1
0
        public override double this[double x, double y]
        {
            get
            {
                double value          = 0.0;
                double curPersistence = 1.0;

                x *= Frequency;
                y *= Frequency;

                for (int curOctave = 0; curOctave < OctaveCount; curOctave++)
                {
                    // Make sure that these floating-point values have the same range as a 32-
                    // bit integer so that we can pass them to the coherent-noise functions.
                    double nx = NoiseGen.MakeInt32Range(x);
                    double ny = NoiseGen.MakeInt32Range(y);

                    // Get the coherent-noise value from the input value and add it to the
                    // final result.
                    int    localSeed = Seed + curOctave;
                    double signal    = NoiseGen.GradientCoherentNoise2D(nx, ny, localSeed, NoiseQuality);
                    value += signal * curPersistence;

                    // Prepare the next octave.
                    x *= Lacunarity;
                    y *= Lacunarity;
                    curPersistence *= Persistence;
                }

                return(value);
            }
        }
Beispiel #2
0
        public override double this[double x, double y]
        {
            get
            {
                x *= Frequency;
                y *= Frequency;

                double value  = 0.0;
                double weight = 1.0;

                // These parameters should be user-defined; they may be exposed in a
                // future version of libnoise.
                const double offset = 1.0;
                const double gain   = 2.0;

                for (int curOctave = 0; curOctave < OctaveCount; curOctave++)
                {
                    // Make sure that these floating-point values have the same range as a 32-
                    // bit integer so that we can pass them to the coherent-noise functions.
                    double nx = NoiseGen.MakeInt32Range(x);
                    double ny = NoiseGen.MakeInt32Range(y);

                    // Get the coherent-noise value.
                    int    seed   = (Seed + curOctave) & 0x7fffffff;
                    double signal = NoiseGen.GradientCoherentNoise2D(nx, ny, seed, NoiseQuality);

                    // Make the ridges.
                    signal = Math.Abs(signal);
                    signal = offset - signal;

                    // Square the signal to increase the sharpness of the ridges.
                    signal *= signal;

                    // The weighting from the previous octave is applied to the signal.
                    // Larger values have higher weights, producing sharp points along the
                    // ridges.
                    signal *= weight;

                    // Weight successive contributions by the previous signal.
                    weight = signal * gain;
                    if (weight > 1.0)
                    {
                        weight = 1.0;
                    }
                    if (weight < 0.0)
                    {
                        weight = 0.0;
                    }

                    // Add the signal to the output value.
                    value += (signal * spectralWeights[curOctave]);

                    // Go to the next octave.
                    x *= Lacunarity;
                    y *= Lacunarity;
                }

                return((value * 1.25) - 1.0);
            }
        }