Exemplo n.º 1
0
        /// <summary>
        ///     Generates an output value given the coordinates of the specified input value.
        /// </summary>
        /// <param name="x">The input coordinate on the x-axis.</param>
        /// <param name="y">The input coordinate on the y-axis.</param>
        /// <returns>The resulting output value.</returns>
        public float GetValue(float x, float y)
        {
            int curOctave;

            x *= Frequency;
            y *= Frequency;

            // Initialize value
            var value = 1.0f;

            // inner loop of spectral construction, where the fractal is built
            for (curOctave = 0; curOctave < OctaveCount; curOctave++)
            {
                // Get the coherent-noise value.
                var signal = Offset + Primitive2D.GetValue(x, y) * SpectralWeights[curOctave];

                // Add the signal to the output value.
                value *= signal;

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

            //take care of remainder in OctaveCount
            var remainder = OctaveCount - (int)OctaveCount;

            if (remainder > 0.0f)
            {
                value += remainder * Primitive2D.GetValue(x, y) * SpectralWeights[curOctave];
            }

            return(value);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Generates an output value given the coordinates of the specified input value.
        /// </summary>
        /// <param name="x">The input coordinate on the x-axis.</param>
        /// <param name="y">The input coordinate on the y-axis.</param>
        /// <returns>The resulting output value.</returns>
        public float GetValue(float x, float y)
        {
            int curOctave;

            x *= Frequency;
            y *= Frequency;

            // Initialize value : 1st octave
            var signal = Primitive2D.GetValue(x, y);

            // get absolute value of signal (this creates the ridges)
            if (signal < 0.0f)
            {
                signal = -signal;
            }

            // invert and translate (note that "offset" should be ~= 1.0)
            signal = Offset - signal;

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

            // Add the signal to the output value.
            var value = signal;

            var weight = 1.0f;

            for (curOctave = 1; weight > 0.001 && curOctave < OctaveCount; curOctave++)
            {
                x *= Lacunarity;
                y *= Lacunarity;

                // Weight successive contributions by the previous signal.
                weight = Libnoise.Clamp01(signal * Gain);

                // Get the coherent-noise value.
                signal = Primitive2D.GetValue(x, y);

                // Make the ridges.
                if (signal < 0.0)
                {
                    signal = -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;

                // Add the signal to the output value.
                value += signal * SpectralWeights[curOctave];
            }

            return(value);
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Generates an output value given the coordinates of the specified input value.
        /// </summary>
        /// <param name="x">The input coordinate on the x-axis.</param>
        /// <param name="y">The input coordinate on the y-axis.</param>
        /// <returns>The resulting output value.</returns>
        public float GetValue(float x, float y)
        {
            x *= Frequency;
            y *= Frequency;

            return(Primitive2D.GetValue(x, y));
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Generates an output value given the coordinates of the specified input value.
        /// </summary>
        /// <param name="x">The input coordinate on the x-axis.</param>
        /// <param name="y">The input coordinate on the y-axis.</param>
        /// <returns>The resulting output value.</returns>
        public float GetValue(float x, float y)
        {
            float signal;
            int   curOctave;

            x *= Frequency;
            y *= Frequency;

            // Initialize value : get first octave of function; later octaves are weighted
            var value  = Primitive2D.GetValue(x, y) + Offset;
            var weight = Gain * value;

            x *= Lacunarity;
            y *= Lacunarity;

            // inner loop of spectral construction, where the fractal is built
            for (curOctave = 1; weight > 0.001 && curOctave < OctaveCount; curOctave++)
            {
                // prevent divergence
                if (weight > 1.0)
                {
                    weight = 1.0f;
                }

                // get next higher frequency
                signal = (Offset + Primitive2D.GetValue(x, y)) * SpectralWeights[curOctave];

                // The weighting from the previous octave is applied to the signal.
                signal *= weight;

                // Add the signal to the output value.
                value += signal;

                // update the (monotonically decreasing) weighting value
                weight *= Gain * signal;

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

            //take care of remainder in OctaveCount
            var remainder = OctaveCount - (int)OctaveCount;

            if (remainder > 0.0f)
            {
                signal  = Primitive2D.GetValue(x, y);
                signal *= SpectralWeights[curOctave];
                signal *= remainder;
                value  += signal;
            }

            return(value);
        }
        /// <summary>
        ///     Generates an output value given the coordinates of the specified input value.
        /// </summary>
        /// <param name="x">The input coordinate on the x-axis.</param>
        /// <param name="y">The input coordinate on the y-axis.</param>
        /// <returns>The resulting output value.</returns>
        public float GetValue(float x, float y)
        {
            float signal;
            int   curOctave;

            x *= Frequency;
            y *= Frequency;

            // Initialize value : first unscaled octave of function; later octaves are scaled
            var value = Offset + Primitive2D.GetValue(x, y);

            x *= Lacunarity;
            y *= Lacunarity;

            // inner loop of spectral construction, where the fractal is built
            for (curOctave = 1; curOctave < OctaveCount; curOctave++)
            {
                // obtain displaced noise value.
                signal = Offset + Primitive2D.GetValue(x, y);

                //scale amplitude appropriately for this frequency
                signal *= SpectralWeights[curOctave];

                // scale increment by current altitude of function
                signal *= value;

                // Add the signal to the output value.
                value += signal;

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

            //take care of remainder in OctaveCount
            var remainder = OctaveCount - (int)OctaveCount;

            if (remainder > 0.0f)
            {
                signal  = Offset + Primitive2D.GetValue(x, y);
                signal *= SpectralWeights[curOctave];
                signal *= value;
                signal *= remainder;
                value  += signal;
            }

            return(value);
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Generates an output value given the coordinates of the specified input value.
        /// </summary>
        /// <param name="x">The input coordinate on the x-axis.</param>
        /// <param name="y">The input coordinate on the y-axis.</param>
        /// <returns>The resulting output value.</returns>
        public float GetValue(float x, float y)
        {
            float signal;
            float value;
            int   curOctave;

            x *= Frequency;
            y *= Frequency;

            // Initialize value, fBM starts with 0
            value = 0;

            // Inner loop of spectral construction, where the fractal is built

            for (curOctave = 0; curOctave < OctaveCount; curOctave++)
            {
                // Get the coherent-noise value.
                signal = Primitive2D.GetValue(x, y) * SpectralWeights[curOctave];

                if (signal < 0.0f)
                {
                    signal = -signal;
                }

                // Add the signal to the output value.
                value += signal * PScale + PBias;

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

            //take care of remainder in OctaveCount
            var remainder = OctaveCount - (int)OctaveCount;

            if (remainder > 0)
            {
                value += PScale * remainder * Primitive2D.GetValue(x, y) * SpectralWeights[curOctave] + PBias;
            }

            return(value);
        }
Exemplo n.º 7
0
 public float GetValue(float x, float y)
 {
     return(Primitive2D.GetValue(x * XScale, y * ZScale));
 }