Ejemplo n.º 1
0
        /// <summary>
        /// This function generates a heightmap and returns it as a System.Drawing.Image
        /// </summary>
        /// <param name="imageSize">The size of the image. Square sizes work best</param>
        /// <param name="borderSize"></param>
        /// <param name="octaveCount">The higher the octave, the 'busier' it is. Values 1-6 work well.</param>
        /// <param name="frequency">Increasing frequencies adds detail but also makes the features smaller. 0.5 to 5 work well.</param>
        /// <param name="persistence">Increasing persistence adds roughness. 0.25 to 0.75 work well.</param>
        /// <returns></returns>
        public static Image GeneratePerlinImage(int imageSize, double borderSize = 2, int octaveCount = 4, double frequency = 2, double persistence = 0.4)
        {
            //Console.WriteLine("Press Enter to Start Perlin Generator");
            //Console.ReadLine();
            Console.WriteLine("Generating Perlin Heightmap...");

            //seamless so bumpmap looks good
            heightMapBuilder = new PlanarNoiseMapBuilder((uint)imageSize, (uint)imageSize, borderSize, perlin, xLower, xLower+dist, yLower, yLower+dist, true);
            heightMap = heightMapBuilder.Build();

            GradientColour colors = new GradientColour();
            colors.AddGradientPoint(-1.0F, Color.Black);
            colors.AddGradientPoint(0, Color.Gray);
            colors.AddGradientPoint(1.0F, Color.White);

            perlin.OctaveCount = (uint)octaveCount;
            perlin.Frequency = frequency;
            perlin.Persistence = persistence;

            imgBuilder = new ImageBuilder(heightMap, colors);

            finalImage = imgBuilder.Render();

            Console.WriteLine("Perlin Heightmap Generated");

            return finalImage;
        }
Ejemplo n.º 2
0
        public static Texture GeneratePlanetTexture(Vector2u texSize)
        {
            var imgSize = texSize;
            perlin = new Perlin(random.Next(2, 3), 0.2, NoiseQuality.Best, 4, 0.7, random.Next(0, 1024));
            ridgedMulti = new RidgedMulti(random.NextDouble() * 2, 0.3, 2, NoiseQuality.Best, random.Next(0, 1024));
            voronoi = new Voronoi(0.1, random.NextDouble() * 2, true, random.Next(0, 1024));
            selectModule = new Select(1.0, 1.0, 0.0);
            selectModule.SetSourceModule(0, perlin);
            selectModule.SetSourceModule(1, ridgedMulti);
            selectModule.SetSourceModule(2, voronoi);

            heightMapBuilder = new PlanarNoiseMapBuilder(imgSize.X, imgSize.Y, 0, selectModule, 1, 5, 1, 5, true);
            heightMap = heightMapBuilder.Build();

            var texColors = new GradientColour();
            texColors.AddGradientPoint(-1, GenerateProceduralColor());
            texColors.AddGradientPoint(-0.2 + random.NextDouble() * 0.4, GenerateProceduralColor());
            texColors.AddGradientPoint(1, GenerateProceduralColor());
            var renderer = new ImageBuilder(heightMap, texColors);
            var renderedImg = renderer.Render();
            var img = new Bitmap(renderedImg);
            var sfmlImg = new SFML.Graphics.Image(imgSize.X, imgSize.Y);

            for (uint x = 0; x < imgSize.X; x++)
            {
                for (uint y = 0; y < imgSize.Y; y++)
                {
                    var col = img.GetPixel((int)x, (int)y);
                    sfmlImg.SetPixel(x, y, new Color(col.R, col.G, col.B, col.A));
                }
            }

            var returnTex = new Texture(sfmlImg);
            return returnTex;
        }