private void SetUpRidgedMultiFractal3DModule()
    {
        // make a 3d ridged multifractal module
        PrimitiveModule pModule = null;

        pModule = new SimplexPerlin();

        primitiveModule = pModule;

        pModule.Seed = 123;

        ScaleBias scale = null;

        filterModule             = new Billow(); //  new RidgedMultiFractal(); //new Pipe(); //
        filterModule.Primitive3D = (IModule3D)pModule;

        // Used to show the difference with our gradient color (-1 + 1)
        scale = new ScaleBias(filterModule, 1f, 0f);          // 0.9f, -1.25f);

        float      rmfScale   = .75f;
        ScalePoint scalePoint = new ScalePoint(filterModule, rmfScale, rmfScale * 1f, rmfScale);



        noiseModule = scalePoint;         // scale;
    }
示例#2
0
        public TerrainGenerator(long seed)
        {
            var seededConstant = new SimplexPerlin((int)seed, NoiseQuality.Fast);

            TurbX = new OpenSimplex(seed);
            TurbY = new OpenSimplex(seed);
            Chaos = new RidgedMultiFractal {
                OctaveCount = 7, Primitive2D = seededConstant
            };
            Hill = new OpenSimplex(seed);
            Alt  = new HybridMultiFractal {
                OctaveCount = 8, Gain = 0.1f, Primitive2D = seededConstant
            };
            Temp = new OpenSimplex(seed);
            Dry  = new HeterogeneousMultiFractal()
            {
                Primitive2D = seededConstant
            };
            Small = new HeterogeneousMultiFractal {
                OctaveCount = 2, Primitive2D = seededConstant
            };
            Rock = new HybridMultiFractal()
            {
                Gain = 0.3f, Primitive2D = seededConstant
            };
            Cliff = new HybridMultiFractal()
            {
                Gain = 0.3f, Primitive2D = seededConstant
            };
            Humid = new Billow {
                OctaveCount = 12, Gain = 0.125f, Frequency = 1, Primitive2D = seededConstant
            };
        }
示例#3
0
        static void Main(string[] args)
        {
            var noiseSource = new SimplexPerlin
            {
                Seed    = 0,
                Quality = NoiseQuality.Fast
            };

            var min = 0f;
            var max = 0f;

            for (int x = 0; x < 100; x++)
            {
                for (int z = 0; z < 100; z++)
                {
                    var val = noiseSource.GetValue(x, z);
                    if (val < min)
                    {
                        min = val;
                    }
                    if (val > max)
                    {
                        max = val;
                    }
                }
            }
            Console.Write(min + " " + max);

            Console.ReadKey();
        }
示例#4
0
        public SimplexOctaveGenerator(int seed, int octaves)
        {
            _seed    = seed;
            _octaves = octaves;

            _generators = new SimplexPerlin[octaves];
            for (int i = 0; i < _generators.Length; i++)
            {
                _generators[i] = new SimplexPerlin(seed, NoiseQuality.Best);
            }
        }
示例#5
0
        private SimplexPerlin CreateSimplexPerlin()
        {
            SimplexPerlin tmp = new SimplexPerlin(0, NoiseQuality.Best);
            int           s   = 0;

            for (int i = 0; i < Taste.Length; i++)
            {
                s += (int)tmp.GetValue((int)Taste[i], -i, NoiseRange.Byte);
            }
            tmp = null;

            return(new SimplexPerlin(s, NoiseQuality.Best));
        }
示例#6
0
文件: Chunk.cs 项目: DrSmCraft/Tiles
        public Chunk(int x, int y)
        {
            this.x = x;
            this.y = y;


            simplexPerlin = new SimplexPerlin(seed, NoiseQuality.Fast);

            voronoi             = new Voronoi();
            voronoi.Primitive3D = simplexPerlin;
            voronoi.Distance    = false;
            isGenerated         = false;
        }
示例#7
0
        public float[,] GenerateNoise(int passes, float frequency, float elevation, Func <float, int[], float> manipulator = null)
        {
            float[,] noise = new float[width, height];
            SimplexPerlin[] simplex = new SimplexPerlin[passes];

            for (int s = 0; s < passes; s++)
            {
                simplex[s] = new SimplexPerlin(rnd.Next(-int.MaxValue, int.MaxValue), LibNoise.NoiseQuality.Best);
            }


            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    float value        = 0;
                    float amplitudeSum = 0;
                    for (int i = 0; i < passes; i++)
                    {
                        float freq      = frequency;
                        float amplitude = 1;
                        if (i != 0)
                        {
                            freq = freq * (i * 2);
                            int ii = i + 1;;
                            amplitude = 1.0f / (float)(i + i);
                        }
                        value        += amplitude * simplex[i].GetValue(freq * x, freq * y);
                        amplitudeSum += amplitude;
                    }

                    value = value / amplitudeSum;

                    if (value < 0)
                    {
                        value = -(float)Math.Pow(Math.Abs(value), elevation);
                    }
                    else
                    {
                        value = (float)Math.Pow(Math.Abs(value), elevation);
                    }
                    if (manipulator != null)
                    {
                        value = manipulator(value, new int[] { x, y });
                    }
                    noise[x, y] = value;
                }
            }

            return(noise.NormaliseArray());
        }
    private void SetUpAltNoise2D()
    {
        PrimitiveModule pModule2D = new SimplexPerlin();

        pModule2D.Seed = primitiveModule.Seed + 6789;

        altFilterModule = new Pipe();         // RidgedMultiFractal();

        altFilterModule.Primitive3D = (IModule3D)pModule2D;

        float      alt_module_scale = 2.4f;
        ScalePoint scalePoint_alt   = new ScalePoint(altFilterModule, alt_module_scale, alt_module_scale, alt_module_scale);

        altNoise2DModule = (IModule3D)scalePoint_alt;
    }
    private void SetUpNoise2D()
    {
        //noise character should vary
        PrimitiveModule pModule2D = new SimplexPerlin();          // new ImprovedPerlin(); //

        pModule2D.Seed = primitiveModule.Seed + 1234;

//		noise2DModule = (IModule3D) pModule2D;

        FilterModule fModule = new SumFractal();         // new Billow(); //

        fModule.Primitive3D = (IModule3D)pModule2D;

        float      rmfScale   = .2f;
        ScalePoint scalePoint = new ScalePoint(fModule, rmfScale, rmfScale, rmfScale);

        noise2DModule = (IModule3D)scalePoint;
    }
示例#10
0
        internal GcRandom(ChunkColumn chunki, int seed)
        {
            Chunk = chunki;
            _subtractForLessThanCutoff = _amplitude1 - _cutOff;
            _f1Xz = 1.0 / _sxz;
            _f1Y  = 1.0 / _sy;

            if (_maxCaveHeight - _minCaveHeight > 128)
            {
                _caveBandBuffer = 32;
            }
            else
            {
                _caveBandBuffer = 16;
            }

            _noiseGen1 = new SimplexPerlin(seed, NoiseQuality.Fast);
            _noiseGen2 = new SimplexPerlin((int)_noiseGen1.GetValue(Chunk.X, Chunk.Z), NoiseQuality.Fast);
            _noiseGen3 = new SimplexPerlin((int)_noiseGen1.GetValue(Chunk.X, Chunk.Z), NoiseQuality.Fast);
        }
示例#11
0
        internal GCRandom(ChunkColumn chunki, int seed)
        {
            chunk = chunki;
            subtractForLessThanCutoff = amplitude1 - CutOff;
            f1xz = 1.0 / sxz;
            f1y  = 1.0 / sy;

            if (MaxCaveHeight - MinCaveHeight > 128)
            {
                caveBandBuffer = 32;
            }
            else
            {
                caveBandBuffer = 16;
            }

            noiseGen1 = new SimplexPerlin(seed, NoiseQuality.Fast);
            noiseGen2 = new SimplexPerlin((int)noiseGen1.GetValue(chunk.X, chunk.Z), NoiseQuality.Fast);
            noiseGen3 = new SimplexPerlin((int)noiseGen1.GetValue(chunk.X, chunk.Z), NoiseQuality.Fast);
        }
示例#12
0
        public IModule3D CreateModule(int globalSeed)
        {
            PrimitiveModule primitiveModule = null;

            switch (primative)
            {
            case NoisePrimitive.Constant:
                primitiveModule = new Constant(offset);
                break;

            case NoisePrimitive.Cylinders:
                primitiveModule = new Cylinders(offset);
                break;

            case NoisePrimitive.Spheres:
                primitiveModule = new Spheres(offset);
                break;

            case NoisePrimitive.BevinsGradient:
                primitiveModule = new BevinsGradient();
                break;

            case NoisePrimitive.BevinsValue:
                primitiveModule = new BevinsValue();
                break;

            case NoisePrimitive.ImprovedPerlin:
                primitiveModule = new ImprovedPerlin();
                break;

            case NoisePrimitive.SimplexPerlin:
                primitiveModule = new SimplexPerlin();
                break;
            }
            primitiveModule.Quality = quality;
            primitiveModule.Seed    = globalSeed + seed;
            return((IModule3D)primitiveModule);
        }
 public TunnelNetwork3DPrimitive(double frequency, int seed,
                                 double frequencyAltitude, double scaleAltitude, double baseAltitude,
                                 double tunnelsHeight, double threshold,
                                 double frequencyPerturbation, double scalePerturbation,
                                 double frequencyMicroPerturbation, double scaleMicroPerturbation)
 {
     this.frequencyAltitude          = frequencyAltitude;
     this.scaleAltitude              = scaleAltitude;
     this.baseAltitude               = baseAltitude;
     this.tunnelsHeight              = tunnelsHeight;
     this.threshold                  = threshold;
     this.frequencyPerturbation      = frequencyPerturbation;
     this.scalePerturbation          = scalePerturbation;
     this.frequencyMicroPerturbation = frequencyMicroPerturbation;
     this.scaleMicroPerturbation     = scaleMicroPerturbation;
     simplexAltitude                 = new SimplexPerlin(seed, NoiseQuality.Fast);
     ridgedMultiFractal              = new RidgedMultiFractal
     {
         Frequency   = frequency,
         OctaveCount = 1,
         Primitive2D = new SimplexPerlin(seed, NoiseQuality.Fast)
     };
     simplexPerturbation = new SimplexPerlin(seed, NoiseQuality.Fast);
 }
        public INoiseMap <float> GenerateMap(int mapWidth = 512, int mapHeight = 512, float scale = 1, int seed = 0)
        {
            if (mapWidth <= 0)
            {
                throw new ArgumentException("mapWidth should be greater than 0");
            }
            if (mapHeight <= 0)
            {
                throw new ArgumentException("mapHeight should be greater than 0");
            }
            if (scale <= 0)
            {
                throw new ArgumentException("scale should be greater than 0");
            }

            var perlineNoiseSource = new SimplexPerlin
            {
                Seed    = seed,
                Quality = NoiseQuality.Fast
            };

            var noiseMap = new float[mapWidth, mapHeight];

            for (int y = 0; y < mapHeight; y++)
            {
                for (int x = 0; x < mapWidth; x++)
                {
                    var sampleX = x / scale;
                    var sampleY = y / scale;

                    var perlinValue = perlineNoiseSource.GetValue(sampleX, sampleY);
                    noiseMap[x, y] = perlinValue;
                }
            }
            return(new NoiseMap(MapWidth: mapWidth, MapHeight: mapHeight, Data: noiseMap));
        }
        private void InitBiomeProviders(int seed)
        {
            var biomeScale = 128f;// Preset.CoordinateScale;

            //  var biomeScale = 8f * Preset.BiomeSize;

            INoiseModule distortionX = new SimplexPerlin(seed, NoiseQuality.Fast);

            distortionX = new PipeNoiseModule()
            {
                Primitive = distortionX,
                Frequency = 1f / 48.24345f
            };

            INoiseModule distortionY = new SimplexPerlin(seed, NoiseQuality.Fast);

            distortionY = new PipeNoiseModule()
            {
                Primitive = distortionY,
                Frequency = 1f / 32.24145f
            };

            // INoiseModule temperatureNoise = new SimplexPerlin(seed^3, NoiseQuality.Fast);

            /*temperatureNoise = new BillowNoiseModule()
             * {
             *  Primitive = temperatureNoise,
             *  Lacunarity = 2f,
             *  Frequency = 0.25f,
             *  OctaveCount = 1
             * // Scale = 0.1f,
             * // Bias = 1f
             * //  SpectralExponent = 0.8f,
             * // Offset = 1f,
             * // Gain = 2f
             * };*/

            INoiseModule temperatureNoise = new SimplexPerlin(seed ^ 3, NoiseQuality.Fast);

            /* temperatureNoise = new OctaveNoise(temperatureNoise, 4)
             * {
             *   Amplitude = 16f,
             *   Frequency = 1.8f
             * };
             */
            temperatureNoise = new VoronoiNoseModule()
            {
                Primitive    = temperatureNoise,
                Distance     = false,
                Frequency    = 0.343f,//0.125644f,
                Displacement = 1f,
                Size         = 2,
            };

            temperatureNoise = new ScaledNoiseModule(temperatureNoise)
            {
                ScaleX = 1f / biomeScale, ScaleY = 1f / biomeScale, ScaleZ = 1f / biomeScale
            };

            temperatureNoise = new TurbulenceNoiseModule(temperatureNoise, distortionX, distortionY, distortionY, 16f);

            //  temperatureNoise = new AverageSelectorModule(temperatureNoise, temperatureNoise);


            INoiseModule rainNoise = new SimplexPerlin(seed * seed ^ 2, NoiseQuality.Fast);

            rainNoise = new VoronoiNoseModule()
            {
                Primitive    = rainNoise,
                Distance     = false,
                Frequency    = 0.22776f,
                Displacement = 1f,
                Size         = 2
            };

            rainNoise = new ScaledNoiseModule(rainNoise)
            {
                ScaleX = 1f / biomeScale, ScaleY = 1f / biomeScale, ScaleZ = 1f / biomeScale
            };

            rainNoise = new TurbulenceNoiseModule(rainNoise, distortionY, distortionX, distortionX, 16f);

            BiomeProvider    = new BiomeProvider();
            RainfallNoise    = rainNoise;
            TemperatureNoise = temperatureNoise;
        }
示例#16
0
 public Simplex3DPrimitive(double frequency, double scale, int seed, NoiseQuality quality)
 {
     this.frequency = frequency;
     this.scale     = scale;
     simplex        = new SimplexPerlin(seed, quality);
 }
示例#17
0
        private void InitBiomeProviders(int seed)
        {
            // var biomeScale = 32f * Preset.BiomeSize;

            var biomeScale = 8f * Preset.BiomeSize;

            SimplexPerlin temperaturePerlin = new SimplexPerlin(seed + seed * seed, NoiseQuality.Fast);
            INoiseModule  temperatureNoise  = new OctaveNoise(temperaturePerlin, 4)
            {
                Amplitude = 3f,
                Frequency = 0.535f
            };

            temperatureNoise = new ScaledNoiseModule(temperatureNoise)
            {
                ScaleX = 1f / biomeScale,
                ScaleZ = 1f / biomeScale,
                ScaleY = 1f / biomeScale
            };

            temperatureNoise = new VoronoiNoseModule()
            {
                Primitive = temperatureNoise,
                Distance  = false,
                Frequency = 0.2325f,
                //    SpectralExponent = 0.25f
            };

            INoiseModule rainNoise = new SimplexPerlin(seed - seed * seed, NoiseQuality.Fast);

            rainNoise = new OctaveNoise(rainNoise, 4)
            {
                Amplitude = 3f,
                Frequency = 0.345f
            };

            rainNoise = new ScaledNoiseModule(rainNoise)
            {
                ScaleX = 1f / biomeScale,
                ScaleZ = 1f / biomeScale,
                ScaleY = 1f / biomeScale
            };

            rainNoise = new VoronoiNoseModule()
            {
                Primitive = rainNoise,
                Distance  = false,
                Frequency = 0.25f,
                // SpectralExponent = 0.25f
            };

            BiomeProvider = new BiomeProvider()
            {
                //RainfallProvider = rainNoise,
                //TemperatureProvider = temperatureNoise
            };
            RainfallNoise    = rainNoise;
            TemperatureNoise = temperatureNoise;

            /* TemperatureNoise = new SpacedCellularNoise(seed * seed)
             * {
             *   Settings = new VoronoiSettings(3200.0)
             * };
             * RainfallNoise = new SpacedCellularNoise(-seed)
             * {
             *   Settings = new VoronoiSettings(3200.0)
             * };*/
        }
示例#18
0
        public NoiseMap Render()
        {
            PrimitiveModule primitive = null;

            switch (this.Primitive)
            {
            case NoisePrimitive.Constant:
                primitive = new Constant(this.Offset);
                break;

            case NoisePrimitive.Cylinders:
                primitive     = new Cylinders(this.Offset);
                this.Seamless = false;
                break;

            case NoisePrimitive.Spheres:
                primitive     = new Spheres(this.Offset);
                this.Seamless = false;
                break;

            case NoisePrimitive.BevinsGradient: primitive = new BevinsGradient(); break;

            case NoisePrimitive.BevinsValue: primitive = new BevinsValue(); break;

            case NoisePrimitive.ImprovedPerlin: primitive = new ImprovedPerlin(); break;

            case NoisePrimitive.SimplexPerlin: primitive = new SimplexPerlin(); break;
            }

            primitive.Seed    = this.Seed;
            primitive.Quality = this.NoiseQuality;

            FilterModule filter = null;
            ScaleBias    scale  = null;

            switch (this.Filter)
            {
            case NoiseFilter.Pipe: filter = new Pipe(); break;

            case NoiseFilter.SumFractal: filter = new SumFractal(); break;

            case NoiseFilter.SinFractal: filter = new SinFractal(); break;

            case NoiseFilter.MultiFractal:
                filter = new MultiFractal();
                // Used to show the difference with our gradient color (-1 + 1)
                scale = new ScaleBias(filter, 1f, -0.8f);
                break;

            case NoiseFilter.Billow:
                filter = new Billow();
                ((Billow)filter).Bias  = -0.2f;
                ((Billow)filter).Scale = 2f;
                break;

            case NoiseFilter.HeterogeneousMultiFractal:
                filter = new HeterogeneousMultiFractal();
                // Used to show the difference with our gradient color (-1 + 1)
                scale = new ScaleBias(filter, -1f, 2f);
                break;

            case NoiseFilter.HybridMultiFractal:
                filter = new HybridMultiFractal();
                // Used to show the difference with our gradient color (-1 + 1)
                scale = new ScaleBias(filter, 0.7f, -2f);
                break;

            case NoiseFilter.RidgedMultiFractal:
                filter = new RidgedMultiFractal();
                // Used to show the difference with our gradient color (-1 + 1)
                scale = new ScaleBias(filter, 0.9f, -1.25f);
                break;

            case NoiseFilter.Voronoi: filter = new Voronoi(); break;
            }

            filter.Frequency   = this.Frequency;
            filter.Lacunarity  = this.Lacunarity;
            filter.OctaveCount = this.OctaveCount;
            filter.Offset      = this.Offset;
            filter.Gain        = this.Gain;
            filter.Primitive3D = (IModule3D)primitive;

            IModule3D final = scale ?? (IModule3D)filter;

            NoiseMapBuilder projection;

            switch (this.Projection)
            {
            case NoiseMapProjection.Spherical:
                projection = new NoiseMapBuilderSphere();
                ((NoiseMapBuilderSphere)projection).SetBounds(-90f, 90f, -180f, 180f);     // degrees
                break;

            case NoiseMapProjection.Cylindrical:
                projection = new NoiseMapBuilderCylinder();
                ((NoiseMapBuilderCylinder)projection).SetBounds(-180f, 180f, -10f, 10f);
                break;

            case NoiseMapProjection.Planar:
            default:
                float bound = 2f;
                projection = new NoiseMapBuilderPlane(bound, bound * 2, bound, bound * 2, this.Seamless);
                break;
            }

            NoiseMap noise = new NoiseMap();

            projection.SetSize(this.Width, this.Height);
            projection.SourceModule = final;
            projection.NoiseMap     = noise;
            projection.Build();

            float min, max;

            noise.MinMax(out min, out max);

            this.Map = noise;
            return(noise);
        }
 public IslandGenerator(World world, int seed, int minDepth = 0, int maxDepth = 0) : base(world, seed, minDepth, maxDepth)
 {
     moistureNoise = new SimplexPerlin(seed, NoiseQuality.Best);
 }
示例#20
0
 protected override void CreateNoise(IGH_DataAccess DA, int seed, NoiseQuality noiseQuality)
 {
     noise = new SimplexPerlin(seed, noiseQuality);
 }
示例#21
0
文件: FrmMain.cs 项目: ofux/LibNoise
        /// <summary>
        ///
        /// </summary>
        protected void GenerateNoise()
        {
            EnabledInterface(false);

            // Parse input ------------------------------------------------------------------------------------
            int    seed        = ParseInt(_tbxSeed.Text, PrimitiveModule.DefaultSeed);
            double frequency   = ParseDouble(_tbxFrequency.Text, FilterModule.DEFAULT_FREQUENCY);
            double lacunarity  = ParseDouble(_tbxLacunarity.Text, FilterModule.DEFAULT_LACUNARITY);
            double gain        = ParseDouble(_tbxGain.Text, FilterModule.DEFAULT_GAIN);
            double offset      = ParseDouble(_tbxOffset.Text, FilterModule.DEFAULT_OFFSET);
            double exponent    = ParseDouble(_tbxExponent.Text, FilterModule.DEFAULT_SPECTRAL_EXPONENT);
            var    octaveCount = (int)_nstpOctave.Value;
            bool   seamless    = _chkbx.Checked;

            GradientColor gradient  = GradientColors.Grayscale;
            NoiseQuality  quality   = PrimitiveModule.DefaultQuality;
            var           primitive = NoisePrimitive.ImprovedPerlin;
            var           filter    = NoiseFilter.SumFractal;

            try
            {
                quality = (NoiseQuality)Enum.Parse(typeof(NoiseQuality), _cbxQuality.Text);
            }
            catch
            {
                MessageBox.Show(
                    String.Format("Unknown quality '{0}'", _cbxQuality.Text),
                    "Libnoise Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );

                EnabledInterface(true);

                return;
            }

            try
            {
                primitive = (NoisePrimitive)Enum.Parse(typeof(NoisePrimitive), _cbxPrimitive.Text);
            }
            catch
            {
                MessageBox.Show(
                    String.Format("Unknown primitive '{0}'", _cbxPrimitive.Text),
                    "Libnoise Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );

                EnabledInterface(true);

                return;
            }

            try
            {
                filter = (NoiseFilter)Enum.Parse(typeof(NoiseFilter), _cbxFilter.Text);
            }
            catch
            {
                MessageBox.Show(
                    String.Format("Unknown filter '{0}'", _cbxFilter.Text),
                    "Libnoise Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );

                EnabledInterface(true);

                return;
            }

            switch (_cbxGradient.Text)
            {
            case "Grayscale":
                gradient = GradientColors.Grayscale;
                break;

            case "Terrain":
                gradient = GradientColors.Terrain;
                break;
            }

            // Create module tree ------------------------------------------------------------------------------------

            PrimitiveModule pModule = null;

            switch (primitive)
            {
            case NoisePrimitive.Constant:
                pModule = new Constant(offset);
                break;

            case NoisePrimitive.Cylinders:
                pModule  = new Cylinders(offset);
                seamless = false;
                break;

            case NoisePrimitive.Spheres:
                pModule  = new Spheres(offset);
                seamless = false;
                break;

            case NoisePrimitive.BevinsGradient:
                pModule = new BevinsGradient();
                break;

            case NoisePrimitive.BevinsValue:
                pModule = new BevinsValue();
                break;

            case NoisePrimitive.ImprovedPerlin:
                pModule = new ImprovedPerlin();
                break;

            case NoisePrimitive.SimplexPerlin:
                pModule = new SimplexPerlin();
                break;
            }

            pModule.Quality = quality;
            pModule.Seed    = seed;

            FilterModule fModule = null;
            ScaleBias    scale   = null;

            switch (filter)
            {
            case NoiseFilter.Pipe:
                fModule = new Pipe();
                break;

            case NoiseFilter.SumFractal:
                fModule = new SumFractal();
                break;

            case NoiseFilter.SinFractal:
                fModule = new SinFractal();
                break;

            case NoiseFilter.MultiFractal:
                fModule = new MultiFractal();
                // Used to show the difference with our gradient color (-1 + 1)
                scale = new ScaleBias(fModule, 1, -0.8);
                break;

            case NoiseFilter.Billow:
                fModule = new Billow();
                ((Billow)fModule).Bias  = -0.2;
                ((Billow)fModule).Scale = 2;
                break;

            case NoiseFilter.HeterogeneousMultiFractal:
                fModule = new HeterogeneousMultiFractal();
                // Used to show the difference with our gradient color (-1 + 1)
                scale = new ScaleBias(fModule, -1, 2);
                break;

            case NoiseFilter.HybridMultiFractal:
                fModule = new HybridMultiFractal();
                // Used to show the difference with our gradient color (-1 + 1)
                scale = new ScaleBias(fModule, 0.7, -2);
                break;

            case NoiseFilter.RidgedMultiFractal:
                fModule = new RidgedMultiFractal();
                // Used to show the difference with our gradient color (-1 + 1)
                scale = new ScaleBias(fModule, 0.9, -1.25);
                break;

            case NoiseFilter.Voronoi:
                fModule = new Voronoi();
                break;
            }

            fModule.Frequency   = frequency;
            fModule.Lacunarity  = lacunarity;
            fModule.OctaveCount = octaveCount;
            fModule.Offset      = offset;
            fModule.Offset      = offset;
            fModule.Gain        = gain;
            fModule.Primitive3D = (IModule3D)pModule;

            IModule3D finalModule;

            if (scale == null)
            {
                finalModule = (IModule3D)fModule;
            }
            else
            {
                finalModule = scale;
            }

            NoiseMapBuilder projection;

            switch (_cbxProjection.Text)
            {
            case "Spherical":
                projection = new NoiseMapBuilderSphere();
                ((NoiseMapBuilderSphere)projection).SetBounds(-90, 90, -180, 180);      // degrees
                break;

            case "Cylindrical":
                projection = new NoiseMapBuilderCylinder();
                ((NoiseMapBuilderCylinder)projection).SetBounds(-180, 180, -10, 10);
                break;

            case "Planar":
            default:
                double bound = 2;
                projection = new NoiseMapBuilderPlane(bound, bound * 2, bound, bound * 2, seamless);
                //projection = new NoiseMapBuilderPlane(-bound, bound, -bound, bound, seamless);
                //projection = new NoiseMapBuilderPlane(0, bound, 0, bound, seamless);
                break;
            }

            int width  = 0;
            int height = 0;

            switch (_cbxSize.Text)
            {
            case "256 x 256":
                width  = 256;
                height = 256;
                break;

            case "512 x 512":
                width  = 512;
                height = 512;
                break;

            case "1024 x 1024":
                width  = 1024;
                height = 1024;
                break;

            case "256 x 128":
                width  = 256;
                height = 128;
                break;

            case "512 x 256":
                width  = 512;
                height = 256;
                break;

            case "1024 x 512":
                width  = 1024;
                height = 512;
                break;

            case "2048 x 1024":
                width  = 2048;
                height = 1024;
                break;

            default:

            case "128 x 128":
                width  = 128;
                height = 128;
                break;
            }

            // ------------------------------------------------------------------------------------------------
            // 0 - Initializing
            _prbarRenderProgression.Visible = true;
            _lblProgressPercent.Visible     = true;
            _prbarRenderProgression.Value   = 0;
            ;
            _lblProgressPercent.Text = "";

            _lblLog.Text = String.Format("Create a {0} image with a {1} projection\n", _cbxSize.Text,
                                         _cbxProjection.Text);

            var      watchDog = new Stopwatch();
            TimeSpan ts;
            double   elaspedTime = 0;

            //
            // ------------------------------------------------------------------------------------------------
            // 1 - Build the noise map
            watchDog.Reset();

            _prbarRenderProgression.Value = 0;
            _lblLog.Text += "Building noise map ... ";

            var noiseMap = new NoiseMap();

            /*
             *          // ShapeFilter test
             *          Bitmap bmpShape = new Bitmap("smileyShape.bmp");
             *          BitmapAdaptater bmShapeAdaptater = new BitmapAdaptater(bmpShape);
             *
             *          ShapeFilter shapeFilter = new ShapeFilter();
             *          shapeFilter.Shape = bmShapeAdaptater;
             *
             *          projection.Filter = shapeFilter;
             */

            projection.SetSize(width, height);
            projection.SourceModule = finalModule;
            projection.NoiseMap     = noiseMap;
            projection.CallBack     = delegate(int line)
            {
                line++;

                watchDog.Stop();

                //Process message
                Application.DoEvents();

                _prbarRenderProgression.Value = (line * 100 / height);
                _lblProgressPercent.Text      = String.Format("{0} % - {1} line(s)", _prbarRenderProgression.Value, line);

                watchDog.Start();
            };

            watchDog.Start();
            projection.Build();
            watchDog.Stop();

            ts           = watchDog.Elapsed;
            elaspedTime += ts.TotalMilliseconds;

            _lblLog.Text += String.Format("{0:00}:{1:00} {2:00},{3:0000}\n",
                                          ts.Hours, ts.Minutes,
                                          ts.Seconds, ts.Milliseconds * 10
                                          );

            // ------------------------------------------------------------------------------------------------
            // 2 - Render image
            // Create a renderer, BitmapAdaptater create a System.Drawing.Bitmap on the fly
            watchDog.Reset();
            _prbarRenderProgression.Value = 0;
            _lblLog.Text += "Rendering image ... ";

            var renderer = new ImageRenderer();

            renderer.NoiseMap        = noiseMap;
            renderer.Gradient        = gradient;
            renderer.LightBrightness = 2;
            renderer.LightContrast   = 8;
            //renderer.LightEnabled = true;

            // Libnoise image struct strategy
            //Graphics.Tools.Noise.Renderer.Image image = new Graphics.Tools.Noise.Renderer.Image();
            //renderer.Image = image;

            // Dotnet Bitmap Strategy
            var bmpAdaptater = new BitmapAdaptater(width, height);

            renderer.Image = bmpAdaptater;

            renderer.CallBack = delegate(int line)
            {
                line++;

                watchDog.Stop();

                //Process message
                Application.DoEvents();

                _prbarRenderProgression.Value = (line * 100 / height);
                _lblProgressPercent.Text      = String.Format("{0} % - {1} line(s)", _prbarRenderProgression.Value, line);

                watchDog.Start();
            };

            // Render the texture.
            watchDog.Start();
            renderer.Render();
            watchDog.Stop();

            ts           = watchDog.Elapsed;
            elaspedTime += ts.TotalMilliseconds;

            _lblLog.Text += String.Format("{0:00}:{1:00} {2:00},{3:0000}\n",
                                          ts.Hours, ts.Minutes,
                                          ts.Seconds, ts.Milliseconds * 10
                                          );

            //----------------------------------------
            // Normalmap rendering test
            //

            /*
             *          BitmapAdaptater nmapAdaptater = new BitmapAdaptater(width, height);
             *          NormalMapRenderer nmap = new NormalMapRenderer();
             *          nmap.Image = nmapAdaptater;
             *          nmap.BumpHeight = 30.0;
             *          nmap.NoiseMap = noiseMap;
             *          nmap.Render();
             *          nmapAdaptater.Bitmap.Save("normalMap.png", ImageFormat.Png);
             */
            //----------------------------------------

            /*
             *          Heightmap8 heightmap8 = new Heightmap8();
             *          Heightmap8Renderer heightmapRenderer = new Heightmap8Renderer();
             *          heightmapRenderer.Heightmap = heightmap8;
             */

            /*
             *          Heightmap16 heightmap16 = new Heightmap16();
             *          Heightmap16Renderer heightmapRenderer = new Heightmap16Renderer();
             *          heightmapRenderer.Heightmap = heightmap16;
             */

            /*
             *          Heightmap32 heightmap32 = new Heightmap32();
             *          Heightmap32Renderer heightmapRenderer = new Heightmap32Renderer();
             *          heightmapRenderer.Heightmap = heightmap32;
             */

            /*
             *          heightmapRenderer.NoiseMap = noiseMap;
             *          heightmapRenderer.ExactFit();
             *          heightmapRenderer.Render();
             */

            /*
             *          Heightmap16RawWriter rawWriter = new Heightmap16RawWriter();
             *          rawWriter.Heightmap = heightmap16;
             *          rawWriter.Filename = "heightmap16.raw";
             *          rawWriter.WriteFile();
             */

            // ------------------------------------------------------------------------------------------------
            // 3 - Painting

            // Save the file
            //bmpAdaptater.Bitmap.Save("rendered.png",ImageFormat.Png);
            _imageRendered.Width  = width;
            _imageRendered.Height = height;

            //_imageRendered.Image = _bitmap;
            _imageRendered.Image = bmpAdaptater.Bitmap;

            if (_imageRendered.Width > _panImageViewport.Width)
            {
                _imageRendered.Left = 0;
            }
            else
            {
                _imageRendered.Left = (_panImageViewport.Width - _imageRendered.Width) / 2;
            }

            if (_imageRendered.Height > _panImageViewport.Height)
            {
                _imageRendered.Top = 0;
            }
            else
            {
                _imageRendered.Top = (_panImageViewport.Height - _imageRendered.Height) / 2;
            }

            if (_imageRendered.Width > _panImageViewport.Width || _imageRendered.Height > _panImageViewport.Height)
            {
                _imageRendered.Anchor        = (AnchorStyles.Left | AnchorStyles.Top);
                _panImageViewport.AutoScroll = true;
            }
            else
            {
                _panImageViewport.AutoScroll = false;
            }

            // ----------------------------------------------------------------

            ts = TimeSpan.FromMilliseconds(elaspedTime);

            // Format and display the TimeSpan value.
            _lblLog.Text += String.Format("Duration : {0:00}:{1:00} {2:00},{3:0000}\n",
                                          ts.Hours, ts.Minutes,
                                          ts.Seconds, ts.Milliseconds * 10
                                          );

            EnabledInterface(true);

            _prbarRenderProgression.Value   = 0;
            _lblProgressPercent.Text        = "";
            _prbarRenderProgression.Visible = false;
            _lblProgressPercent.Visible     = false;
        }
示例#22
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;
        }