示例#1
0
    public static void Apply(Texture2D tex)
    {
        if (tex == null)
        {
            return;
        }

        int   xSize   = tex.width;
        int   ySize   = tex.height;
        float xStep   = 1.0f / (float)xSize;
        float yStep   = 1.0f / (float)ySize;
        float xOffset = xStep * 0.5f;
        float yOffset = yStep * 0.5f;

        PerlinNoise perlin = new PerlinNoise();

        for (int y = 0; y < ySize; y++)
        {
            float vy = y * yStep + yOffset;
            for (int x = 0; x < xSize; x++)
            {
                float vx = x * xStep + xOffset;
                tex.SetPixel(x, y, Color.white * perlin.Eval(vx, vy));
            }
        }
        tex.Apply();
    }