Exemplo n.º 1
0
    public void generateSkin(GameObject sun, Color c1, Color c2, float speed, float aS)
    {
        this.aS    = aS;
        this.sun   = sun;
        this.speed = speed;
        var noise   = new PerlinNoise2D(7, 7, 5);
        var texture = new Texture2D(70, 70, TextureFormat.RGBA32, false);

        for (var x = 0; x < 70; x++)
        {
            for (var y = 0; y < 70; y++)
            {
                var c     = noise.at(x / 10f, y / 10f) / 2 + .5f;
                var color = Color.Lerp(c1, c2, c);
                texture.SetPixel(x, y, color);
            }
        }
        texture.Apply();

        var renderer     = GetComponent <Renderer>();
        var tempMaterial = new Material(renderer.sharedMaterial);

        tempMaterial.mainTexture = texture;

        renderer.sharedMaterial = tempMaterial;
    }
Exemplo n.º 2
0
    public float at(Vector2 point)
    {
        int sx = (int)Math.Floor(point.x);
        int sy = (int)Math.Floor(point.y);

        var qp = point - new Vector2(sx, sy);

        var w = data.GetLength(0);
        var h = data.GetLength(1);

        var sx1 = sx + 1;
        var sy1 = sy + 1;

        var noise =
            Mathf.Lerp(
                Mathf.Lerp(
                    Vector2.Dot(data[sx % w, sy % h], point - new Vector2(sx, sy)),
                    Vector2.Dot(data[sx1 % w, sy % h], point - new Vector2(sx1, sy)),
                    smoother(qp.x)
                    ),
                Mathf.Lerp(
                    Vector2.Dot(data[sx % w, sy1 % h], point - new Vector2(sx, sy1)),
                    Vector2.Dot(data[sx1 % w, sy1 % h], point - new Vector2(sx1, sy1)),
                    smoother(qp.x)
                    ),
                smoother(qp.y)
                );

        if (p != null)
        {
            noise += p.at(point * 2) / 2;
        }

        return(noise);
    }
Exemplo n.º 3
0
    // todo probably don't need
    public static Texture2D getCracks(int width, int height)
    {
        var xyPeriod  = 8.0f;  //number of rings
        var turbPower = 0.2f;  //makes twists
        var turbSize  = 32.0f; //initial size of the turbulence

        var noise = new PerlinNoise2D(width / 10, height / 100, 1);

        var texWid  = width;
        var texHei  = height;
        var texture = new Texture2D(texWid, texHei, TextureFormat.ARGB32, false);

        for (int x = 0; x < texWid; x++)
        {
            for (int y = 0; y < texHei; y++)
            {
                var noiseVal = noise.at((float)x / 10, (float)y / 100) / (.5f * Mathf.Sqrt(2)) + .5f;
                noiseVal = noiseVal > 0.9 ? (noiseVal - 0.9f) / (1 - 0.9f) : 0;


                var noiseColor = new Color(noiseVal, noiseVal, noiseVal);
                var treeColor  = noiseColor;

                texture.SetPixel(x, y, Color.Lerp(treeColor, noiseColor, 0f));
            }
        }

        texture.Apply();

        return(texture);
    }
Exemplo n.º 4
0
    public static Mesh generateAsteroid(float radius, float distortion)
    {
        var mesh = new Mesh();

        mesh.name = "Asteroid";

        var horizontalLines = 40;
        var verticalLines   = 40;

        var vertices = new Vector3[horizontalLines * verticalLines];
        var posMap   = new Dictionary <(int, int), int>();

        List <Vector2> newUVs       = new List <Vector2>();
        List <int>     newTriangles = new List <int>();
        List <Vector3> normals      = new List <Vector3>();


        var noise = new PerlinNoise2D(5, 5, 5);

        int index  = 0;
        var origin = new Vector3(0, 0, 0);

        for (int m = 0; m < horizontalLines; m++)
        {
            for (int n = 0; n < verticalLines - 1; n++)
            {
                var sample = noise.at(m / 8f, n / 8f) * distortion;
                sample *= Mathf.Sin(Mathf.PI * m / (horizontalLines - 1));

                var pos = at(n, m, verticalLines, horizontalLines, radius + sample);
                vertices[index] = pos;
                posMap[(n, m)]  = index;
Exemplo n.º 5
0
    public void generateSkin(Color c1, Color c2)
    {
        this.c1 = c1;
        this.c2 = c2;
        var noise   = new PerlinNoise2D(10, 10, 5);
        var texture = new Texture2D(100, 100, TextureFormat.RGBA32, false);

        for (var x = 0; x < 100; x++)
        {
            for (var y = 0; y < 100; y++)
            {
                var c     = noise.at(x / 10f, y / 10f) / 2 + .5f;
                var color = Color.Lerp(c1, c2, c);
                texture.SetPixel(x, y, color);
            }
        }

        texture.Apply();

        var renderer     = GetComponent <Renderer>();
        var tempMaterial = new Material(renderer.sharedMaterial);

        tempMaterial.mainTexture = texture;
        tempMaterial.SetTexture(EmissionMap, texture);
        tempMaterial.SetColor(EmissionColor, Color.white);

        renderer.sharedMaterial = tempMaterial;
    }
Exemplo n.º 6
0
    private void calculateTerrainNoise(ref float[,] heights)
    {
        var scale  = 1 << noiseRandomScale;
        var fscale = (float)scale;
        var wid    = heights.GetLength(0);
        var hei    = heights.GetLength(1);
        var noise  = new PerlinNoise2D(wid / scale, hei / scale);

        for (var x = 0; x < wid; x++)
        {
            for (var y = 0; y < hei; y++)
            {
                heights[x, y] = (noise.at(x / fscale, y / fscale) / 0.5f + 1) / 2;
            }
        }
    }
Exemplo n.º 7
0
    // static Color dark = new Color(139 / 255f, 69 / 255f, 19 / 255f);
    // static Color light = new Color(200 / 255f, 199 / 255f, 137 / 255f);

    public static Texture2D getLines(
        bool vertical,
        int width,
        int height,
        int num,
        Color dark,
        Color light,
        float highGrain = 1,
        float lowGrain  = 1 / 5f,
        float _2dNoise  = 1 / 5f
        )
    {
        var noise          = new PerlinNoise2D(width, height, 5);
        var widthNoise     = new PerlinNoise2D(width, 1, 5);
        var highGrainNoise = new PerlinNoise2D(width, 1, 1);
        var texture        = new Texture2D(width * num, height * num, TextureFormat.RGBA32, false);
        var offset         = Random.Range(0, Mathf.PI * 2);

        if (vertical)
        {
            (width, height) = (height, width);
        }

        for (int y = 0; y < height * num; y++)
        {
            var fy           = (float)y / num;
            var widthDisturb = widthNoise.at(fy, 0.5f) * highGrain;
            widthDisturb += highGrainNoise.at(fy, 0.5f) * lowGrain;

            for (int x = 0; x < width * num; x++)
            {
                var fx       = (float)x / num;
                var noiseVal = noise.at(fx, fy);

                var pos = new Vector2(fx, fy);
                pos = shift(pos, noiseVal * _2dNoise);

                var linePattern = getLinePattern(pos, widthDisturb, offset);

                var col = Color.Lerp(
                    light,
                    dark,
                    Mathf.Pow(linePattern, 1f / 8)
                    );

                if (linePattern > 0.95f)
                {
                    col = Color.Lerp(Color.black, dark, 0.5f + 1 / 0.1f * (1 - linePattern));
                    // col = Color.Lerp(Color.black, dark, 0.5f);
                }

                var disCol = new Color(col.r, col.g, col.b);

                if (vertical)
                {
                    texture.SetPixel(y, x, disCol);
                }
                else
                {
                    texture.SetPixel(x, y, disCol);
                }
            }
        }

        texture.Apply();

        return(texture);
    }