Fractal() public static method

public static Fractal ( Vector2 coord, int octave ) : float
coord Vector2
octave int
return float
Esempio n. 1
0
    void Update()
    {
        // Move the offset vectors.
        var delta = Time.deltaTime * _noiseSpeed;

        noiseOffset1 += Vector3.right * delta;
        noiseOffset2 += Vector3.up * delta;
        noiseOffset3 += Vector3.forward * delta;

        // Move the vertices.
        if (surfaceSpace)
        {
            for (var i = 0; i < position.Length; i++)
            {
                var v  = position[i];
                var c1 = (v + noiseOffset1) * _noiseScale;
                var c2 = (v + noiseOffset2) * _noiseScale;
                var c3 = (v + noiseOffset3) * _noiseScale;
                v       += vector1[i] * (Kvant.Fractal(c1, octave) * _displacement);
                v       += vector2[i] * (Kvant.Fractal(c2, octave) * _displacement);
                v       += vector3[i] * (Kvant.Fractal(c3, octave) * _displacement);
                temp1[i] = v;
            }
        }
        else
        {
            for (var i = 0; i < position.Length; i++)
            {
                var v  = position[i];
                var c1 = (v + noiseOffset1) * _noiseScale;
                var c2 = (v + noiseOffset2) * _noiseScale;
                var c3 = (v + noiseOffset3) * _noiseScale;
                v       += Vector3.right * (Kvant.Fractal(c1, octave) * _displacement);
                v       += Vector3.up * (Kvant.Fractal(c2, octave) * _displacement);
                v       += Vector3.forward * (Kvant.Fractal(c3, octave) * _displacement);
                temp1[i] = v;
            }
        }

        if (smooth)
        {
            // Simply copy the moved vertices.
            mesh.vertices = temp1;
        }
        else
        {
            // Split the moved vertices.
            for (var i = 0; i < index.Length; i++)
            {
                temp2[i] = temp1[index[i]];
            }
            mesh.vertices = temp2;
        }

        // Rebuild the mesh.
        mesh.RecalculateNormals();
        mesh.RecalculateBounds();
    }
Esempio n. 2
0
    void Update()
    {
        // Move the offset vector.
        noiseOffset += noiseVelocity * Time.deltaTime;

        // Move the vertices.
        if (fractal)
        {
            for (var i = 0; i < position.Length; i++)
            {
                var v = position[i];
                var c = (v + noiseOffset) * noiseScale;
                var d = Kvant.Fractal(c, octave) * deformAmount;
                temp1[i] = v + normal[i] * d;
            }
        }
        else
        {
            for (var i = 0; i < position.Length; i++)
            {
                var v = position[i];
                var c = (v + noiseOffset) * noiseScale;
                var d = Kvant.Fractal4Coeffs(c, 1, 2, 4, 8) * deformAmount * 0.03125f;
                temp1[i] = v + normal[i] * d;
            }
        }

        if (smooth)
        {
            // Simply copy the moved vertices.
            mesh.vertices = temp1;
        }
        else
        {
            // Split the moved vertices.
            for (var i = 0; i < index.Length; i++)
            {
                temp2[i] = temp1[index[i]];
            }
            mesh.vertices = temp2;
        }

        // Rebuild the mesh.
        mesh.RecalculateNormals();
        mesh.RecalculateBounds();
    }