コード例 #1
0
ファイル: Perlin.cs プロジェクト: Earthmark/Libnoise
        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);
            }
        }
コード例 #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);
            }
        }
コード例 #3
0
ファイル: Perlin.cs プロジェクト: Neovariance/LibNoise
        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);
        }
コード例 #4
0
ファイル: Checkerboard.cs プロジェクト: Earthmark/Libnoise
        /// <summary>
        ///      Generates an output value given the coordinates of the specified input value.
        /// </summary>
        /// <param name="x">The x coordinate of the input value.</param>
        /// <param name="y">The y coordinate of the input value.</param>
        /// <param name="z">The z coordinate of the input value.</param>
        /// <returns>The output value.</returns>
        public override double GetValue(double x, double y, double z)
        {
            var ix = (int)(Math.Floor(NoiseGen.MakeInt32Range(x)));
            var iy = (int)(Math.Floor(NoiseGen.MakeInt32Range(y)));
            var iz = (int)(Math.Floor(NoiseGen.MakeInt32Range(z)));

            return((ix & 1 ^ iy & 1 ^ iz & 1) != 0 ? -1.0 : 1.0);
        }
コード例 #5
0
 /// <summary>
 ///      Generates an output value given the coordinates of the specified input value.
 /// </summary>
 /// <param name="x">The x coordinate of the input value.</param>
 /// <returns>The output value.</returns>
 public override double this[double x]
 {
     get
     {
         var ix = (int)(Math.Floor(NoiseGen.MakeInt32Range(x)));
         return((ix & 1) != 0 ? -1.0 : 1.0);
     }
 }