예제 #1
0
        public override double GetValue(double x, double y, double z)
        {
            double value = 0.0;
            double signal = 0.0;
            double curPersistence = 1.0;
            double nx, ny, nz;
            int    seed;

            x *= m_frequency;
            y *= m_frequency;
            z *= m_frequency;

            for (int curOctave = 0; curOctave < m_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.
                nx = NoiseGen.MakeInt32Range(x);
                ny = NoiseGen.MakeInt32Range(y);
                nz = NoiseGen.MakeInt32Range(z);

                // Get the coherent-noise value from the input value and add it to the
                // final result.
                seed   = (int)((m_seed + curOctave) & 0xffffffff);
                signal = NoiseGen.GradientCoherentNoise3D(nx, ny, nz, seed, m_noiseQuality);
                value += signal * curPersistence;

                // Prepare the next octave.
                x *= m_lacunarity;
                y *= m_lacunarity;
                z *= m_lacunarity;
                curPersistence *= m_persistence;
            }

            return(value);
        }
예제 #2
0
        public override double this[double x, double y, double z]
        {
            get
            {
                double value          = 0.0;
                double curPersistence = 1.0;

                x *= Frequency;
                y *= Frequency;
                z *= 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);
                    double nz = NoiseGen.MakeInt32Range(z);

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

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

                return(value);
            }
        }
예제 #3
0
        public override double GetValue(double x, double y, double z)
        {
            x *= Frequency;
            y *= Frequency;
            z *= 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);
                double nz = NoiseGen.MakeInt32Range(z);

                // Get the coherent-noise value.
                int    seed   = (Seed + curOctave) & 0x7fffffff;
                double signal = NoiseGen.GradientCoherentNoise3D(nx, ny, nz, 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;
                z *= Lacunarity;
            }

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