Esempio n. 1
0
    void OnWizardCreate()
    {
        switch (equation)
        {
        case Equation.Normal:
            m_noiseEquationCallback = NormalPerlinNoise2D;
            break;

        case Equation.NormalSum:
            m_noiseEquationCallback = NormalPerlinNoise2D_Sum;
            break;

        case Equation.TurbulenceSum:
            m_noiseEquationCallback = Turbulence_Sum;
            break;

        case Equation.SinTurbulenceSum:
            m_noiseEquationCallback = SinTurbulence_Sum;
            break;

        case Equation.Wood:
            m_noiseEquationCallback = Wood;
            break;

        case Equation.Seamless:
            m_noiseEquationCallback = SeamlessPerlinNoise2D;
            break;
        }
        Texture2D tex = CreatePerlinNoiseTexture(512, 512, seed, m_noiseEquationCallback);

        SaveTextureAsPNG(tex, Application.dataPath + "/PerlinNoise/Textures/perlinnoise.png");
        AssetDatabase.Refresh();
    }
Esempio n. 2
0
    Texture2D CreatePerlinNoiseTexture(int width, int height, int seed, NoiseEquationCallback callback)
    {
        if (callback == null)
        {
            Debug.LogWarning("CreatePerlinNoiseTexture fail. callback is null.");
            return(null);
        }
        Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);

        Color[] col = new Color[width * height];
        for (float i = 0; i < height; i++)
        {
            for (float j = 0; j < width; j++)
            {
                float u      = i / height;
                float v      = j / width;
                float sample = callback(new Vector2(u, v));
                col [(int)(i * width + j)] = new Color(sample, sample, sample);
            }
        }
        tex.SetPixels(col);
        tex.Apply();
        return(tex);
    }