Exemplo n.º 1
0
        /// <summary>
        /// Generates an plan of values within a specified range based on the coordinates of the specified start values.
        /// </summary>
        /// <param name="module"><see cref="IModule2D"/> represent a noise generator.</param>
        /// <param name="width">The width of the plan (x-axis).</param>
        /// <param name="height">The height of the plan (y-axis).</param>
        /// <param name="scaleFactor">The scale factor of the plan.</param>
        /// <param name="range">Target range to convert the plan.</param>
        /// <param name="start_x">The start coordinate on the x-axis.</param>
        /// <param name="start_y">The start coordinate on the y-axis.</param>
        /// <returns>The resulting plan in target range.</returns>
        static public float[,] GetPlane(this IModule2D module, int width, int height, float scaleFactor, NoiseRange range, int start_x, int start_y)
        {
            float[,] rslt = new float[width, height];
            for (int w = 0; w < width; w++)
            {
                for (int h = 0; h < height; h++)
                {
                    rslt[w, h] = module.GetValue((start_x + w) * scaleFactor, (start_y + h) * scaleFactor, range);
                }
            }

            return(rslt);
        }
        private float FeatureBlend(IModule2D feature, GameCoordinate coordinates)
        {
            const float multFactor = 6000;
            const float stepSize   = 100;
            // guarantees coords as 0 <= coord < stepSize
            var onex       = ((coordinates.x % stepSize) + stepSize) % stepSize;
            var oney       = ((coordinates.y % stepSize) + stepSize) % stepSize;
            var altx       = onex + stepSize;
            var alty       = oney + stepSize;
            var xWeight    = onex / stepSize;
            var yWeight    = oney / stepSize;
            var invXWeight = 1 - xWeight;
            var invYWeight = 1 - yWeight;

            return(feature.GetValue(onex * multFactor, oney * multFactor) * xWeight * yWeight
                   + feature.GetValue(altx * multFactor, oney * multFactor) * invXWeight * yWeight
                   + feature.GetValue(onex * multFactor, alty * multFactor) * xWeight * invYWeight
                   + feature.GetValue(altx * multFactor, alty * multFactor) * invXWeight * invYWeight);
        }
Exemplo n.º 3
0
        public async Task <float[]> GenerateSmoothMap(IModule2D noise, float noiseMin, float noiseMax, float rangeStart, float rangeEnd, int chunkX, int chunkZ)
        {
            return(await Task.Run(() =>
            {
                int minX = ((chunkX) * 16);
                int minZ = ((chunkZ) * 16);
                var maxX = ((chunkX + 1) << 4);
                var maxZ = ((chunkZ + 1) << 4);

                int cx = (chunkX * 16);
                int cz = (chunkZ * 16);

                float q11 = noise.GetValue(minX, minZ);
                float q12 = noise.GetValue(minX, maxZ);

                float q21 = noise.GetValue(maxX, minZ);
                float q22 = noise.GetValue(maxX, maxZ);

                float[] heightMap = new float[16 * 16];

                for (int x = 0; x < 16; x++)
                {
                    float rx = cx + x;

                    for (int z = 0; z < 16; z++)
                    {
                        float rz = cz + z;

                        var baseNoise = MathUtils.BilinearCmr(
                            rx, rz,
                            q11,
                            q12,
                            q21,
                            q22,
                            minX, maxX, minZ, maxZ);

                        heightMap[(x << 4) + z] = MathUtils.ConvertRange(noiseMin, noiseMax, rangeStart, rangeEnd, baseNoise); //WaterLevel + ((128f * baseNoise));
                    }
                }

                return heightMap;
            }));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Generates an output value within a specified range based on the coordinates of the specified input value.
 /// </summary>
 /// <param name="module"><see cref="IModule2D"/> represent the noise generator.</param>
 /// <param name="x">The input coordinate on the x-axis.</param>
 /// <param name="y">The input coordinate on the y-axis.</param>
 /// <param name="range">Target range to convert the output value.</param>
 /// <returns>The resulting output value in target range.</returns>
 static public float GetValue(this IModule2D module, float x, float y, NoiseRange range)
 {
     return(ToRange(module.GetValue(x, y), range));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Generates an plan of values within a specified range based on the coordinates of the specified start values.
 /// </summary>
 /// <param name="module"><see cref="IModule2D"/> represent a noise generator.</param>
 /// <param name="width">The width of the plan (x-axis).</param>
 /// <param name="height">The height of the plan (y-axis).</param>
 /// <param name="range">Target range to convert the plan.</param>
 /// <param name="start_x">The start coordinate on the x-axis.</param>
 /// <param name="start_y">The start coordinate on the y-axis.</param>
 /// <returns>The resulting plan in target range.</returns>
 static public float[,] GetPlane(this IModule2D module, int width, int height, NoiseRange range, int start_x, int start_y)
 {
     return(module.GetPlane(width, height, 1, range, start_x, start_y));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Generates an plan of values within a specified coordinates of the specified start values.
 /// </summary>
 /// <param name="module"><see cref="IModule2D"/> represent a noise generator.</param>
 /// <param name="width">The width of the plan (x-axis).</param>
 /// <param name="height">The height of the plan (y-axis).</param>
 /// <param name="scaleFactor">The scale factor of the plan.</param>
 /// <param name="start_x">The start coordinate on the x-axis.</param>
 /// <param name="start_y">The start coordinate on the y-axis.</param>
 /// <returns>The resulting plan.</returns>
 static public float[,] GetPlane(this IModule2D module, int width, int height, float scaleFactor, int start_x, int start_y)
 {
     return(module.GetPlane(width, height, scaleFactor, _default, start_x, start_y));
 }
Exemplo n.º 7
0
 /// <summary>
 /// Generates an plan of values within a specified range.
 /// </summary>
 /// <param name="module"><see cref="IModule2D"/> represent a noise generator.</param>
 /// <param name="width">The width of the plan (x-axis).</param>
 /// <param name="height">The height of the plan (y-axis).</param>
 /// <param name="scaleFactor">The scale factor of the plan.</param>
 /// <param name="range">Target range to convert the plan.</param>
 /// <returns>The resulting plan in target range.</returns>
 static public float[,] GetPlane(this IModule2D module, int width, int height, float scaleFactor, NoiseRange range)
 {
     return(module.GetPlane(width, height, scaleFactor, range, 0, 0));
 }
Exemplo n.º 8
0
 /// <summary>
 /// Generates an plan of values.
 /// </summary>
 /// <param name="module"><see cref="IModule2D"/> represent a noise generator.</param>
 /// <param name="width">The width of the plan (x-axis).</param>
 /// <param name="height">The height of the plan (y-axis).</param>
 /// <returns>The resulting plan.</returns>
 static public float[,] GetPlane(this IModule2D module, int width, int height)
 {
     return(module.GetPlane(width, height, 1, _default));
 }
 public static float GetValue(this IModule2D module, GameCoordinate coordinates) => module.GetValue(coordinates.x, coordinates.y);
Exemplo n.º 10
0
        public OverworldGenerator()
        {
            int seed = Config.GetProperty("seed", "YoHoMotherducker!").GetHashCode();

            Seed = seed;

            BiomeModifierX = new SimplexPerlin(seed + 3700);
            BiomeModifierZ = new SimplexPerlin(seed + 5000);

            var rainSimplex = new SimplexPerlin(seed);

            var rainNoise = new Voronoi();

            rainNoise.Primitive3D = rainSimplex;
            rainNoise.Primitive2D = rainSimplex;
            rainNoise.Distance    = false;
            rainNoise.Frequency   = RainFallFrequency;
            rainNoise.OctaveCount = 2;
            RainNoise             = rainNoise;

            var tempSimplex = new SimplexPerlin(seed + 100);
            var tempNoise   = new Voronoi();

            tempNoise.Primitive3D = tempSimplex;
            tempNoise.Primitive2D = tempSimplex;
            tempNoise.Distance    = false;
            tempNoise.Frequency   = TemperatureFrequency;
            tempNoise.OctaveCount = 2;
            //	tempNoise.Gain = 2.5f;
            TempNoise = tempNoise;

            var mainLimitNoise = new SimplexPerlin(seed + 200);

            var mainLimitFractal = new SumFractal()
            {
                Primitive3D      = mainLimitNoise,
                Primitive2D      = mainLimitNoise,
                Frequency        = MainNoiseFrequency,
                OctaveCount      = 2,
                Lacunarity       = MainNoiseLacunarity,
                Gain             = MainNoiseGain,
                SpectralExponent = MainNoiseSpectralExponent,
                Offset           = MainNoiseOffset,
            };
            var mainScaler = new ScaleableNoise()
            {
                XScale      = 1f / MainNoiseScaleX,
                YScale      = 1f / MainNoiseScaleY,
                ZScale      = 1f / MainNoiseScaleZ,
                Primitive3D = mainLimitFractal,
                Primitive2D = mainLimitFractal
            };

            //ModTurbulence turbulence = new ModTurbulence(mainLimitFractal, new ImprovedPerlin(seed - 350, NoiseQuality.Fast), new ImprovedPerlin(seed + 350, NoiseQuality.Fast), null, 0.0125F);
            _mainNoise = mainScaler;             //turbulence;

            var mountainNoise   = new SimplexPerlin(seed + 300);
            var mountainTerrain = new HybridMultiFractal()
            {
                Primitive3D      = mountainNoise,
                Primitive2D      = mountainNoise,
                Frequency        = DepthFrequency,
                OctaveCount      = 4,
                Lacunarity       = DepthLacunarity,
                SpectralExponent = DepthNoiseScaleExponent,
                //Offset = 0.7f,
                Gain = DepthNoiseGain
            };

            ScaleableNoise scaling = new ScaleableNoise();

            scaling.Primitive2D = mountainTerrain;
            scaling.Primitive3D = mountainTerrain;
            scaling.YScale      = 1f / HeightScale;
            scaling.XScale      = 1f / DepthNoiseScaleX;
            scaling.ZScale      = 1f / DepthNoiseScaleZ;

            _depthNoise = scaling;

            BiomeUtils.FixMinMaxHeight();
        }
Exemplo n.º 11
0
        public NoiseProvider(WorldGeneratorPreset generatorPreset, int seed)
        {
            GeneratorPreset = generatorPreset;

            Seed       = seed;
            FastRandom = new FastRandom(seed);


            var mainLimitNoise = new SimplexPerlin(seed + FastRandom.Next(), NoiseQuality.Fast);

            var mainLimitFractal = new LibNoise.Filter.MultiFractal()
            {
                Primitive3D      = mainLimitNoise,
                Primitive2D      = mainLimitNoise,
                Frequency        = MainNoiseFrequency,
                OctaveCount      = 4,
                Lacunarity       = MainNoiseLacunarity,
                Gain             = MainNoiseGain,
                SpectralExponent = MainNoiseSpectralExponent
            };

            TerrainNoise = new ScaleableNoise()
            {
                XScale      = 1f / GeneratorPreset.CoordinateScale,
                YScale      = 1f / GeneratorPreset.HeightScale,
                ZScale      = 1f / GeneratorPreset.CoordinateScale,
                Primitive3D = mainLimitFractal,
                Primitive2D = mainLimitFractal
            }; //turbulence;


            var baseHeightNoise = new SimplexPerlin(seed + FastRandom.Next(), NoiseQuality.Fast);

            var fractal = new Voronoi()
            {
                Primitive2D = new ScaleableNoise()
                {
                    Primitive2D = baseHeightNoise,
                    XScale      = 1f / GeneratorPreset.CoordinateScale,
                    ZScale      = 1f / GeneratorPreset.CoordinateScale
                },
                OctaveCount      = 1,
                Frequency        = 1.295f,
                SpectralExponent = 0.25f
                                   //Distance = true
                                   //   Distance = false
            };

            BaseHeightNoise = new ScaleableNoise()
            {
                Primitive2D = fractal,
                XScale      = 1f / 8f,
                ZScale      = 1f / 8f
            };

            var depthNoise        = new SimplexPerlin(seed + FastRandom.Next(), NoiseQuality.Fast);
            var depthNoiseFractal = new RidgedMultiFractal()
            {
                Primitive2D      = depthNoise,
                Primitive3D      = depthNoise,
                Frequency        = DepthFrequency,
                Lacunarity       = DepthLacunarity,
                Gain             = DepthNoiseGain,
                OctaveCount      = 2,
                SpectralExponent = (float)GeneratorPreset.DepthNoiseScaleExponent
            };

            DepthNoise = new ScaleableNoise
            {
                Primitive2D = depthNoiseFractal,
                Primitive3D = depthNoiseFractal,
                XScale      = 1f / GeneratorPreset.MainNoiseScaleX,
                YScale      = 1f / GeneratorPreset.MainNoiseScaleY,
                ZScale      = 1f / GeneratorPreset.MainNoiseScaleZ
            };

            var rainSimplex = new SimplexPerlin(seed + FastRandom.Next(), NoiseQuality.Fast);
            var rainVoronoi = new WorldGenerator.Utils.Noise.Voronoi
            {
                Primitive3D = rainSimplex,
                Primitive2D = rainSimplex,
                Distance    = false,
                Frequency   = RainFallFrequency,
                OctaveCount = 2
            };

            var biomeScaling = (32.3345885f) * GeneratorPreset.BiomeSize;

            var rainNoise = new WorldGenerator.Utils.Noise.ScaleableNoise()
            {
                Primitive2D = rainVoronoi,
                Primitive3D = rainVoronoi,
                XScale      = 1f / biomeScaling,
                YScale      = 1f / biomeScaling,
                ZScale      = 1f / biomeScaling
            };

            // GeneratorPreset.bi

            IModule2D tempSimplex = new SimplexPerlin(seed + FastRandom.Next(), NoiseQuality.Fast);
            var       tempVoronoi = new WorldGenerator.Utils.Noise.Voronoi
            {
                Primitive2D      = tempSimplex,
                Distance         = false,
                Frequency        = TemperatureFrequency,
                OctaveCount      = 2,
                SpectralExponent = 0.25f
            };

            /*var tempNoise =  new ScaleableNoise()
             * {
             *  Primitive2D = tempVoronoi,
             *  Primitive3D = tempVoronoi,
             *  XScale = 1f / biomeScaling,
             *  YScale = 1f / biomeScaling,
             *  ZScale = 1f / biomeScaling
             * };
             */
            TempNoise = new ScaleableNoise()
            {
                Primitive2D = tempVoronoi,
                //   Primitive3D = tempSimplex,
                XScale = 1f / biomeScaling,
                YScale = 1f / biomeScaling,
                ZScale = 1f / biomeScaling
            };
            RainNoise = rainNoise;
        }