// VALUE //

    public static NoiseSample Value1D(Vector3 point, float frequency, bool derivative)
    {
        point *= frequency;

        int i0 = Mathf.FloorToInt(point.x);

        i0 &= hashMask;
        int i1 = i0 + 1;

        int h0 = GameUtils.Hash[i0];
        int h1 = GameUtils.Hash[i1];

        float a = h0;
        float b = h1 - h0;

        float t  = point.x - i0;
        float ts = GameUtils.Smooth(t);

        NoiseSample sample = new NoiseSample();

        sample.value = a + b * ts;

        if (derivative)
        {
            float dt = GameUtils.SmoothDerivative(t);

            sample.derivative.x = b * dt;
            sample.derivative.y = 0f;
            sample.derivative.z = 0f;

            sample.derivative *= frequency;
        }

        return(sample * (2f / hashMask) - 1f);
    }
    private void FillTexture()
    {
        NoiseMethod method = Noise.noiseMethods[(int)type][dimensions - 1];

        float stepSize = 1f / resolution;

        Vector3 point00 = transform.TransformPoint(new Vector3(-0.5f, -0.5f));
        Vector3 point10 = transform.TransformPoint(new Vector3(0.5f, -0.5f));
        Vector3 point01 = transform.TransformPoint(new Vector3(-0.5f, 0.5f));
        Vector3 point11 = transform.TransformPoint(new Vector3(0.5f, 0.5f));

        for (int y = 0; y < resolution; y++)
        {
            Vector3 point0 = Vector3.Lerp(point00, point01, (y + 0.5f) * stepSize);
            Vector3 point1 = Vector3.Lerp(point10, point11, (y + 0.5f) * stepSize);

            for (int x = 0; x < resolution; x++)
            {
                Vector3 point = Vector3.Lerp(point0, point1, (x + 0.5f) * stepSize);

                NoiseSample sample = Noise.Sum(method, point, frequency, octaves, lacunarity, persistence);

                sample = sample * 0.5f + 0.5f;

                texture.SetPixel(x, y, Color.white * coloring.Evaluate(sample.value));
            }
        }

        texture.Apply();
    }
Exemple #3
0
    public NoiseSample[,] CreateNoise(Vector2 location, Vector2Int size, int chunkSize, int seed)
    {
        danny.Begin();

        // create a item to return
        NoiseSample[,] NoiseMap = new NoiseSample[size.x, size.y];


        // generate map heights with octaves each octave being more imporatant in generation than last
        for (int X = 0; X < NoiseMap.GetLength(0); X++)
        {
            for (int Z = 0; Z < NoiseMap.GetLength(1); Z++)
            {
                Vector3 pos = (Vector3)((new Vector2(X - 1, Z - 1) + location * 240f) / 240f);


                NoiseSample height = Desert(pos);


                NoiseMap[X, Z] = height;
            }
        }

        danny.End();
        return(NoiseMap);
    }
Exemple #4
0
    public void Refresh()
    {
        if (resolution != currentResolution)
        {
            CreateGrid();
        }

        Quaternion q       = Quaternion.Euler(rotation);
        Vector3    point00 = q * new Vector3(-0.5f, -0.5f) + offset;
        Vector3    point10 = q * new Vector3(0.5f, -0.5f) + offset;
        Vector3    point01 = q * new Vector3(-0.5f, 0.5f) + offset;
        Vector3    point11 = q * new Vector3(0.5f, 0.5f) + offset;

        NoiseMethod method   = Noise.noiseMethods[(int)type][dimensions - 1];
        float       stepSize = 1f / resolution;

        float amplitude = damping ? strength / frequency : strength;

        for (int v = 0, y = 0; y <= resolution; y++)
        {
            Vector3 point0 = Vector3.Lerp(point00, point01, y * stepSize);
            Vector3 point1 = Vector3.Lerp(point10, point11, y * stepSize);

            for (int x = 0; x <= resolution; x++, v++)
            {
                Vector3 point = Vector3.Lerp(point0, point1, x * stepSize);

                NoiseSample sample = Noise.Sum(method, point, frequency, octaves, lacunarity, persistence);

                sample = type == NoiseMethodType.Value ? (sample - 0.5f) : (sample * 0.5f);

                if (coloringForStrength)
                {
                    colors[v] = coloring.Evaluate(sample.value + 0.5f);
                    sample   *= amplitude;
                }

                else
                {
                    sample   *= amplitude;
                    colors[v] = coloring.Evaluate(sample.value + 0.5f);
                }

                vertices[v].y = sample.value;

                sample *= strength;

                if (type != NoiseMethodType.Value)
                {
                    sample = sample * 0.5f + 0.5f;
                }
                vertices[v].y = sample.value;
                // colors[v] = coloring.Evaluate(sample + 0.5f);
            }
        }
        mesh.vertices = vertices;
        mesh.colors   = colors;
        CalculateNormals();
        mesh.normals = normals;
    }
    private static NoiseSample SimplexValue2DPart(Vector3 point, int ix, int iy, bool derivative)
    {
        float unskew = (ix + iy) * squaresToTriangles;
        float x      = point.x - ix + unskew;
        float y      = point.y - iy + unskew;
        float f      = 0.5f - x * x - y * y;

        NoiseSample sample = new NoiseSample();

        if (f > 0f)
        {
            float f2 = f * f;
            float f3 = f * f2;
            float h  = GameUtils.Hash[GameUtils.Hash[ix & hashMask] + iy & hashMask];

            sample.value = h * f3;

            if (derivative)
            {
                float h6f2 = -6f * h * f2;
                sample.derivative.x = h6f2 * x;
                sample.derivative.y = h6f2 * y;
            }
        }

        return(sample);
    }
Exemple #6
0
    private void PositionParticles()
    {
        Quaternion  q         = Quaternion.Euler(rotation);
        Quaternion  qInv      = Quaternion.Inverse(q);
        NoiseMethod method    = Noise.methods[(int)type][dimensions - 1];
        float       amplitude = damping ? strength / frequency : strength;

        morphOffset += Time.deltaTime * morphSpeed;
        if (morphOffset > 256f)
        {
            morphOffset -= 256f;
        }
        for (int i = 0; i < particles.Length; i++)
        {
            Vector3     position = particles[i].position;
            Vector3     point    = q * new Vector3(position.z, position.y, position.x + morphOffset) + offset;
            NoiseSample sampleX  = Noise.Sum(method, point, frequency, octaves, lacunarity, persistence);
            sampleX           *= amplitude;
            sampleX.derivative = qInv * sampleX.derivative;
            point = q * new Vector3(position.x + 100f, position.z, position.y + morphOffset) + offset;
            NoiseSample sampleY = Noise.Sum(method, point, frequency, octaves, lacunarity, persistence);
            sampleY           *= amplitude;
            sampleY.derivative = qInv * sampleY.derivative;
            point = q * new Vector3(position.y, position.x + 100f, position.z + morphOffset) + offset;
            NoiseSample sampleZ = Noise.Sum(method, point, frequency, octaves, lacunarity, persistence);
            sampleZ           *= amplitude;
            sampleZ.derivative = qInv * sampleZ.derivative;
            Vector3 curl;
            curl.x = sampleZ.derivative.x - sampleY.derivative.y;
            curl.y = sampleX.derivative.x - sampleZ.derivative.y;
            curl.z = sampleY.derivative.x - sampleX.derivative.y;
            particles[i].velocity = curl;
        }
    }
    public override NoiseSample interpolate(float x, float y, float z)
    {
        NoiseMethod method = Noise.methods[(int)NoiseMethodType.Simplex][2];
        NoiseSample sample = Noise.Sum(method, new Vector3(x, y, z), 1, 2, 2, .5f);

        return(sample);
    }
    private static NoiseSample Simplex3DPart(Vector3 point, int ix, int iy, int iz, bool derivative)
    {
        float unskew = (ix + iy + iz) * (1f / 6f);

        float x = point.x - ix + unskew;
        float y = point.y - iy + unskew;
        float z = point.z - iz + unskew;
        float f = 0.5f - x * x - y * y - z * z;

        NoiseSample sample = new NoiseSample();

        if (f > 0f)
        {
            float f2 = f * f;
            float f3 = f * f2;

            Vector3 g = simplexGradients3D[GameUtils.Hash[GameUtils.Hash[GameUtils.Hash[ix & hashMask] + iy & hashMask] + iz & hashMask] & simplexGradientsMask3D];
            float   v = GameUtils.Dot(g, x, y, z);

            sample.value = v * f3;

            if (derivative)
            {
                float v6f2 = -6f * v * f2;
                sample.derivative.x = g.x * f3 + v6f2 * x;
                sample.derivative.y = g.y * f3 + v6f2 * y;
                sample.derivative.z = g.z * f3 + v6f2 * z;
            }
            else
            {
                sample.derivative = Vector3.zero;
            }
        }
        return(sample);
    }
    private static NoiseSample Simplex2DPart(Vector3 point, int ix, int iy, bool derivative)
    {
        float       unskew = (ix + iy) * squaresToTriangles;
        float       x      = point.x - ix + unskew;
        float       y      = point.y - iy + unskew;
        float       f      = 0.5f - x * x - y * y;
        NoiseSample sample = new NoiseSample();

        if (f > 0f)
        {
            float   f2   = f * f;
            float   f3   = f * f2;
            Vector2 g    = gradients2D[GameUtils.Hash[GameUtils.Hash[ix & hashMask] + iy & hashMask] & gradientsMask2D];
            float   v    = GameUtils.Dot(g, x, y);
            float   v6f2 = -6f * v * f2;
            sample.value = v * f3;
            if (derivative)
            {
                sample.derivative.x = g.x * f3 + v6f2 * x;
                sample.derivative.y = g.y * f3 + v6f2 * y;
            }
            else
            {
                sample.derivative = Vector3.zero;
            }
        }
        return(sample);
    }
Exemple #10
0
    public static NoiseSample SimplexGradient2D(Vector3 point, float frequency)
    {
        point *= frequency;

        float skew = (point.x + point.y) * trianglesToSquares;
        float sx   = point.x + skew;
        float sy   = point.y + skew;

        int ix = Mathf.FloorToInt(sx);
        int iy = Mathf.FloorToInt(sy);

        NoiseSample sample = SimplexGradient2DPart(point, ix, iy);

        sample += SimplexGradient2DPart(point, ix + 1, iy + 1);

        if (sx - ix >= sy - iy)
        {
            sample += SimplexGradient2DPart(point, ix + 1, iy);
        }
        else
        {
            sample += SimplexGradient2DPart(point, ix, iy + 1);
        }

        return(sample * simplexScale2D);
    }
Exemple #11
0
    public static NoiseSample Simplex3D(Vector3 point, float frequency)
    {
        point *= frequency;
        float       skew   = (point.x + point.y + point.z) * (1f / 3f);
        float       sx     = point.x + skew;
        float       sy     = point.y + skew;
        float       sz     = point.z + skew;
        int         ix     = Mathf.FloorToInt(sx);
        int         iy     = Mathf.FloorToInt(sy);
        int         iz     = Mathf.FloorToInt(sz);
        NoiseSample sample = Simplex3DPart(point, ix, iy, iz);

        sample += Simplex3DPart(point, ix + 1, iy + 1, iz + 1);
        float x = sx - ix;
        float y = sy - iy;
        float z = sz - iz;

        if (x >= y)
        {
            if (x >= z)
            {
                sample += Simplex3DPart(point, ix + 1, iy, iz);
                if (y >= z)
                {
                    sample += Simplex3DPart(point, ix + 1, iy + 1, iz);
                }
                else
                {
                    sample += Simplex3DPart(point, ix + 1, iy, iz + 1);
                }
            }
            else
            {
                sample += Simplex3DPart(point, ix, iy, iz + 1);
                sample += Simplex3DPart(point, ix + 1, iy, iz + 1);
            }
        }
        else
        {
            if (y >= z)
            {
                sample += Simplex3DPart(point, ix, iy + 1, iz);
                if (x >= z)
                {
                    sample += Simplex3DPart(point, ix + 1, iy + 1, iz);
                }
                else
                {
                    sample += Simplex3DPart(point, ix, iy + 1, iz + 1);
                }
            }
            else
            {
                sample += Simplex3DPart(point, ix, iy, iz + 1);
                sample += Simplex3DPart(point, ix, iy + 1, iz + 1);
            }
        }
        sample.derivative *= frequency;
        return(sample * simplexScale3D);
    }
    private void PositionParticles()
    {
        Quaternion  q         = Quaternion.Euler(surface.rotation);
        Quaternion  qInv      = Quaternion.Inverse(q);
        NoiseMethod method    = Noise.methods[(int)surface.type][surface.dimensions - 1];
        float       amplitude = surface.damping ? surface.strength / surface.frequency : surface.strength;

        for (int i = 0; i < particles.Length; i++)
        {
            Vector3     position = particles[i].position;
            Vector3     point    = q * new Vector3(position.x, position.z) + surface.offset;
            NoiseSample sample   = Noise.Sum(method, point, surface.frequency, surface.octaves, surface.lacunarity, surface.persistence);
            sample            = sample * 0.5f;
            sample           *= amplitude;
            sample.derivative = qInv * sample.derivative;
            Vector3 curl = new Vector3(sample.derivative.y, 0f, -sample.derivative.x);
            position             += curl * Time.deltaTime * flowStrength;
            position.y            = sample.value + system.main.startSize.constant;
            particles[i].position = position;
            if (position.x < -0.5f || position.x > 0.5f || position.z < -0.5f || position.z > 0.5f)
            {
                particles[i].remainingLifetime = 0f;
            }
        }
    }
Exemple #13
0
    public static NoiseSample SimplexValue2D(Vector3 point, float frequency, bool derivative)
    {
        point *= frequency;
        float       skew   = (point.x + point.y) * trianglesToSquares;
        float       sx     = point.x + skew;
        float       sy     = point.y + skew;
        int         ix     = Mathf.FloorToInt(sx);
        int         iy     = Mathf.FloorToInt(sy);
        NoiseSample sample = SimplexValue2DPart(point, ix, iy, derivative);

        sample += SimplexValue2DPart(point, ix + 1, iy + 1, derivative);
        if (sx - ix >= sy - iy)
        {
            sample += SimplexValue2DPart(point, ix + 1, iy, derivative);
        }
        else
        {
            sample += SimplexValue2DPart(point, ix, iy + 1, derivative);
        }
        if (derivative)
        {
            sample.derivative *= frequency;
        }

        return(sample * (8f * 2f / hashMask) - 1f);
    }
Exemple #14
0
    private static NoiseSample SimplexValue3DPart(Vector3 point, int ix, int iy, int iz, bool derivative)
    {
        float       unskew = (ix + iy + iz) * (1f / 6f);
        float       x      = point.x - ix + unskew;
        float       y      = point.y - iy + unskew;
        float       z      = point.z - iz + unskew;
        float       f      = 0.5f - x * x - y * y - z * z;
        NoiseSample sample = new NoiseSample();

        if (f > 0f)
        {
            float f2 = f * f;
            float f3 = f * f2;
            float h  = GameUtils.Hash[GameUtils.Hash[GameUtils.Hash[ix & hashMask] + iy & hashMask] + iz & hashMask];

            sample.value = h * f3;

            if (derivative)
            {
                float h6f2 = -6f * h * f2;
                sample.derivative.x = h6f2 * x;
                sample.derivative.y = h6f2 * y;
                sample.derivative.z = h6f2 * z;
            }
            else
            {
                sample.derivative = Vector3.zero;
            }
        }
        return(sample);
    }
Exemple #15
0
    public void Refresh()
    {
        if (mesh == null)
        {
            Init();
        }
        if (resolution != currentResolution)
        {
            CreateGrid();
        }
        Quaternion q       = Quaternion.Euler(rotation);
        Quaternion qInv    = Quaternion.Inverse(q);
        Vector3    point00 = q * new Vector3(-0.5f, -0.5f) + offset;
        Vector3    point10 = q * new Vector3(0.5f, -0.5f) + offset;
        Vector3    point01 = q * new Vector3(-0.5f, 0.5f) + offset;
        Vector3    point11 = q * new Vector3(0.5f, 0.5f) + offset;

        NoiseMethod method    = Noise.methods[(int)type][dimensions - 1];
        float       stepSize  = 1f / resolution;
        float       amplitude = damping ? strength / frequency : strength;

        for (int v = 0, y = 0; y <= resolution; ++y)
        {
            Vector3 point0 = Vector3.Lerp(point00, point01, y * stepSize);
            Vector3 point1 = Vector3.Lerp(point10, point11, y * stepSize);
            for (int x = 0; x <= resolution; ++x, ++v)
            {
                Vector3     point  = Vector3.Lerp(point0, point1, x * stepSize);
                NoiseSample sample = Noise.Sum(method, point, frequency, octaves, lacunarity, persistence);
                sample = type == NoiseMethodType.Value ? (sample - 0.5f) : (sample * 0.5f);
                if (coloringForStrength)
                {
                    colors[v] = coloring.Evaluate(sample.value + 0.5f);
                    sample   *= amplitude;
                }
                else
                {
                    sample   *= amplitude;
                    colors[v] = coloring.Evaluate(sample.value + 0.5f);
                }
                vertices[v].y     = sample.value;
                sample.derivative = qInv * sample.derivative;
                if (analyticalDerivatives)
                {
                    normals[v] = new Vector3(-sample.derivative.x, 1f, -sample.derivative.y).normalized;
                }
            }
        }
        mesh.vertices = vertices;
        mesh.colors   = colors;
        if (!analyticalDerivatives)
        {
            CalculateNormals();
        }
        mesh.normals = normals;
    }
Exemple #16
0
    public static NoiseSample Simplex1D(Vector3 point, float frequency)
    {
        point *= frequency;
        int         ix     = Mathf.FloorToInt(point.x);
        NoiseSample sample = Simplex1DPart(point, ix);

        sample            += Simplex1DPart(point, ix + 1);
        sample.derivative *= frequency;
        return(sample * (64f / 27f));
    }
Exemple #17
0
    public static NoiseSample Simplex1D(Vector3 point, float frequency)
    {
        point *= frequency;
        int         ix     = Mathf.FloorToInt(point.x);    // get left-side cell start position
        NoiseSample sample = Simplex1DPart(point, ix);     // get falloff value of this point from left cell int position

        sample            += Simplex1DPart(point, ix + 1); // get and add falloff value of this point from right cell int position
        sample.derivative *= frequency;
        return(sample * (64f / 27f));                      // get value back into 0-1 range
    }
Exemple #18
0
    public static NoiseSample SimplexValue1D(Vector3 point, float frequency)
    {
        point *= frequency;
        int         ix     = Mathf.FloorToInt(point.x);
        NoiseSample sample = SimplexValue1DPart(point, ix);

        sample            += SimplexValue1DPart(point, ix + 1);
        sample.derivative *= frequency;
        return(sample * (2f / hashMask) - 1f);
    }
    public void Refresh()
    {
        if (resolution != _currentResolution)
        {
            CreateGrid();
        }

        Quaternion q       = Quaternion.Euler(rotation);
        Quaternion qInv    = Quaternion.Inverse(q);
        Vector3    point00 = q * new Vector3(-0.5f, -0.5f) + offset;
        Vector3    point10 = q * new Vector3(0.5f, -0.5f) + offset;
        Vector3    point01 = q * new Vector3(-0.5f, 0.5f) + offset;
        Vector3    point11 = q * new Vector3(0.5f, 0.5f) + offset;

        NoiseMethod2 method    = Noise2.noiseMethods[(int)type][dimensions - 1];
        float        stepSize  = 1f / resolution;
        float        amplitude = damping ? strength / frequency : strength;

        for (int v = 0, y = 0; y <= resolution; y++)
        {
            Vector3 point0 = Vector3.Lerp(point00, point01, y * stepSize);
            Vector3 point1 = Vector3.Lerp(point10, point11, y * stepSize);
            for (int x = 0; x <= resolution; x++, v++)
            {
                Vector3     point  = Vector3.Lerp(point0, point1, x * stepSize);
                NoiseSample sample = Noise2.Sum(method, point, frequency, octaves, lacunarity, persistence);
                sample = type == NoiseMethodType2.Value ? (sample - 0.5f) : (sample * 0.5f);
                if (coloringForStrength)
                {
                    _colors[v] = coloring.Evaluate(sample.value + 0.5f);
                    sample    *= amplitude;
                }
                else
                {
                    sample    *= amplitude;
                    _colors[v] = coloring.Evaluate(sample.value + 0.5f);
                }
                _vertices[v].y    = sample.value;
                sample.derivative = qInv * sample.derivative;
                if (analyticalDerivatives)
                {
                    //calcualtes the analytical normals
                    _normals[v] = new Vector3(-sample.derivative.x, 1f, -sample.derivative.y).normalized;
                }
            }
        }
        _mesh.vertices = _vertices;
        _mesh.colors   = _colors;
        //_mesh.RecalculateNormals();
        if (!analyticalDerivatives)
        {
            CalculateNormals();                                         //a version of the above RecalculateNormals() method
        }
        _mesh.normals = _normals;
    }
Exemple #20
0
    // catlikecoding Noise
    public static float[,] theCatNoise(int mapWidth, int mapHeight, float resolution, int octaves, float persistence, float lacunarity, bool damping, float strength)
    {
        float   frequency = 1f;
        Vector3 offset    = new Vector3(1f, 2f, 3f);
        Vector3 rotation  = new Vector3(45f, 45f, 0f);

        float [,] noiseMap = new float[mapWidth, mapHeight];

        Quaternion q = Quaternion.Euler(rotation);
        // Quaternion qInv = Quaternion.Inverse(q);
        Vector3 point00 = q * new Vector3(-0.5f, -0.5f) + offset;
        Vector3 point10 = q * new Vector3(0.5f, -0.5f) + offset;
        Vector3 point01 = q * new Vector3(-0.5f, 0.5f) + offset;
        Vector3 point11 = q * new Vector3(0.5f, 0.5f) + offset;

        // NoiseMethod method = Noise.methods[(int)type][dimensions - 1];
        float stepSize  = 1f / mapHeight;
        float amplitude = damping ? strength / frequency : strength;

        for (int v = 0, y = 0; y < mapWidth; y++)
        {
            Vector3 point0 = Vector3.Lerp(point00, point01, y * stepSize);
            Vector3 point1 = Vector3.Lerp(point10, point11, y * stepSize);
            for (int x = 0; x < mapHeight; x++, v++)
            {
                Vector3     point  = Vector3.Lerp(point0, point1, x * stepSize);
                NoiseSample sample = catNoise.Sum3D(point, frequency, octaves, lacunarity, persistence);
                sample  = sample - 0.5f;
                sample *= amplitude;
                // sample = type == NoiseMethodType.Value ? (sample - 0.5f) : (sample * 0.5f);
                // if (coloringForStrength) {
                //   colors[v] = coloring.Evaluate(sample.value + 0.5f);
                //   sample *= amplitude;
                // }
                // else {
                //   sample *= amplitude;
                //   colors[v] = coloring.Evaluate(sample.value + 0.5f);
                // }
                //vertices[v].y = 1f-Mathf.Abs(sample.value);
                //sample.derivative = qInv * sample.derivative;
                // if (analyticalDerivatives) {
                //   normals[v] = new Vector3(-sample.derivative.x, 1f, -sample.derivative.y).normalized;
                // }
                noiseMap[y, x] = sample.value;
            }
        }

        // Ridged
        // sample.value = 1f-Mathf.Abs(sample.value);

        // sample.derivative = qInv * sample.derivative;
        return(noiseMap);
    }
Exemple #21
0
    private static NoiseSample SimplexValue1DPart(Vector3 point, int ix)
    {
        float       x      = point.x - ix;
        float       f      = 1f - x * x;
        float       f2     = f * f;
        float       f3     = f * f2;
        float       h      = hash[ix & hashMask];
        NoiseSample sample = new NoiseSample();

        sample.value        = h * f3;
        sample.derivative.x = -6f * h * x * f2;
        return(sample);
    }
Exemple #22
0
    // -------------------------
    // // SIMPLEX VALUE NOISE FUNCTIONS:
    // //   ========================================================================================================
    private static NoiseSample SimplexValue1DPart(Vector3 point, int ix)
    {
        float       x      = point.x - ix; // get relative position of sample point with respect to base integer cell
        float       f      = 1f - x * x;
        float       f2     = f * f;
        float       f3     = f * f2;               // falloff function f(0)=1, f(1)=0
        float       h      = hash [ix & hashMask]; // get hashed (shuffled) value for this cell int
        NoiseSample sample = new NoiseSample();

        sample.value        = h * f3;   // multiply h hash value by f3, the contribution of h at this position.
        sample.derivative.x = -6f * h * x * f2;
        return(sample);
    }
    private void UpdateSkyTangents()
    {
        for (int i = 0; i < strokeBackgroundArray.Length; i++)
        {
            //background1[i].y = Mathf.Abs(background1[i].y);
            NoiseSample noiseSample = NoisePrime.Simplex3D(strokeBackgroundArray[i].pos + skyNoiseOffset, skyNoiseFrequency);
            //float size = Vector3.Dot(noiseSample.derivative.normalized, strokeBackgroundArray[i].normal);
            noiseSample.value = noiseSample.value * 0.5f + 0.5f;
            //strokeBackgroundArray[i].pos = background1[i];
            float       colorNoiseFrequency = 1000f;
            NoiseSample colorNoiseSample    = NoisePrime.Simplex3D(strokeBackgroundArray[i].pos, skyNoiseFrequency * colorNoiseFrequency);
            float       colorNoise          = (colorNoiseSample.value * 0.5f + 0.5f);

            Color color = skyColorGradient.Evaluate(Vector3.Dot(strokeBackgroundArray[i].pos.normalized, Vector3.up));
            strokeBackgroundArray[i].col = new Vector3(Mathf.Lerp(color.r, colorNoise, skyColorNoise), Mathf.Lerp(color.g, colorNoise, skyColorNoise), Mathf.Lerp(color.b, colorNoise, skyColorNoise));
            //strokeBackgroundArray[i].col = new Vector3(noiseSample.value, noiseSample.value, noiseSample.value);
            //strokeBackgroundArray[i].normal = -background1[i].normalized;
            //Vector3 cross = Vector3.Cross(strokeBackgroundArray[i].normal, noiseSample.derivative);
            strokeBackgroundArray[i].tangent = Vector3.Cross(strokeBackgroundArray[i].normal, noiseSample.derivative);
            //strokeBackgroundArray[i].prevPos = background1[i];

            //size = (1.0f - Mathf.Abs(size));  //0 = 1,
            strokeBackgroundArray[i].dimensions = new Vector2(1f, 1f);
        }
        skyNoiseOffset += skyNoiseScroll * Time.deltaTime;
        backgroundStrokesBuffer.SetData(strokeBackgroundArray);


        /*float groundPos = -5f;
         * for (int i = 0; i < strokeTerrainArray.Length; i++) {
         *  //strokeTerrainArray[i].pos = UnityEngine.Random.insideUnitSphere * groundSpreadExponent;
         *  //strokeTerrainArray[i].pos *= strokeTerrainArray[i].pos.sqrMagnitude;
         *  strokeTerrainArray[i].pos.y = groundPos;  // start at groundHeight
         *  NoiseSample noiseSample = NoisePrime.Simplex3D(new Vector3(strokeTerrainArray[i].pos.x, 0f, strokeTerrainArray[i].pos.z), groundNoiseFrequency);
         *  float heightOffset = noiseSample.value * groundNoiseAmplitude;
         *  strokeTerrainArray[i].pos.y = groundPos + heightOffset;
         *  //strokeTerrainArray[i].pos = terrain1[i];
         *  Color color = terrainColorGradient.Evaluate(noiseSample.value * 0.5f + 0.5f);
         *  strokeTerrainArray[i].col = new Vector3(color.r, color.g, color.b);
         *  //Vector3 preTangent = noiseSample.derivative;
         *  //preTangent.y *= groundNoiseAmplitude;
         *
         *  //strokeTerrainArray[i].normal = new Vector3(-noiseSample.derivative.x, 1f, -noiseSample.derivative.z);
         *  //Vector3 cross = Vector3.Cross(strokeBackgroundArray[i].normal, noiseSample.derivative);
         *  strokeTerrainArray[i].tangent = Vector3.Cross(strokeTerrainArray[i].normal, noiseSample.derivative);
         *  strokeTerrainArray[i].dimensions = new Vector2(1f, 1f);
         *
         * }
         * terrainStrokesBuffer.SetData(strokeTerrainArray);
         */
    }
Exemple #24
0
    // ---------------------------------
    // // SIMPLEX FUNCTIONS !!!
    // ----------------------------------
    private static NoiseSample Simplex1DPart(Vector3 point, int ix)
    {
        float       x      = point.x - ix; // get relative position of sample point with respect to base integer cell
        float       f      = 1f - x * x;
        float       f2     = f * f;
        float       f3     = f * f2; // falloff function f(0)=1, f(1)=0
        float       g      = gradients1D [hash [ix & hashMask] & gradientsMask1D];
        float       v      = g * x;
        NoiseSample sample = new NoiseSample();

        sample.value        = v * f3;   // multiply h hash value by f3, the contribution of h at this position.
        sample.derivative.x = g * f3 - 6f * v * x * f2;
        return(sample);
    }
Exemple #25
0
    private static NoiseSample SimplexValue1DPart(Vector3 point, int ix)
    {
        float x  = point.x - ix;
        float f  = 1f - x * x;
        float f2 = f * f;
        float f3 = f * f2;
        float h  = PermutationTable[ix & hashMask];

        NoiseSample sample = new NoiseSample();

        sample.value = h * f3;

        return(sample);
    }
Exemple #26
0
    private static NoiseSample Simplex1DPart(Vector3 point, int ix)
    {
        float       x      = point.x - ix;
        float       f      = 1f - x * x;
        float       f2     = f * f;
        float       f3     = f * f2;
        float       g      = gradients1D[hash[ix & hashMask] & gradientsMask1D];
        float       v      = g * x;
        NoiseSample sample = new NoiseSample();

        sample.value        = v * f3;
        sample.derivative.x = g * f3 - 6f * v * x * f2;
        return(sample);
    }
Exemple #27
0
    public static NoiseSample Value2D(Vector3 point, float frequency, bool derivative)
    {
        point *= frequency;

        int ix0 = Mathf.FloorToInt(point.x);
        int iy0 = Mathf.FloorToInt(point.y);

        float tx = point.x - ix0;
        float ty = point.y - iy0;

        ix0 &= hashMask;
        iy0 &= hashMask;

        int ix1 = ix0 + 1;
        int iy1 = iy0 + 1;

        int h0 = GameUtils.Hash[ix0];
        int h1 = GameUtils.Hash[ix1];

        int h00 = GameUtils.Hash[h0 + iy0];
        int h10 = GameUtils.Hash[h1 + iy0];
        int h01 = GameUtils.Hash[h0 + iy1];
        int h11 = GameUtils.Hash[h1 + iy1];

        float txs = GameUtils.Smooth(tx);
        float tys = GameUtils.Smooth(ty);

        float a = h00;
        float b = h10 - h00;
        float c = h01 - h00;
        float d = h11 - h01 - h10 + h00;

        NoiseSample sample = new NoiseSample();

        sample.value = a + b * txs + (c + d * txs) * tys;

        if (derivative)
        {
            float dtx = GameUtils.SmoothDerivative(tx);
            float dty = GameUtils.SmoothDerivative(ty);

            sample.derivative.x = (b + d * tys) * dtx;
            sample.derivative.y = (c + d * txs) * dty;
            sample.derivative.z = 0f;
            sample.derivative  *= frequency;
        }

        return(sample * (2f / hashMask) - 1f);
    }
    private void createNoiseAsset()
    {
        NoiseSample noiseSample = ScriptableObject.CreateInstance <NoiseSample> ();

        noiseSample.setScale(scale);
        noiseSample.setSaturation(saturation);
        noiseSample.setNoiseScale(weight);
        noiseSample.setPersistentSample(sample);
        checkPath();
        AssetDatabase.CreateAsset(noiseSample, "Assets/ProcedureTerrain/NoiseSample/" + name + ".asset");

        //EditorUtility.SetDirty(sample3D);

        AssetDatabase.SaveAssets();
    }
    public static NoiseSample Sum(NoiseMethod method, Vector3 point, float frequency, int octaves, float lacunarity, float persistence)
    {
        NoiseSample sum       = method(point, frequency);
        float       amplitude = 1f;
        float       range     = 1f;

        for (int o = 1; o < octaves; o++)
        {
            frequency *= lacunarity;
            amplitude *= persistence;
            range     += amplitude;
            sum       += method(point, frequency) * amplitude;
        }
        return(sum * (1f / range));
    }
 public float interpolateAt(NoiseSample sample, float x, float y, float z)
 {
     this.noiseSample = sample;
     int X0 = fastFloor(x) % (sample.getSample().GetLength(0)-1);
     int Y0 = fastFloor(y) % (sample.getSample().GetLength(1)-1);
     int Z0 = fastFloor(z) % (sample.getSample().GetLength(2)-1);
     x -= fastFloor (x);
     y -= fastFloor (y);
     z -= fastFloor (z);
     float	u = fade (x),
             v = fade (y),
             w = fade (z);
     float interpolated = interpolateCube (X0, Y0, Z0, u, v, w);
     return interpolated;
 }
Exemple #31
0
    private static NoiseSample SimplexGradient1DPart(Vector3 point, int ix)
    {
        float x  = point.x - ix;
        float f  = 1f - x * x;
        float f2 = f * f;
        float f3 = f * f2;
        float g  = gradients1D[PermutationTable[ix & hashMask] & gradientsMask1D];
        float v  = g * x;

        NoiseSample sample = new NoiseSample();

        sample.value = v * f3;

        return(sample);
    }
	// -------------------------
	// // SIMPLEX VALUE NOISE FUNCTIONS:
	// //   ========================================================================================================
	private static NoiseSample SimplexValue1DPart (Vector3 point, int ix) {
		float x = point.x - ix;  // get relative position of sample point with respect to base integer cell
		float f = 1f - x * x;
		float f2 = f * f;
		float f3 = f * f2; // falloff function f(0)=1, f(1)=0
		float h = hash [ix & hashMask]; // get hashed (shuffled) value for this cell int
		NoiseSample sample = new NoiseSample();
		sample.value = h * f3;  // multiply h hash value by f3, the contribution of h at this position.
		sample.derivative.x = -6f * h * x * f2;
		return sample;
	}
Exemple #33
0
 private static NoiseSample Simplex1DPart(Vector3 point, int ix)
 {
     float x = point.x - ix;
     float f = 1f - x * x;
     float f2 = f * f;
     float f3 = f * f2;
     float g = gradients1D[hash[ix & hashMask] & gradientsMask1D];
     float v = g * x;
     NoiseSample sample = new NoiseSample();
     sample.value = v * f3;
     sample.derivative.x = g * f3 - 6f * v * x * f2;
     return sample;
 }
Exemple #34
0
 private static NoiseSample SimplexValue1DPart(Vector3 point, int ix)
 {
     float x = point.x - ix;
     float f = 1f - x * x;
     float f2 = f * f;
     float f3 = f * f2;
     float h = hash[ix & hashMask];
     NoiseSample sample = new NoiseSample();
     sample.value = h * f3;
     sample.derivative.x = -6f * h * x * f2;
     return sample;
 }
 public void addSample(NoiseSample sample)
 {
     samples.Add (sample);
 }
	// // 2D ========================================================================================================
	public static NoiseSample SimplexValue2DPart (Vector3 point, int ix, int iy) {
		float unskew = (ix + iy) * squaresToTriangles;
		float x = point.x - ix + unskew;
		float y = point.y - iy + unskew;
		float f = 0.5f - x * x - y * y;  // 1 - x^2 - y^2 
		NoiseSample sample = new NoiseSample();
		if (f > 0f) {
			float f2 = f * f;  // f^3
			float f3 = f * f2;
			float h = hash[hash[ix & hashMask] + iy & hashMask];
			float h6f2 = -6f * h * f2;
			sample.value = h * f3;
			sample.derivative.x = h6f2 * x;
			sample.derivative.y = h6f2 * y;
		}
		return sample;
	}
	// // 3D ========================================================================================================
	private static NoiseSample SimplexValue3DPart (Vector3 point, int ix, int iy, int iz) {
		float unskew = (ix + iy + iz) * (1f / 6f);
		float x = point.x - ix + unskew;
		float y = point.y - iy + unskew;
		float z = point.z - iz + unskew;
		float f = 0.5f - x * x - y * y - z * z;
		NoiseSample sample = new NoiseSample();
		if (f > 0f) {
			float f2 = f * f;
			float f3 = f * f2;
			float h = hash[hash[hash[ix & hashMask] + iy & hashMask] + iz & hashMask];
			float h6f2 = -6f * h * f2;
			sample.value = h * f3;
			sample.derivative.x = h6f2 * x;
			sample.derivative.y = h6f2 * y;
			sample.derivative.z = h6f2 * z;
		}
		return sample;
	}	
	// ---------------------------------
	// // SIMPLEX FUNCTIONS !!!
	// ----------------------------------
	private static NoiseSample Simplex1DPart (Vector3 point, int ix) {
		float x = point.x - ix;  // get relative position of sample point with respect to base integer cell
		float f = 1f - x * x;
		float f2 = f * f;
		float f3 = f * f2; // falloff function f(0)=1, f(1)=0
		float g = gradients1D [hash [ix & hashMask] & gradientsMask1D];
		float v = g * x;
		NoiseSample sample = new NoiseSample();
		sample.value = v * f3;  // multiply h hash value by f3, the contribution of h at this position.
		sample.derivative.x = g * f3 - 6f * v * x * f2;
		return sample;
	}
	// // 2D ========================================================================================================
	public static NoiseSample Simplex2DPart (Vector3 point, int ix, int iy) {
		float unskew = (ix + iy) * squaresToTriangles;
		float x = point.x - ix + unskew;
		float y = point.y - iy + unskew;
		float f = 0.5f - x * x - y * y;  // 1 - x^2 - y^2 
		NoiseSample sample = new NoiseSample();
		if (f > 0f) {
			float f2 = f * f;  // f^3
			float f3 = f * f2;
			Vector2 g = gradients2D[hash[hash[ix & hashMask] + iy & hashMask] & gradientsMask2D];
			float v = Dot(g, x, y);
			float v6f2 = -6f * v * f2;
			sample.value = v * f3;
			sample.derivative.x = g.x * f3 * v6f2 * x;
			sample.derivative.y = g.y * f3 + v6f2 * y;
		}
		return sample;
	}
	// // 3D ========================================================================================================
	private static NoiseSample Simplex3DPart (Vector3 point, int ix, int iy, int iz) {
		float unskew = (ix + iy + iz) * (1f / 6f);
		float x = point.x - ix + unskew;
		float y = point.y - iy + unskew;
		float z = point.z - iz + unskew;
		float f = 0.5f - x * x - y * y - z * z;
		NoiseSample sample = new NoiseSample();
		if (f > 0f) {
			float f2 = f * f;
			float f3 = f * f2;
			Vector3 g = simplexGradients3D[hash[hash[hash[ix & hashMask] + iy & hashMask] + iz & hashMask] &
			                        simplexGradientsMask3D];
			float v = Dot(g, x, y, z);
			float v6f2 = -6f * v * f2;
			sample.value = v * f3;
			sample.derivative.x = g.x * f3 + v6f2 * x;
			sample.derivative.y = g.y * f3 + v6f2 * y;
			sample.derivative.z = g.z * f3 + v6f2 * z;
		}
		return sample;
	}