Exemple #1
0
        public override void Generate(Map map, GenStepParams parms)
        {
            ModuleBase chambers = new Perlin(0.010, 1.7, 0.5, 6, Rand.Range(0, int.MaxValue), QualityMode.High);

            ModuleBase columns = new Perlin(0.150, 0.5, 0.5, 6, Rand.Range(0, int.MaxValue), QualityMode.High);

            columns = new ScaleBias(0.5, 0.5, columns);

            // push columns to the centers of chambers
            ModuleBase columnsNoise = new Invert(chambers);

            columnsNoise = new ScaleBias(3f, -2f, columnsNoise);
            columnsNoise = new Min(new Const(0.0), columnsNoise);
            columns      = new Add(columns, columnsNoise);

            // broken tunnel network
            ModuleBase tunnels      = new Perlin(0.01, 1.7, 0.5, 6, Rand.Range(0, int.MaxValue), QualityMode.High);
            ModuleBase tunnelsNoise = new Perlin(0.005, 0.0, 0.5, 6, Rand.Range(0, int.MaxValue), QualityMode.Medium);

            tunnels = new Abs(tunnels);
            tunnels = new Add(new Const(0.5), tunnels);
            tunnels = new Add(tunnels, new Clamp(0, 0.5, tunnelsNoise));

            chambers = new Min(new Add(chambers, new Const(0.75)), tunnels);

            MapGenFloatGrid elevation = MapGenerator.Elevation;

            foreach (IntVec3 cell in map.AllCells)
            {
                elevation[cell] = Math.Max(columns.GetValue(cell), chambers.GetValue(cell));
            }
        }
Exemple #2
0
        /***
         *   OctaveCount   八度数
         *   Frequency     频率
         *   Persistence   连续性
         *   Lacunarity    空隙度
         * **/
        protected override void InitWormsGenerator()
        {
            var perlin = new MTBPerlin(_seed);

            perlin.OctaveCount = 40;
            perlin.Frequency   = 10;
            perlin.Persistence = 0.2;
            perlin.Lacunarity  = 0.4;
            var hightline = new ScaleBias(perlin.ModuleBase);

            hightline.Bias   = BlockHeightToFloat(1);
            _heightGenerator = hightline;

            var perlin2 = new MTBPerlin(_seed + 1);

            perlin2.OctaveCount = 80;
            perlin2.Frequency   = 50;
            perlin2.Persistence = 0.1;
            perlin2.Lacunarity  = 0.1;
            var scetion = new ScaleBias(perlin2.ModuleBase);

            scetion.Bias      = BlockHeightToFloat(1);
            _sectionGenerator = scetion;

            _lenght = 80;
            _thresholdOffsetFront = 1.0f;
            _limitWidth           = 1;
            _limitHeight          = 0;
            _radiusHeight         = 1;
            _radiusWidth          = 2;
            _upMixValue           = 1;
            _downMixValue         = 2;
            _emptyRateOffset      = 0.01f;
        }
Exemple #3
0
    // This lets us load the modules once when the game starts and then treat them as static.
    private static void LoadModules(int game_seed)
    {
        seed = game_seed;
        // Create noise functions.
        mountain      = new RidgedMultifractal();
        mountain.Seed = seed;

        baseFlatTerrain           = new Billow();
        baseFlatTerrain.Seed      = seed;
        baseFlatTerrain.Frequency = 0.5;
        //0.125
        flatTerrain = new ScaleBias(0.0625, -0.75, baseFlatTerrain);
        //flatTerrain = new LibNoise.Unity.Generator.Const (-0.75);

        terrainType             = new Perlin();
        terrainType.Seed        = seed;
        terrainType.Frequency   = 0.5;
        terrainType.Persistence = 0.125;

        finalTerrain = new Select(flatTerrain, mountain, terrainType);
        finalTerrain.SetBounds(0.25, 1000.0);
        finalTerrain.FallOff = 0.125;

        modules_loaded = true;
    }
Exemple #4
0
        public override void Generate(Map map, GenStepParams parms)
        {
            ModuleBase tunnels = new Perlin(0.024, 2.2, 0.5, 6, Rand.Range(0, int.MaxValue), QualityMode.High);

            tunnels = new ScaleBias(0.5, 0.5, tunnels);

            ModuleBase noise = new Perlin(0.02, 1.5, 0.5, 6, Rand.Range(0, int.MaxValue), QualityMode.Medium);



            MapGenFloatGrid elevation = MapGenerator.Elevation;

            foreach (IntVec3 cell in map.AllCells)
            {
                elevation[cell] = 0.53f + 2f * Math.Abs(tunnels.GetValue(cell) - 0.5f) + 0.10f * noise.GetValue(cell);
            }


            IntVec3 roomLoc = map.Center;

            roomLoc.x = (int)(Rand.Range(0.3f, 1.7f) * roomLoc.x);
            roomLoc.z = (int)(Rand.Range(0.3f, 1.7f) * roomLoc.z);

            ModuleBase roomNoise = new Perlin(Rand.Range(0.015f, 0.028f), 2.0, 0.5, 6, Rand.Range(0, 2147483647), QualityMode.High);
            float      sizeAdj   = Rand.Range(8f, 10f);

            foreach (IntVec3 cell in map.AllCells)
            {
                float distance = (float)Math.Sqrt(Math.Pow(cell.x - roomLoc.x, 2) + Math.Pow(cell.z - roomLoc.z, 2));

                float addition = 25 * (1f - (sizeAdj * distance / map.Size.x)) + 15f * roomNoise.GetValue(cell);

                elevation[cell] -= Math.Max(0, addition);
            }
        }
Exemple #5
0
        /***
         *   OctaveCount   八度数
         *   Frequency     频率
         *   Persistence   连续性
         *   Lacunarity    空隙度
         * **/
        protected override void InitCaveGenerator()
        {
            var perlin = new Perlin();

            perlin.OctaveCount = 10;
            perlin.Frequency   = 4;
            perlin.Persistence = 0.5;
            perlin.Lacunarity  = 1.0;
            perlin.Seed        = _seed + 1;
            var lowwall = new ScaleBias(perlin);

            lowwall.Bias      = BlockHeightToFloat(1);
            _lowWallGenerator = lowwall;
            var perlin2 = new Perlin();

            perlin2.OctaveCount = 40;
            perlin2.Frequency   = 10;
            perlin2.Persistence = 0.1;
            perlin2.Lacunarity  = 2.5;
            perlin2.Seed        = _seed + 2;
            var highwall = new ScaleBias(perlin2);

            highwall.Bias      = BlockHeightToFloat(1);
            _highWallGenerator = highwall;
        }
        /// <summary>
        /// Initializes the base mod
        /// </summary>
        public override void OnSetup()
        {
            Billow billow = new Billow()
            {
                Seed      = seed,
                Frequency = 2 * (1f / smoothness)
            };
            ScaleBias          scaleBia           = new ScaleBias((1f / plainSmoothness), mesaVsPlainsBias, billow);
            RidgedMultifractal riggedMultifractal = new RidgedMultifractal
            {
                Seed        = seed,
                OctaveCount = noisePasses,
                Frequency   = 1 / smoothness
            };
            Perlin perlin = new Perlin
            {
                Seed        = seed,
                OctaveCount = noisePasses,
                Frequency   = 1 / plainsVsMountainSmoothness,
                Persistence = 1 / falloff
            };

            terrainHeightMap = new Select(0, 1, plainsVsMountainThreshold, scaleBia, riggedMultifractal)
            {
                Controller = perlin
            };
        }
Exemple #7
0
        private void SetupSwampinessNoise()
        {
            float      freqMultiplier = FreqMultiplier;
            ModuleBase input          = new Perlin((double)(0.09f * freqMultiplier), 2.0, 0.40000000596046448, 6, Rand.Range(0, 2147483647), QualityMode.High);
            ModuleBase input2         = new RidgedMultifractal((double)(0.025f * freqMultiplier), 2.0, 6, Rand.Range(0, 2147483647), QualityMode.High);

            input           = new ScaleBias(0.5, 0.5, input);
            input2          = new ScaleBias(0.5, 0.5, input2);
            noiseSwampiness = new Multiply(input, input2);
            ModuleBase  module = noiseElevation;
            FloatRange  swampinessMaxElevation = SwampinessMaxElevation;
            float       max = swampinessMaxElevation.max;
            FloatRange  swampinessMaxElevation2 = SwampinessMaxElevation;
            InverseLerp rhs = new InverseLerp(module, max, swampinessMaxElevation2.min);

            noiseSwampiness = new Multiply(noiseSwampiness, rhs);
            ModuleBase  module2 = noiseRainfall;
            FloatRange  swampinessMinRainfall = SwampinessMinRainfall;
            float       min = swampinessMinRainfall.min;
            FloatRange  swampinessMinRainfall2 = SwampinessMinRainfall;
            InverseLerp rhs2 = new InverseLerp(module2, min, swampinessMinRainfall2.max);

            noiseSwampiness = new Multiply(noiseSwampiness, rhs2);
            NoiseDebugUI.StorePlanetNoise(noiseSwampiness, "noiseSwampiness");
        }
Exemple #8
0
    private void Meh(bool random = false)
    {
        if (random)
        {
            Noise.xOrg = Random.Range(-1000, 1000);
            Noise.yOrg = Random.Range(-1000, 1000);
        }
        // STEP 1
        // Gradient is set directly on the object
        var mountainTerrain = new RidgedMultifractal();

        // STEP 2
        var baseFlatTerrain = new Billow();

        baseFlatTerrain.Frequency = Noise.Frequency;

        // STEP 3
        var flatTerrain = new ScaleBias(Noise.Scale, Noise.Bias, baseFlatTerrain);

        // STEP 4
        var terrainType = new Perlin();

        terrainType.Frequency   = Noise.TFrequency;
        terrainType.Persistence = Noise.Persistence;

        generator = new Select(flatTerrain, mountainTerrain, terrainType);
        generator.SetBounds(Noise.Min, Noise.Max);
        generator.FallOff = Noise.FallOff;

        RenderAndSetImage(generator);
    }
Exemple #9
0
    public static void testPreset(out ModuleBase finalTerrain, out ModuleBase finalTexture)
    {
        float f;

        finalTexture = buildTexture(new Dictionary <Sub, double>(), out f, 1, new System.Random(1));

        float scale = 100000f;

        finalTerrain = new Voronoi(1 / scale, 0, 2623246, true);


        /*finalTerrain = new Billow(1/scale,
         *      2,
         *      .5,
         *      1,
         *      123414,//Random.Range(int.MinValue, int.MaxValue),
         *      QualityMode.High);*/

        /*	Curve c = new Curve(finalTerrain);
         *      c.Add(-1, 0);
         *      c.Add(0, 0);
         *      c.Add(.5, 0);
         *      c.Add(1, -1);*/

        //finalTerrain = new Min(new Const(-.9), new Invert(finalTerrain));

        finalTerrain = new ScaleBias(scale * .5, 0, finalTerrain);
        //finalTerrain = new Invert(finalTerrain);
    }
Exemple #10
0
 }          //  Base Height Result Module
 protected override void SetModules()
 {
     base.SetModules();
     #region 1
     ModuleBase module1 = new Const(5);
     #endregion
     #region 2
     ModuleBase module2a = new RidgedMultifractal(frequency: Mathf.Pow(2, -8), lacunarity: 2.0, octaves: 6, seed: Random[IdxForRnd].Next(), quality: QualityMode.Low);
     ModuleBase module2b = new Turbulence(input: module2a);
     ((Turbulence)module2b).Seed      = Random[IdxForRnd].Next();
     ((Turbulence)module2b).Frequency = Mathf.Pow(2, -2);
     ((Turbulence)module2b).Power     = 1;
     ModuleBase module2c = new ScaleBias(scale: 1.0, bias: 30.0, input: module2b);
     #endregion
     #region 3
     ModuleBase module3a = new Billow(frequency: Mathf.Pow(2, -7) * 1.6, lacunarity: 2.0, persistence: 0.5, octaves: 8, seed: Random[IdxForRnd].Next(), quality: QualityMode.Low);
     ModuleBase module3b = new Turbulence(input: module3a);
     ((Turbulence)module3b).Seed      = Random[IdxForRnd].Next();
     ((Turbulence)module3b).Frequency = Mathf.Pow(2, -2);
     ((Turbulence)module3b).Power     = 1.8;
     ModuleBase module3c = new ScaleBias(scale: 1.0, bias: 31.0, input: module3b);
     #endregion
     #region 4
     ModuleBase module4a = new Perlin(frequency: Mathf.Pow(2, -6), lacunarity: 2.0, persistence: 0.5, octaves: 6, seed: Random[IdxForRnd].Next(), quality: QualityMode.Low);
     ModuleBase module4b = new Select(inputA: module2c, inputB: module3c, controller: module4a);
     ((Select)module4b).SetBounds(min: -.2, max: .2);
     ((Select)module4b).FallOff = .25;
     ModuleBase module4c = new Multiply(lhs: module4b, rhs: module1);
     #endregion
     MaterialSelectors[0] = (Select)module4b;
     Modules.Add(module4c);
 }
Exemple #11
0
    // Use this for initialization
    void Start()
    {
        IModule mountainTerrain = new RidgedMulti();
        IModule baseFlatTerrain = new Billow();

        ((Billow)baseFlatTerrain).Frequency = 2.0;
        IModule flatTerrain = new ScaleBias(baseFlatTerrain, 0.125, -0.75);
        IModule terrainType = new Perlin();

        ((Perlin)terrainType).Frequency   = 0.5;
        ((Perlin)terrainType).Persistence = 0.25;
        IModule finalTerrain = new Select(flatTerrain, mountainTerrain, terrainType);

        ((Select)finalTerrain).SetBounds(0.0, 1000.0);
        ((Select)finalTerrain).SetEdgeFallOff(0.125);
        NoiseMapBuilderPlane heightMapBuilder = new NoiseMapBuilderPlane(256, 256);

        heightMapBuilder.SetBounds(6.0, 10.0, 1.0, 5.0);
        heightMapBuilder.Build(finalTerrain);
        RendererImage render = new RendererImage();

        render.SourceNoiseMap = heightMapBuilder.Map;
        render.ClearGradient();
        render.AddGradientPoint(-1.0000, new Color32(32, 160, 0, 255));
        render.AddGradientPoint(-0.2500, new Color32(224, 224, 0, 255));
        render.AddGradientPoint(0.2500, new Color32(128, 128, 128, 255));
        render.AddGradientPoint(1.0000, new Color32(255, 255, 255, 255));
        render.IsLightEnabled  = true;
        render.LightContrast   = 3.0;
        render.LightBrightness = 2.0;
        render.Render();
        tex = render.GetTexture();
    }
Exemple #12
0
        static void Tutorial4()
        {
            Console.WriteLine("Begin Tutorial 4");

            RiggedMultifractal mountainTerrain = new RiggedMultifractal();
            Billow             baseFlatTerrain = new Billow();

            baseFlatTerrain.Frequency = 2.0;

            ScaleBias flatTerrain = new ScaleBias();

            flatTerrain[0]    = baseFlatTerrain;
            flatTerrain.Scale = 0.125;
            flatTerrain.Bias  = -0.75;

            Perlin terrainType = new Perlin();

            terrainType.Frequency   = 0.5;
            terrainType.Persistence = 0.25;

            Select finalTerrain = new Select();

            finalTerrain[0]         = flatTerrain;
            finalTerrain[1]         = mountainTerrain;
            finalTerrain.Controller = terrainType;
            finalTerrain.SetBounds(0.0, 1000.0);
            finalTerrain.FallOff = 0.125;

            NoiseMap             heightMap        = new NoiseMap();
            NoiseMapBuilderPlane heightMapBuilder = new NoiseMapBuilderPlane();;

            heightMapBuilder.SetSourceModule(finalTerrain);
            heightMapBuilder.SetDestNoiseMap(heightMap);
            heightMapBuilder.SetDestSize(256, 256);
            heightMapBuilder.SetBounds(6.0, 10.0, 1.0, 5.0);
            heightMapBuilder.Build();

            RendererImage renderer = new RendererImage();
            NoiseImage    image    = new NoiseImage();

            renderer.SetSourceNoiseMap(heightMap);
            renderer.SetDestImage(image);
            renderer.ClearGradient();
            renderer.AddGradientPoint(-1.00, new Color(32, 160, 0, 255));   // grass
            renderer.AddGradientPoint(-0.25, new Color(224, 224, 0, 255));  // dirt
            renderer.AddGradientPoint(0.25, new Color(128, 128, 128, 255)); // rock
            renderer.AddGradientPoint(1.00, new Color(255, 255, 255, 255)); // snow
            renderer.EnableLight();
            renderer.SetLightContrast(3.0);
            renderer.SetLightBrightness(2.0);
            renderer.Render();

            WriterBMP writer = new WriterBMP();

            writer.SetSourceImage(image);
            writer.SetDestFilename("tutorial4.bmp");
            writer.WriteDestFile();

            Console.WriteLine("End Tutorial 4");
        }
    void Awake()
    {
        noiseGenerator = new NoiseGenerator();

        billowModule = new Billow(n1frequency, n1lacunarity, n1persistence, n1octaves, n1seed, QualityMode.High); //(frequency, lacunarity, persistence, octaves, seed, QualityMode.High));
        //billowModule = new Voronoi(n1frequency, n1lacunarity, n1seed, true);
        billowScaleBiasModule = new ScaleBias(n1scale, n1bias, billowModule);

        ridgedModule          = new RidgedMultifractal(n2frequency, n2lacunarity, n2octaves, n2seed, QualityMode.High);
        ridgedScaleBiasModule = new ScaleBias(n2scale, n2bias, ridgedModule);

        perlinModule          = new Perlin(n3frequency, n3lacunarity, n3persistence, n3octaves, n3seed, QualityMode.High);
        perlinScaleBiasModule = new ScaleBias(n3scale, n3bias, perlinModule);

        selectModule = new Select(billowScaleBiasModule, ridgedScaleBiasModule, perlinScaleBiasModule);
        selectModule.SetBounds(0.5, 1000);  // parameterize?
        selectModule.FallOff = 0.3928571;

        turbulenceModule           = new Turbulence(0.335, selectModule);
        turbulenceModule.Frequency = 4.742f;
        turbulenceScaleBias        = new ScaleBias(n1scale, n1bias, turbulenceModule);

        currentModule = billowScaleBiasModule;

        waterGenerator = GameObject.FindObjectOfType <WaterGenerator> ();
    }
        public static void Init(Map map)
        {
            Rot4 a = Find.World.CoastDirectionAt(map.Tile);

            if (!a.IsValid)
            {
                beachNoise = null;
                return;
            }
            ModuleBase input = new Perlin(0.029999999329447746, 2.0, 0.5, 3, Rand.Range(0, int.MaxValue), QualityMode.Medium);

            input = new ScaleBias(0.5, 0.5, input);
            NoiseDebugUI.StoreNoiseRender(input, "BeachMaker base", map.Size.ToIntVec2);
            ModuleBase input2 = new DistFromAxis(CoastWidthRange.RandomInRange);

            if (a == Rot4.North)
            {
                input2 = new Rotate(0.0, 90.0, 0.0, input2);
                input2 = new Translate(0.0, 0.0, -map.Size.z, input2);
            }
            else if (a == Rot4.East)
            {
                input2 = new Translate(-map.Size.x, 0.0, 0.0, input2);
            }
            else if (a == Rot4.South)
            {
                input2 = new Rotate(0.0, 90.0, 0.0, input2);
            }
            input2 = new ScaleBias(1.0, -1.0, input2);
            input2 = new Clamp(-1.0, 2.5, input2);
            NoiseDebugUI.StoreNoiseRender(input2, "BeachMaker axis bias");
            beachNoise = new Add(input, input2);
            NoiseDebugUI.StoreNoiseRender(beachNoise, "beachNoise");
        }
Exemple #15
0
        public float getValue(Vector3 cubeWorldPosition)
        {
            this.frequency   = 0.5f;
            this.lacunarity  = 2;
            this.offset      = 1;
            this.gain        = 2;
            this.exponent    = 1f;
            this.octaveCount = 4f;

            this.gradient  = GradientColors.Grayscale;
            this.quality   = PrimitiveModule.DefaultQuality;
            this.primitive = NoisePrimitive.ImprovedPerlin;
            this.filter    = NoiseFilter.MultiFractal;

            this.pModule = new ImprovedPerlin();

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

            this.fModule = new MultiFractal();

            this.scale = new ScaleBias(fModule, 1f, -0.8f);

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

            this.finalModule = scale;

            return(this.finalModule.GetValue(cubeWorldPosition.X, cubeWorldPosition.Y, cubeWorldPosition.Z));
        }
Exemple #16
0
    public XNoiseTurbulence()
    {
        left   = 6;
        right  = 10;
        top    = 1;
        bottom = 5;

        var mountainTerrain = new RidgedMultifractal();

        var baseFlatTerrain = new Billow();

        baseFlatTerrain.Frequency = 2.0;

        var flatTerrain = new ScaleBias(0.125, -0.75, baseFlatTerrain);

        var terrainType = new Perlin();

        terrainType.Frequency   = 0.5;
        terrainType.Persistence = 0.25;

        var terrainSelector = new Select(flatTerrain, mountainTerrain, terrainType);

        terrainSelector.SetBounds(0, 1000);
        terrainSelector.FallOff = 0.125f;

        var terrainScaler = new ScaleBias(terrainSelector);

        terrainScaler.Scale = 375;
        terrainScaler.Bias  = 375;

        finalTerrain           = new Turbulence(terrainScaler);
        finalTerrain.Frequency = 4;
        finalTerrain.Power     = 0.125f;
    }
    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;
    }
        protected override void ConfigureProviders(int seed)
        {
            //Generate perlin noise
            //Scale to be lower, bias to plains range
            Perlin baseTerrain = new Perlin()
            {
                OctaveCount = 8,
                Frequency   = 1.1,
                Persistence = 0.124,
                Seed        = seed
            };
            Perlin secondaryTerrain = new Perlin()
            {
                OctaveCount = 4,
                Frequency   = 1.5,
                Persistence = 0.123,
                Seed        = -seed
            };
            Add adder = new Add(baseTerrain, secondaryTerrain);

            ScaleBias provider = new ScaleBias(adder)
            {
                Scale = 0.125,
                //Bias = 0.03f
            };

            this._baseProvider = provider;
        }
    private void Start()
    {
        // STEP 1
        // Gradient is set directly on the object
        var mountainTerrain = new RidgedMultifractal();
        // // STEP 2
        var baseFlatTerrain = new Billow();

        baseFlatTerrain.Frequency = 2.0;
        // STEP 3
        var flatTerrain = new ScaleBias(0.125, -0.75, baseFlatTerrain);
        // STEP 4
        var terrainType = new Perlin();

        terrainType.Frequency   = 0.5;
        terrainType.Persistence = 0.25;

        var finalTerrain = new Select(flatTerrain, mountainTerrain, terrainType);

        finalTerrain.SetBounds(0, 1000);
        finalTerrain.FallOff = 0.125;

        float start = Time.realtimeSinceStartup;

        RenderAndSetImage(finalTerrain);
        Debug.Log("BurstLibNoise runtime: " + (Time.realtimeSinceStartup - start));
    }
Exemple #20
0
        public World()
        {
            _seed   = new Random().Next();
            _random = new Random(_seed);

            _perlin = new Perlin
            {
                Seed        = _seed,
                OctaveCount = OctaveCount,
                Frequency   = Frequency,
                //Persistence = Persistence
            };

            _scaleBias = new ScaleBias
            {
                Source0 = _perlin,
                Scale   = Scale,
                Bias    = Bias
            };

            _clamp = new Clamp
            {
                LowerBound = LowerBound,
                UpperBound = UpperBound,
                Source0    = _scaleBias
            };

            _builder = new PlaneNoiseMapBuilder
            {
                DestNoiseMap   = new NoiseMap(),
                SourceModule   = _clamp,
                EnableSeamless = false
            };
            _builder.SetDestSize(Chunk.CHUNK_SIZE, Chunk.CHUNK_SIZE);
        }
Exemple #21
0
    /// <summary>
    /// modifies a module
    /// </summary>
    /// <returns>The mod.</returns>
    /// <param name="baseMod">Base mod.</param>
    /// <param name="modType">Mod type.</param>
    private static ModuleBase modMod(ModuleBase baseMod, int modType, System.Random rand)
    {
        switch (modType)
        {
        case 0:         //curves
            Curve c = new Curve(baseMod);
            for (int i = 0; i < 4; i++)
            {
                c.Add(rand.NextDouble() * 2 - 1, rand.NextDouble() * 2 - 1);
            }
            return(c);

        case 1:        //terrace
            Terrace terr      = new Terrace(baseMod);
            int     numPoints = rand.Next(1, 10);
            for (int i = 0; i < numPoints; i++)
            {
                terr.Add(randDoub(-1, 1, rand.NextDouble()));
            }
            return(terr);

        case 2:        //add noise
            float      scale        = eDist(1, 10000, rand.NextDouble());
            ModuleBase addedTerrain = getGradientNoise(hnProb, rand.NextDouble(), scale, rand);
            double     amplitude    = eDist(.5, scale / 4, rand.NextDouble());
            addedTerrain = new ScaleBias(amplitude, 0, addedTerrain);
            return(new Add(baseMod, addedTerrain));

        case 3:         //scale module input(stretch it)
            return(new Scale(rand.NextDouble() * 5 + .01, rand.NextDouble() * 5 + .01, rand.NextDouble() * 5 + .01, baseMod));

        default:
            return(new Checker());
        }
    }
Exemple #22
0
        public OverworldTerrain(OverworldTerrainSettings ots, bool isUnitTest = false)
        {
            settings = ots;

            ocean     = new OceanTerrain(ots);
            plains    = new PlainsTerrain(ots);
            hills     = new HillsTerrain(ots);
            badlands  = new BadlandsTerrain(ots);
            mountains = new MountainsTerrain(ots);
            rivers    = new RiverTerrain(ots);

            humidity    = new HumidityNoise(ots);
            temperature = new TemperatureNoise(ots);
            terrain     = new TerrainNoise(ots);

            cave = new CavesCarver(ots);

            // Scale Point multiplies input values by the scaling factors.
            // Used to stretch or shrink the terrain horizontally.
            var scaled = GetScaledModuleOutput(MergedLandOceanRivers());
            //var scaled = GetScaledModuleOutput(LandOceanSelector());
            //var scaled = GetScaledModuleOutput(temperature.RiverSelector);

            // Scale bias scales the verical output (usually -1.0 to +1.0) to
            // Minecraft values. If MinElev is 40 (leaving room for caves under oceans)
            // and MaxElev is 168, a value of -1 becomes 40, and a value of 1 becomes 168.
            var biased = new ScaleBias
            {
                Scale   = (settings.MaxElev - settings.MinElev) / 2.0,
                Bias    = settings.MinElev + ((settings.MaxElev - settings.MinElev) / 2.0) - 44,
                Source0 = scaled
            };

            Result = isUnitTest ? scaled : biased;
        }
Exemple #23
0
        public override void Generate(Map map, GenStepParams parms)
        {
            if (map.Biome != Util_CaveBiome.CaveBiomeDef)
            {
                // Nothing to do in other biomes.
                return;
            }

            // Generate basic map elevation.
            NoiseRenderer.renderSize = new IntVec2(map.Size.x, map.Size.z);
            ModuleBase perlinMap = new Perlin(ElevationFreq, 1.0, 0.5, 6, Rand.Range(0, 2147483647), QualityMode.High);

            perlinMap = new ScaleBias(0.5, 0.5, perlinMap);
            NoiseDebugUI.StoreNoiseRender(perlinMap, "Cave: elev base");
            perlinMap = new Multiply(perlinMap, new Const(ElevationFactorCave));
            NoiseDebugUI.StoreNoiseRender(perlinMap, "Cave: elev cave-factored");

            // Override base elevation grid so the GenStep_Terrain.Generate function uses this one.
            MapGenFloatGrid mapGenFloatGrid = MapGenerator.FloatGridNamed("Elevation");

            foreach (IntVec3 current in map.AllCells)
            {
                mapGenFloatGrid[current] = perlinMap.GetValue(current);
            }
        }
        public static void Init(Map map)
        {
            Rot4 a = Find.World.CoastDirectionAt(map.Tile);

            if (!a.IsValid)
            {
                BeachMaker.beachNoise = null;
                return;
            }
            ModuleBase moduleBase = new Perlin(0.029999999329447746, 2.0, 0.5, 3, Rand.Range(0, int.MaxValue), QualityMode.Medium);

            moduleBase = new ScaleBias(0.5, 0.5, moduleBase);
            NoiseDebugUI.StoreNoiseRender(moduleBase, "BeachMaker base", new IntVec2(map.Size.x, map.Size.z));
            ModuleBase moduleBase2 = new DistFromAxis(BeachMaker.CoastWidthRange.RandomInRange);

            if (a == Rot4.North)
            {
                moduleBase2 = new Rotate(0.0, 90.0, 0.0, moduleBase2);
                moduleBase2 = new Translate(0.0, 0.0, (double)(-(double)map.Size.z), moduleBase2);
            }
            else if (a == Rot4.East)
            {
                moduleBase2 = new Translate((double)(-(double)map.Size.x), 0.0, 0.0, moduleBase2);
            }
            else if (a == Rot4.South)
            {
                moduleBase2 = new Rotate(0.0, 90.0, 0.0, moduleBase2);
            }
            moduleBase2 = new ScaleBias(1.0, -1.0, moduleBase2);
            moduleBase2 = new Clamp(-1.0, 2.5, moduleBase2);
            NoiseDebugUI.StoreNoiseRender(moduleBase2, "BeachMaker axis bias");
            BeachMaker.beachNoise = new Add(moduleBase, moduleBase2);
            NoiseDebugUI.StoreNoiseRender(BeachMaker.beachNoise, "beachNoise");
        }
    void Start()
    {
        var mountainTerrain = new RidgedMultifractal();

        var baseFlatTerrain = new Billow();

        baseFlatTerrain.Frequency = 2.0;

        var flatTerrain = new ScaleBias(0.125, -0.75, baseFlatTerrain);

        var terrainType = new Perlin();

        terrainType.Frequency   = 0.5;
        terrainType.Persistence = 0.25;

        // Create the selector for turbulence
        var terrainSelector = new Select(flatTerrain, mountainTerrain, terrainType);

        terrainSelector.SetBounds(0, 1000);
        terrainSelector.FallOff = 0.125f;

        var finalTerrain = new Turbulence(terrainSelector);

        finalTerrain.Frequency = _frequency;
        finalTerrain.Power     = _power;

        RenderAndSetImage(finalTerrain);
    }
Exemple #26
0
        /// <summary>
        /// Build the noise tree used for terrain generation
        /// </summary>
        private Module BuildModuleTree()
        {
            var mountainTerrain = new RidgedMulti()
            {
                Seed = this.Seed
            };

            var baseFlatTerrain = new Billow()
            {
                Seed      = this.Seed,
                Frequency = 2
            };

            var flatTerrain = new ScaleBias()
            {
                Source0 = baseFlatTerrain,
                Scale   = 0.125,
                Bias    = -0.75
            };

            var terrainType1 = new Perlin()
            {
                Frequency   = 0.5,
                Persistence = 0.25,
                Seed        = this.Seed
            };

            var terrainType2 = new Perlin()
            {
                Frequency   = 0.5,
                Persistence = 0.25,
                Seed        = this.Seed + 1337
            };

            var terrainType = new Multiply()
            {
                Source0 = terrainType1,
                Source1 = terrainType2
            };

            var terrainSelector = new Select()
            {
                Source0     = flatTerrain,
                Source1     = mountainTerrain,
                Control     = terrainType,
                LowerBound  = 0,
                UpperBound  = 1000,
                EdgeFalloff = 0.125
            };

            var finalTerrain = new Turbulence()
            {
                Source0   = terrainSelector,
                Frequency = 4,
                Power     = 0.125,
                Seed      = this.Seed
            };

            return(finalTerrain);
        }
Exemple #27
0
        private void SetupSwampinessNoise()
        {
            float      freqMultiplier = WorldGenStep_Terrain.FreqMultiplier;
            ModuleBase input          = new Perlin(0.090000003576278687 * freqMultiplier, 2.0, 0.40000000596046448, 6, Rand.Range(0, 2147483647), QualityMode.High);
            ModuleBase input2         = new RidgedMultifractal(0.02500000037252903 * freqMultiplier, 2.0, 6, Rand.Range(0, 2147483647), QualityMode.High);

            input  = new ScaleBias(0.5, 0.5, input);
            input2 = new ScaleBias(0.5, 0.5, input2);
            this.noiseSwampiness = new Multiply(input, input2);
            ModuleBase  module = this.noiseElevation;
            FloatRange  swampinessMaxElevation = WorldGenStep_Terrain.SwampinessMaxElevation;
            float       max = swampinessMaxElevation.max;
            FloatRange  swampinessMaxElevation2 = WorldGenStep_Terrain.SwampinessMaxElevation;
            InverseLerp rhs = new InverseLerp(module, max, swampinessMaxElevation2.min);

            this.noiseSwampiness = new Multiply(this.noiseSwampiness, rhs);
            ModuleBase  module2 = this.noiseRainfall;
            FloatRange  swampinessMinRainfall = WorldGenStep_Terrain.SwampinessMinRainfall;
            float       min = swampinessMinRainfall.min;
            FloatRange  swampinessMinRainfall2 = WorldGenStep_Terrain.SwampinessMinRainfall;
            InverseLerp rhs2 = new InverseLerp(module2, min, swampinessMinRainfall2.max);

            this.noiseSwampiness = new Multiply(this.noiseSwampiness, rhs2);
            NoiseDebugUI.StorePlanetNoise(this.noiseSwampiness, "noiseSwampiness");
        }
Exemple #28
0
        private void SetupRainfallNoise()
        {
            float      freqMultiplier = WorldGenStep_Terrain.FreqMultiplier;
            ModuleBase input          = new Perlin(0.014999999664723873 * freqMultiplier, 2.0, 0.5, 6, Rand.Range(0, 2147483647), QualityMode.High);

            input = new ScaleBias(0.5, 0.5, input);
            NoiseDebugUI.StorePlanetNoise(input, "basePerlin");
            SimpleCurve simpleCurve = new SimpleCurve();

            simpleCurve.Add(0f, 1.12f, true);
            simpleCurve.Add(25f, 0.94f, true);
            simpleCurve.Add(45f, 0.7f, true);
            simpleCurve.Add(70f, 0.3f, true);
            simpleCurve.Add(80f, 0.05f, true);
            simpleCurve.Add(90f, 0.05f, true);
            ModuleBase moduleBase = new AbsLatitudeCurve(simpleCurve, 100f);

            NoiseDebugUI.StorePlanetNoise(moduleBase, "latCurve");
            this.noiseRainfall = new Multiply(input, moduleBase);
            float      num    = 0.000222222225f;
            float      num2   = (float)(-500.0 * num);
            ModuleBase input2 = new ScaleBias((double)num, (double)num2, this.noiseElevation);

            input2 = new ScaleBias(-1.0, 1.0, input2);
            input2 = new Clamp(0.0, 1.0, input2);
            NoiseDebugUI.StorePlanetNoise(input2, "elevationRainfallEffect");
            this.noiseRainfall = new Multiply(this.noiseRainfall, input2);
            Func <double, double> processor = delegate(double val)
            {
                if (val < 0.0)
                {
                    val = 0.0;
                }
                if (val < 0.12)
                {
                    val = (val + 0.12) / 2.0;
                    if (val < 0.03)
                    {
                        val = (val + 0.03) / 2.0;
                    }
                }
                return(val);
            };

            this.noiseRainfall = new Arbitrary(this.noiseRainfall, processor);
            this.noiseRainfall = new Power(this.noiseRainfall, new Const(1.5));
            this.noiseRainfall = new Clamp(0.0, 999.0, this.noiseRainfall);
            NoiseDebugUI.StorePlanetNoise(this.noiseRainfall, "noiseRainfall before mm");
            this.noiseRainfall = new ScaleBias(4000.0, 0.0, this.noiseRainfall);
            SimpleCurve rainfallCurve = Find.World.info.overallRainfall.GetRainfallCurve();

            if (rainfallCurve != null)
            {
                this.noiseRainfall = new CurveSimple(this.noiseRainfall, rainfallCurve);
            }
        }
Exemple #29
0
        public override Module GetModule()
        {
            int n = 2 + (int)Mathf.Log(_height, 2);

            var mountainTerrain = new RidgedMulti()
            {
                Frequency   = 1,
                Lacunarity  = 1.9532562354f,
                OctaveCount = n,
                Seed        = _seed + 2 * _offset
            };

            var baseFlatTerrain = new Billow()
            {
                Frequency   = 2,
                Lacunarity  = 2.031242124f,
                OctaveCount = n,
                Seed        = _seed + 1 * _offset,
            };

            var flatTerrain = new ScaleBias()
            {
                Source0 = baseFlatTerrain,
                Scale   = 0.75,
                Bias    = -0.25,
            };

            var terrainType = new Perlin()
            {
                Frequency   = _frequency,
                Lacunarity  = 2.1023423f,
                Persistence = 0.25,
                OctaveCount = n,
                Seed        = _seed
            };

            var terrainSelector = new Select()
            {
                Source0     = flatTerrain,
                Source1     = mountainTerrain,
                Control     = terrainType,
                LowerBound  = 0,
                UpperBound  = 1000,
                EdgeFalloff = 0.125,
            };

            var finalTerrain = new Turbulence()
            {
                Source0   = terrainSelector,
                Frequency = 4,
                Roughness = 8,
                Power     = 0.125,
            };

            return(finalTerrain);
        }
        public override object Run()
        {
            ScaleBias bias = new ScaleBias(
                GetInputValue <SerializableModuleBase>("Input", this.Input));

            bias.Scale = GetInputValue <double>("Scale", this.Scale);
            bias.Bias  = GetInputValue <double>("Bias", this.Bias);

            return(bias);
        }
		public override void Generate()
		{
            if (Find.Map.Biome != Util_CaveBiome.CaveBiomeDef)
            {
                // Nothing to do in other biomes.
                return;
            }
			NoiseRenderer.renderSize = new IntVec2(Find.Map.Size.x, Find.Map.Size.z);
            ModuleBase moduleBase = new Perlin(ElevationFreq, 1.0, 0.5, 6, Rand.Range(0, 2147483647), QualityMode.High);
			moduleBase = new ScaleBias(0.5, 0.5, moduleBase);
            NoiseDebugUI.StoreNoiseRender(moduleBase, "Cave: elev base");
            moduleBase = new Multiply(moduleBase, new Const((double)ElevationFactorCave));
            NoiseDebugUI.StoreNoiseRender(moduleBase, "Cave: elev cave-factored");
            // Override base elevation grid so the GenStep_Terrain.Generate function uses this one.
            MapGenFloatGrid mapGenFloatGrid = MapGenerator.FloatGridNamed("Elevation");
			foreach (IntVec3 current in Find.Map.AllCells)
			{
                mapGenFloatGrid[current] = moduleBase.GetValue(current);
			}
		}