示例#1
0
        public override double GetValue(double x, double y, double z)
        {
            double value          = 0.0;
            double signal         = 0.0;
            double curPersistence = 1.0;
            long   seed;

            double lacunarity = Lacunarity.GetValue(x, y, z);
            double persist    = Persistence.GetValue(x, y, z);
            double frequency  = Frequency.GetValue(x, y, z);

            x *= frequency;
            y *= frequency;
            z *= frequency;

            int mOctaveCount = (int)OctaveCount.GetValue(x, y, z);

            for (int currentOctave = 0; currentOctave < mOctaveCount; currentOctave++)
            {
                seed   = (Seed + currentOctave) & 0xffffffff;
                signal = GradientCoherentNoise(x, y, z, (int)seed, NoiseQuality);
                signal = 2.0 * System.Math.Abs(signal) - 1.0;
                value += signal * curPersistence;

                x *= lacunarity;
                y *= lacunarity;
                z *= lacunarity;
                curPersistence *= persist;
            }

            value += 0.5;

            return(value);
        }
示例#2
0
        public override double GetValue(double x, double y)
        {
            double value          = 0.0;
            double signal         = 0.0;
            double curPersistence = 1.0;
            //double nx, ny, nz;
            long seed;

            double lacunarity  = Lacunarity.GetValue(x, y);
            double persistence = Persistence.GetValue(x, y);
            double frequency   = Frequency.GetValue(x, y);

            x *= frequency;
            y *= frequency;

            int mOctaveCount = (int)OctaveCount.GetValue(x, y);

            for (int currentOctave = 0; currentOctave < mOctaveCount; currentOctave++)
            {
                seed = (Seed + currentOctave) & 0xffffffff;

                signal = GradientNoise.GradientCoherentNoise(x, y, (int)seed, NoiseQuality);

                value += signal * curPersistence;

                x *= lacunarity;
                y *= lacunarity;
                curPersistence *= persistence;
            }

            return(value);
        }
示例#3
0
        public override double GetValue(double x, double y, double z)
        {
            double lacunarity = Lacunarity.GetValue(x, y, z);
            double frequency  = Frequency.GetValue(x, y, z);

            x *= frequency;
            y *= frequency;
            z *= frequency;

            int mOctaveCount = (int)OctaveCount.GetValue(x, y, z);

            double signal = 0.0;
            double value  = 0.0;
            double weight = 1.0;

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

            for (int currentOctave = 0; currentOctave < mOctaveCount; currentOctave++)
            {
                long seed = (Seed + currentOctave) & 0x7fffffff;
                signal = GradientCoherentNoise(x, y, z, (int)seed, NoiseQuality);

                // Make the ridges.
                signal = System.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[currentOctave]);

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

            return((value * 1.25) - 1.0);
        }
示例#4
0
        private void CalculateSpectralWeights()
        {
            double h = 1.0;

            double lacunarity = Lacunarity.GetValue(0, 0);
            double frequency  = 1.0;

            for (int i = 0; i < MaxOctaves; i++)
            {
                // Compute weight for each frequency.
                SpectralWeights[i] = System.Math.Pow(frequency, -h);
                frequency         *= lacunarity;
            }
        }
示例#5
0
        public override DrawStackNode Allocate(DrawInfo info, SurfaceTexture tex, ref int stackID)
        {
            // Stack required.

            // Allocate a target stack now:
            int       targetStack = stackID;
            DrawStack stack       = tex.GetStack(targetStack, info);

            stackID++;

            float curAmplitude = 1f;
            float curFrequency = (float)Frequency.GetValue(0, 0);
            float lacunarity   = (float)Lacunarity.GetValue(0, 0);
            float persistence  = (float)Persistence.GetValue(0, 0);
            int   mOctaveCount = (int)OctaveCount.GetValue(0, 0);

            Material[] materials = new Material[mOctaveCount];

            // Stack up "OctaveCount" quads.
            for (int currentOctave = 0; currentOctave < mOctaveCount; currentOctave++)
            {
                // Update seed:
                long seed = (Seed + currentOctave) & 0xffffffff;

                // And a material.
                UnityEngine.Material material = GetMaterial(TypeID, SubMaterialID);

                // _Data (Seed, Frequency, Amplitude, Jitter):
                material.SetVector("_Data", new Vector4(seed, curFrequency, curAmplitude, 0f));

                // Add to set:
                materials[currentOctave] = material;

                curFrequency *= lacunarity;
                curAmplitude *= persistence;
            }

            // Create our node:
            BlockStackNode bsn = new BlockStackNode();

            DrawStore     = bsn;
            bsn.Mesh      = info.Mesh;
            bsn.Materials = materials;
            bsn.Stack     = stack;

            return(bsn);
        }