Exemplo n.º 1
0
    public float GetNoiseFactor(Vector3 pointOnUnitSphere, int index)
    {
        EarthNoise earthNoise   = noiseArray[index];
        float      factor       = 0;
        var        layerFreq    = earthNoise.noiseFrequency;
        var        layerStrenth = 1.0f;
        var        lastLayerV   = 1.0f; //only used in ridge generation

        for (int i = 0; i < earthNoise.noiseMultiLayer; i++)
        {
            var layerFactor = 0.0f;
            if (index == 0)
            {
                layerFactor = (noise.Evaluate(pointOnUnitSphere * layerFreq + earthNoise.noiseOffset) + 1) * 0.5f * layerStrenth;
            }
            else
            {
                var decimalValue         = 1 - Mathf.Abs(noise.Evaluate(pointOnUnitSphere * layerFreq + earthNoise.noiseOffset));
                var powed                = Mathf.Pow(decimalValue, 2);
                var multiplyByLastLayerV = powed * lastLayerV;
                lastLayerV  = multiplyByLastLayerV;
                layerFactor = multiplyByLastLayerV * layerStrenth;
            }

            factor       += layerFactor;
            layerFreq    *= earthNoise.noiseFrequencyMulti;
            layerStrenth *= earthNoise.noiseStrenthMulti;
        }

        // Make a threshould so that only value > threshould get shown
        // Others all keep 0
        factor = Mathf.Max(0, factor - earthNoise.noiseThreshould);

        return(factor * earthNoise.noiseStrength);
    }
Exemplo n.º 2
0
//#endif
    public float Evaluate(Vector3 point, float mountainRadiu, int seed)
    {
        float noiseValue = 0;
        float frequency  = settings.baseRoughness;
        float amplitude  = 1;

        for (int i = 0; i < settings.numLayers; i++)
        {
            float v = noise.Evaluate(point * frequency + settings.centre); //Generate noise
            noiseValue += (v + 1) * .5f * amplitude;                       //Set layer value
            //Increase based when greater than 1 and decrease when less that 1 for each layer
            frequency *= settings.roughness;
            amplitude *= settings.persistence;
        }

        if (point.y > -0.1f || point.y < -0.3f)
        {
            noiseValue = Mathf.Max(0, noiseValue - settings.minValue);
        }
        else
        {
            noiseValue = 0;
        }


        return(noiseValue * settings.strength);
    }
Exemplo n.º 3
0
    public float Evaluate(Vector3 point)
    {
        float noiseValue = 0;
        float frequency  = settings.baseRoughness;
        float amplitude  = 1;
        float weight     = 1;

        // Generate noise layers
        for (int i = 0; i < settings.numLayers; i++)
        {
            float v = 1 - Mathf.Abs(noise.Evaluate(point * frequency + settings.centre));
            v *= v;

            v     *= weight;
            weight = Mathf.Clamp01(v * settings.weightMultiplier); // propagate into weight to get clearly defined ridges and crevaces across multiple superimposed layers // Clamp01 clamps the value between 0 and 1

            noiseValue += v * amplitude;

            frequency *= settings.roughness;   // increment (increase) layer frequency
            amplitude *= settings.persistence; // increment (decrease) layer amplitude
        }

        noiseValue = noiseValue - settings.minValue; //Mathf.Max(0, noiseValue - settings.minValue); // minimum altitude is base sphere

        return(noiseValue * settings.strength);
    }
Exemplo n.º 4
0
    public float Evaluate(Vector3 point)
    {
        float noiseValue = 0;
        float frequency  = noiseSettings.baseRoughness;
        float amplitude  = 1;
        float weight     = 1;

        for (int i = 0; i < noiseSettings.noiseLayers; ++i)
        {
            float noiseIteration = 1 - Mathf.Abs(noise.Evaluate(point * frequency + noiseSettings.center));
            noiseIteration *= noiseIteration;

            // In each layer, we multiply the weight and set it for the next layer.
            // Regions that start out lower down remain undetailed in comparison to higher regions.
            noiseIteration *= weight;
            weight          = Mathf.Clamp01(noiseIteration * noiseSettings.weightMultiplier);

            noiseValue += noiseIteration * amplitude;

            frequency *= noiseSettings.roughness;
            amplitude *= noiseSettings.persistence;
        }

        noiseValue = Mathf.Max(0, noiseValue - noiseSettings.minimum);
        return(noiseValue * noiseSettings.strength);
    }
    public float EvaluateVertexPoint(Vector3 a_pointOnMesh, int a_vertexCount, int a_vertexDivisions)
    {
        //Use this layers noise function to evaluate where vertex should sit on mesh.
        float noiseValue = (m_noise.Evaluate(a_pointOnMesh, a_vertexCount, a_vertexDivisions) + 1) * 0.5f;

        return(noiseValue);
    }
Exemplo n.º 6
0
    public float Evaluate(Vector3 point)
    {
        float noiseValue = 0;
        float frequency  = settings.baseRoughness;
        float amplitude  = 1;
        float weight     = 1;

        for (int i = 0; i < settings.numberLayers; i++)
        {
            float v = noise.Evaluate(point * frequency + settings.center);
            v  = 1 - Mathf.Abs(v);
            v *= v;
            v *= weight;

            weight = Mathf.Clamp01(v * settings.weightMultiplier);

            noiseValue += v * amplitude;

            frequency *= settings.roughness;
            amplitude *= settings.persistence;
        }

        noiseValue = Mathf.Max(settings.minValue, noiseValue);
        return(noiseValue * settings.strength);
    }
Exemplo n.º 7
0
    public float Evaluate(Vector3 point)
    {
        //float noiseValue = noise.Evaluate(point);

        float noiseValue = 0;

        float frequency = noiseSettings.baseRoughness;
        float amplitude = 1;
        float weight    = 1;

        for (int i = 0; i < noiseSettings.layerCount; i++)
        {
            float v = 1 - Mathf.Abs(noise.Evaluate(point * frequency + noiseSettings.center));
            v     *= v;
            v     *= weight;
            weight = Mathf.Clamp01(v * noiseSettings.weightMultiplier);

            noiseValue += v * amplitude;
            frequency  *= noiseSettings.roughness;
            amplitude  *= noiseSettings.persistance;
        }

        noiseValue = Mathf.Max(0, noiseValue - noiseSettings.minValue);
        return(noiseValue * noiseSettings.strenght);
    }
Exemplo n.º 8
0
    public float GetDensity(float x, float y, float z)
    {
        Vector3 toCenter = new Vector3(x, y, z);

        float radius = noise.Evaluate(toCenter.normalized * 1000f / 40f) * 9f + 1000f;

        return(toCenter.magnitude - radius);
    }
    public float Evaluate(Vector3 _point)
    {
        float noiseValue = noise.Evaluate((_point + offset) * frequency);

        noiseValue = (noiseValue + 1) * 0.5f;

        return(noiseValue);
    }
Exemplo n.º 10
0
    public float Evaluate(Vector3 point)
    {
        float noiseValue = 0;
        float frequency  = settings.baseRoughness;
        float amplitude  = 1;
        float weight     = 1;
        float noiseIn    = 0;
        float spike      = 0;
        float layer;

        /*for (int i = 0; i < settings.numLayers; i++)
         * {
         *  float v = 1-Mathf.Abs(noise.Evaluate(point * frequency + settings.centre));
         *  v *= v;
         *  v *= weight;
         *  weight = Mathf.Clamp01(v * settings.weightMultiplier);
         *
         *  noiseValue += v * amplitude;
         *  frequency *= settings.roughness;
         *  amplitude *= settings.persistence;
         * }*/
        noiseValue += (Mathf.Clamp01(noise.Evaluate(point * 50 + settings.centre)) * 0.1f + 0.9f) * 0.15f;

        //Mountain Filter
        noiseIn = noise.Evaluate(point * 10 + settings.centre);
        layer   = Mathf.Pow(Mathf.Clamp01(noiseIn + 0.1f), 2) * 1f;
        //noiseValue += layer;

        //Mountains
        noiseIn     = 1 - Mathf.Abs(noise.Evaluate(point * 30 + settings.centre));
        layer       = Mathf.Pow(noiseIn, 2) * layer * 2;
        noiseValue += layer;

        //noiseIn = 1 - Mathf.Abs(noise.Evaluate(point * 40 + settings.centre));
        //layer = Mathf.Pow(noiseIn, 2)*5 * layer;
        //noiseValue += layer;

        float layer2 = layer;

        noiseIn     = 1 - Mathf.Abs(noise.Evaluate(point * 200 + settings.centre));
        layer       = Mathf.Pow(noiseIn, 2) * 0.5f * Mathf.Pow(Mathf.Clamp01(layer + 0.5f) - 0.5f, 2);
        noiseValue += layer;

        noiseIn     = 1 - Mathf.Abs(noise.Evaluate(point * 210 + settings.centre));
        layer       = -Mathf.Pow(noiseIn, 2) * 0.5f * Mathf.Pow(Mathf.Clamp01(layer2 + 0.5f) - 0.5f, 2);
        noiseValue += layer;

        noiseIn     = 1 - Mathf.Abs(noise.Evaluate(point * 500 + settings.centre));
        layer       = Mathf.Pow(noiseIn, 2) / 10 * layer;
        noiseValue += layer;
        //noiseValue *= spike;

        noiseIn     = noise.Evaluate(point * 400 + settings.centre);
        layer       = Mathf.Clamp01(Mathf.Pow((noiseIn - 0.0f), 2)) * 0.05f;
        noiseValue += layer;

        //noiseValue = noiseValue - settings.minValue;
        //noiseValue += spike;
        return(noiseValue * settings.strength);
    }
Exemplo n.º 11
0
        public static float[,] GenerateHeightmap(NoiseSettings noiseSettings, int size, bool normalize = true)
        {
            var map   = new float[size, size];
            var prng  = new Random(noiseSettings.seed);
            var noise = new Noise(noiseSettings.seed);

            // Generate random offset for each layer
            var offsets = new Vector2[noiseSettings.numLayers];

            for (var layer = 0; layer < noiseSettings.numLayers; layer++)
            {
                offsets[layer] = new Vector2((float)prng.NextDouble() * 2 - 1, (float)prng.NextDouble() * 2 - 1) *
                                 10000;
            }
            // offsets[layer] += noiseSettings.offset;

            var minHeight = float.MaxValue;
            var maxHeight = float.MinValue;

            for (var y = 0; y < size; y++)
            {
                for (var x = 0; x < size; x++)
                {
                    var   frequency = noiseSettings.scale;
                    float amplitude = 1;
                    float height    = 0;

                    // Sum layers of noise
                    for (var layer = 0; layer < noiseSettings.numLayers; layer++)
                    {
                        var sampleX = (double)x / size * frequency + offsets[layer].x + noiseSettings.offset.x;
                        var sampleY = (double)y / size * frequency + offsets[layer].y + noiseSettings.offset.y;
                        height    += (float)noise.Evaluate(sampleX, sampleY) * amplitude;
                        frequency *= noiseSettings.lacunarity;
                        amplitude *= noiseSettings.persistence;
                    }

                    map[x, y] = height;
                    minHeight = Mathf.Min(minHeight, height);
                    maxHeight = Mathf.Max(maxHeight, height);
                }
            }

            // Normalize values to range 0-1
            if (normalize)
            {
                for (var y = 0; y < size; y++)
                {
                    for (var x = 0; x < size; x++)
                    {
                        map[x, y] = Mathf.InverseLerp(minHeight, maxHeight, map[x, y]);
                    }
                }
            }

            return(map);
        }
Exemplo n.º 12
0
    private void MapElevation()
    {
        Noise noise = new Noise();

        noise.SetParameters(8, 0.5f, 0.25f, 1f, 2f);
        foreach (ErosionRegion region in erosionRegions.Values)
        {
            region.Elevation = (noise.Evaluate(region.Center) + 1f) / 2f;
        }
    }
Exemplo n.º 13
0
    public float Evaluate(Vector3 point)
    {
        float to   = perlin.Evaluate(point);
        float from = oldPerlin.Evaluate(point);

        float evaluation = Mathf.Lerp(from, to, passedTime / settings.duration);

        evaluation = noiseFilter.Evaluate(evaluation);

        return(evaluation);
    }
Exemplo n.º 14
0
    public static float[,] Generate(NoiseSettings noiseSettings, int width, int length, bool normalize = true)
    {
        float[,] map = new float[width, length];
        System.Random prng  = new System.Random(noiseSettings.seed);
        Noise         noise = new Noise(noiseSettings.seed);

        Vector2[] offsets = new Vector2[noiseSettings.numLayers];

        for (int layer = 0; layer < noiseSettings.numLayers; layer++)
        {
            // use settings
            offsets[layer] = new Vector2((float)prng.NextDouble() * 2 - 1, (float)prng.NextDouble() * 2 - 1) * 10000;
        }

        float minHeight = float.MaxValue;
        float maxHeight = float.MinValue;

        for (int l = 0; l < length; l++)
        {
            for (int w = 0; w < width; w++)
            {
                float frequency = noiseSettings.scale;
                float amplitude = 1;
                float height    = 0;

                // Sum layers of noise
                for (int layer = 0; layer < noiseSettings.numLayers; layer++)
                {
                    double sampleX = (double)w / width * frequency + offsets[layer].x + noiseSettings.offset.x;
                    double sampleY = (double)l / length * frequency + offsets[layer].y + noiseSettings.offset.y;
                    height    += (float)noise.Evaluate(sampleX, sampleY) * amplitude;
                    frequency *= noiseSettings.lacunarity;
                    amplitude *= noiseSettings.persistence;
                }
                map[w, l] = height;

                minHeight = Mathf.Min(minHeight, height);
                maxHeight = Mathf.Max(maxHeight, height);
            }
        }

        if (normalize)
        {
            for (int y = 0; y < length; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    map[x, y] = Mathf.InverseLerp(minHeight, maxHeight, map[x, y]);
                }
            }
        }

        return(map);
    }
Exemplo n.º 15
0
    void Generate(int width, int height)
    {
        Vector2 planetCentre = new Vector2(width / 2f, height / 2f);
        float   planetRadius = Mathf.Max(width, height) / 2f;

        for (int y = 0; y *yOffset <= height / 2 + 2 *border *yOffset; y++)
        {
            for (int x = 0; x *xOffset <= width / 2 + 2 *border *xOffset; x++)
            {
                Vector3 position = new Vector3(x * xOffset + y * yOffset * .5f + (y % 2) * 0.079f - (y / 2) * yOffset, y * yOffset, 0);
                if (position.magnitude <= planetRadius)
                {
                    float noiseValue = (noise.Evaluate(position * noiseScale) + 1) * .5f;
                    if (noiseValue >= noiseThreshhold)
                    {
                        CreatePlanetNode(x - y / 2, y, position);
                    }
                    else
                    {
                        CreateBlankNode(x - y / 2, y, position);
                    }
                }
                else
                {
                    CreateBlankNode(x - y / 2, y, position);
                }

                if (x != 0)
                {
                    x *= -1;
                    if (x < 0)
                    {
                        x--;
                    }
                }
            }

            if (y != 0)
            {
                y *= -1;
                if (y < 0)
                {
                    y--;
                }
            }
        }

        ProcessMap();

        StaticBatchingUtility.Combine(nodeHolder.gameObject);
    }
Exemplo n.º 16
0
        private void SetMaterialSettings()
        {
            var sphereSettings = Resources.Load <SphereSettings>("SphereSettings");

            var texture2D = new Texture2D(sphereSettings.textureSize, sphereSettings.textureSize, TextureFormat.RG16, false)
            {
                filterMode = FilterMode.Point, wrapMode = TextureWrapMode.Clamp
            };

            var noiseR = new Noise(DateTime.Now.Millisecond);
            var noiseG = new Noise(DateTime.Now.Millisecond / 2);

            for (int i = 0; i < sphereSettings.textureSize; i++)
            {
                for (int j = 0; j < sphereSettings.textureSize; j++)
                {
                    var rValue = noiseR.Evaluate(new Vector3(i, j) * sphereSettings.frequency) * sphereSettings.power;
                    var gValue = noiseG.Evaluate(new Vector3(i, j) * sphereSettings.frequency) * sphereSettings.power;

                    texture2D.SetPixel(i, j, new Color(rValue, gValue, 0f));
                }
            }

            texture2D.Apply();

            sphereSettings.SphereMaterial.SetTexture("_Noise", texture2D);
            sphereSettings.SphereMaterial.SetFloat("Speed", sphereSettings.speed);
            MaterialPropertyBlock props = new MaterialPropertyBlock();

            foreach (var sphere in _spheres)
            {
                var color = Random.ColorHSV(0,
                                            1,
                                            1,
                                            1,
                                            1,
                                            1,
                                            0.7f,
                                            0.9f);

                Vector3 lightVector = (Vector3.up * Random.Range(-10f, 10f) +
                                       Vector3.right * Random.Range(-10f, 10f) +
                                       Vector3.back * 20).normalized;
                props.SetColor("_Color", color);
                props.SetVector("_LightVector", lightVector);
                sphere.SphereMeshRenderer.SetPropertyBlock(props);
            }
        }
Exemplo n.º 17
0
    public float evaluate(Vector3 point)
    {
        float noiseValue = 0;
        float frequency  = settings.baseRoughness;
        float amplitude  = 1;

        for (int i = 0; i < settings.nLayers; i++)
        {
            float v = noise.Evaluate(point * frequency + settings.centre);
            noiseValue += (v + 1) * .5f * amplitude;
            frequency  *= settings.roughness;   //roughness > 1 -> frequency of noise increases with each layer
            amplitude  *= settings.persistence; //persistence < 1 -> amplitude decreases with each layer
        }
        noiseValue = noiseValue - settings.minValue;
        return(noiseValue * settings.strength);
    }
        public double SimpleNoiseFilterProcess(double3 point, ref Noise noise)
        {
            double noiseValue = 0;
            double frequency  = baseRoughness;
            double amplitude  = 1;

            for (int i = 0; i < numLayers; i++)
            {
                double v = noise.Evaluate(point * frequency + center);
                noiseValue += (v + 1) * .5f * amplitude;
                frequency  *= roughness;
                amplitude  *= persistence;
            }

            return((noiseValue - 1) * strength);
        }
Exemplo n.º 19
0
    public float Evaluate(Vector3 point)
    {
        float noiseValue = 0;
        float frequency  = settings.BaseRoughness;
        float amplitude  = 1;

        for (int i = 0; i < settings.NumLayers; i++)
        {
            float v = noise.Evaluate(point * frequency + settings.Centre);
            noiseValue += (v + 1) * .5f * amplitude;
            frequency  *= settings.Roughness;
            amplitude  *= settings.Persistence;
        }
        noiseValue = Mathf.Max(0, noiseValue - settings.MinValue);
        return(noiseValue * settings.Strength);
    }
Exemplo n.º 20
0
    public float Evaluate(Vector3 _point)
    {
        float noiseValue  = 0;
        float roughness   = settings.baseRoughness;
        float persistence = 1;

        for (var i = 0; i < settings.octaves; i++)
        {
            float v = noise.Evaluate(_point * roughness + settings.centre);
            noiseValue  += v * persistence;
            roughness   *= settings.roughness;
            persistence *= settings.persistence;
        }

        return(noiseValue * settings.scale);
    }
Exemplo n.º 21
0
    public float Evaluate(Vector3 point)
    {
        float noiseValue = 0;
        float frequency  = settings.baseRoughness;
        float amplitude  = 1;

        for (int i = 0; i < settings.numLayers; i++)
        {
            float v = noise.Evaluate(point * frequency + settings.center);
            noiseValue += (v + 1) * 0.5f * amplitude;
            frequency  *= settings.roughness;
            amplitude  *= settings.persistance;
        }
        noiseValue = Mathf.Max(0, noiseValue - settings.minValue);
        return(noiseValue * settings.strength);
    }
Exemplo n.º 22
0
    public float Evaluate(Vector3 point)
    {
        float noiseValue = 0;
        float frequency  = baseRoughness;
        float amplitude  = 1;

        for (int i = 0; i < numLayers; i++)
        {
            float v = noise.Evaluate(point * frequency + centre);
            noiseValue += (v + 1) * .5f * amplitude;
            frequency  *= roughness;
            amplitude  *= persistence;
        }
        noiseValue = Mathf.Max(0, noiseValue - minValue);
        return(noiseValue * strength);
    }
    public float Evaluate(Vector3 point)
    {
        float value     = 0;
        float frequency = settings.baseRoughness;
        float amplitude = settings.strength;

        for (int i = 0; i < settings.layersCount; ++i)
        {
            float t = noise.Evaluate(point * frequency + settings.center);
            value     += (t + 1) * 0.5f * amplitude;
            frequency *= settings.roughness;
            amplitude *= settings.persistence;
        }

        return(value);
    }
Exemplo n.º 24
0
    public float Eval(Vector3 point)
    {
        float value = 0;
        float freq  = noiseSettings.startRough;
        float amp   = 1;

        for (int i = 0; i < noiseSettings.layerCount; i++)
        {
            float j = noise.Evaluate(point * freq + noiseSettings.center);
            value += ((1 + j) / 2) * amp;
            freq  *= noiseSettings.rough;
            amp   *= noiseSettings.persist;
        }
        value = Mathf.Max(0, value - noiseSettings.min);
        return(value * noiseSettings.strength);
    }
Exemplo n.º 25
0
    public float Evaluate(Vector3 position, NoiseSettings settings, bool limit)
    {
        float noiseValue = 0;
        float frequency  = settings.baseRoughness;
        float amplitude  = 1;

        for (int i = 0; i < settings.numberLayers; i++)
        {
            float v = noise.Evaluate(position * frequency + settings.noiseCenter);
            noiseValue += (v + 1) / 2 * amplitude;
            frequency  *= settings.roughness;
            amplitude  *= settings.persistence;
        }
        // if (limit)
        //   noiseValue = Mathf.Max(0, noiseValue - settings.minValue);
        return(noiseValue * settings.strength);
    }
Exemplo n.º 26
0
    public float Evaluate(Vector3 point)
    {
        float noiseValue = 0;//(noise.Evaluate(point * settings.roughtness + settings.center) + 1) * 0.5f;
        float frequency  = settings.baseRoughtness;
        float amplitude  = 1;

        for (int i = 0; i < settings.octaves; i++)
        {
            float v = noise.Evaluate(point * frequency + settings.center);
            noiseValue += (v + 1) * 0.5f * amplitude;
            frequency  *= settings.roughtness;
            amplitude  *= settings.persistence;
        }

        noiseValue = noiseValue - settings.minValue;
        return(noiseValue * settings.strenght);
    }
    public float Evaluate(Vector3 pos)
    {
        float noiseValue = 0;
        float frequency  = settings.baseFrequency;
        float amplitude  = 1;

        for (int i = 0; i < settings.octaves; ++i)
        {
            float v = noise.Evaluate(pos * frequency + settings.center);
            noiseValue += (v + 1) * .5f * amplitude;
            frequency  *= settings.frequency;
            amplitude  *= settings.persistence;
        }

        noiseValue = noiseValue - settings.minValue;
        return(noiseValue * settings.strength);
    }
    public float Evaluate(Vector3 point)
    {
        float noiseValue = 0;
        float frequency  = settings.baseRoughness;
        float amplitude  = 1;

        for (int i = 0; i < settings.numLays; i++)
        {
            float v = noise.Evaluate(point * frequency + settings.center);
            noiseValue += amplitude * (v + 1) * 1 / 2;
            frequency  *= settings.roughness;
            amplitude  *= settings.persistence;
            //when roughness > 1 the frequency will increase with each layer, and when persistence < 1 amplitude will decrease
        }
        noiseValue = Mathf.Max(0, noiseValue - settings.minValue); // we do not want negative noise
        return(noiseValue * settings.strength);
    }
    public float Evaluate(Vector3 point)
    {
        float noiseValue = 0;
        float frequency  = _settings.baseRoughness;
        float amplitude  = 1;

        for (int i = 0; i < _settings.numLayers; i++)
        {
            float v = _noise.Evaluate(point * frequency + _settings.center);
            noiseValue += (v + 1) * .5f * amplitude;
            frequency  *= _settings.roughness;
            amplitude  *= _settings.persistence;
        }

        noiseValue = noiseValue - _settings.minValue;
        return(noiseValue * _settings.strength);
    }
Exemplo n.º 30
0
    public float Eval(Vector3 point)
    {
        float noiseVal = 0f;
        float freq     = settings.baseRoughness;
        float amp      = 1f;

        for (int i = 0; i < settings.numLayers; i++)
        {
            float v = noise.Evaluate(point * freq + settings.centre);
            noiseVal += (v + 1) * .5f * amp;
            amp      *= settings.persistence;
            freq     *= settings.roughness;
        }

        noiseVal = Mathf.Max(0, noiseVal - settings.minValue);
        return(noiseVal * settings.strength);
    }