Example #1
0
        static void Main(string[] args)
        {
            Perlin2D perlinEng = new Perlin2D();

            float[,] PMap = perlinEng.GetNormalMap(ImgRes);

            OctavePerlin octPerlin = new OctavePerlin(0.5f, 2f);

            float[,] OMap = octPerlin.GetNormalOctavePerlin(6, ImgRes, 3);

            SaveNormalMapAsImage(PMap, ImgRes, "PerlinMap");
            SaveNormalMapAsImage(OMap, ImgRes, "OctavePerlinMap");
        }
Example #2
0
        public float[,] GetNormalOctavePerlin(int Octaves, int Res, int StartingPerlinRes)
        {
            float[,] Output = new float[Res, Res];

            float OctaveRes = StartingPerlinRes;
            float Intensity = 1;

            float min = float.MaxValue;
            float max = float.MinValue;

            for (int Oc = 0; Oc < Octaves; Oc++)
            {
                Perlin2D p = new Perlin2D((int)OctaveRes, Seed);

                float[,] OctaveMap = p.GetNormalMap(Res);

                for (int i = 0; i < Res; i++)
                {
                    for (int j = 0; j < Res; j++)
                    {
                        Output[i, j] += ((OctaveMap[i, j] * 2) - 1) * Intensity;

                        min = min < Output[i, j] ? min : Output[i, j];
                        max = max > Output[i, j] ? max : Output[i, j];
                    }
                }

                OctaveRes *= Lacunarity;
                Intensity *= Persistence;
            }


            //Normalise
            float Difference = max - min;
            float Ratio      = 1 / Difference;

            for (int x = 0; x < Res; x++)
            {
                for (int y = 0; y < Res; y++)
                {
                    Output[x, y] -= min;
                    Output[x, y] *= Ratio;
                }
            }

            return(Output);
        }