コード例 #1
0
    public static float[,] Generate(int width, int height, int seed, int flatness, int voronoi_iterations, int voronoi_start)
    {
        // Create the module network
        ModuleBase moduleBase;

        moduleBase = new RidgedMultifractal();
        Noise2D sound = new Noise2D(width, height, moduleBase);

        sound.GeneratePlanar(
            -1,
            1,
            -1,
            1, true);

        for (int i = 0; i <= voronoi_iterations; i++)
        {
            seed++;
            ModuleBase tempBase = new Voronoi(voronoi_start + i, displacement, seed, false);
            Noise2D    temp     = new Noise2D(width, height, tempBase);
            temp.GeneratePlanar(
                -1,
                1,
                -1,
                1, true);
            LayerNoise(sound, tempBase);
            ModuleBase pBase = new Perlin()
            {
                OctaveCount = perlinOctaves
            };
            LayerNoise(sound, pBase);
        }
        Flatten(sound, flatness);

        return(sound.GetData());
    }
コード例 #2
0
    void Start()
    {
        var rawPerlin = new Perlin();

        rawPerlin.OctaveCount = 6;
        rawPerlin.Frequency   = 3;
        var planarPerlin = new Noise2D(64, 64, rawPerlin);

        planarPerlin.GeneratePlanar(0, 1, 0, 1);
        ppnoise = planarPerlin.GetData();
        Debug.Log("Raw perlin:" + rawPerlin.GetValue(.5, .5, .5));
        Debug.Log("Projected perlin:" + ppnoise[1, 1]);
    }
コード例 #3
0
    public combinedHeightHeat(IMap heightMap, IMap heatMap, worldChunkSettings chunkSettings)
    {
        Const  black        = new Const(-1);
        Select heightselect = new Select(heightMap.GetCache(), black, heightMap.GetCache());

        heightselect.SetBounds(.5, 1, .2);
        this.combo = new Add(heatMap.GetCache(), heightselect);
        //Invert invert = new Invert(combo);

        Noise2D final = new Noise2D(chunkSettings.mapWidth, chunkSettings.mapHeight, combo);

        final.GeneratePlanar(chunkSettings.left, chunkSettings.right, chunkSettings.top, chunkSettings.bottom, isSeamless: true);
        combinedCache = new Cache(combo);
        noiseData     = final.GetData();
    }
コード例 #4
0
    private void fill(worldChunkSettings chunkSettings, heightMapSettings settings)

    {
        RidgedMultifractal baseMap = new RidgedMultifractal();

        baseMap.OctaveCount = settings.Octaves;
        baseMap.Frequency   = settings.Frequency;
        baseMap.Lacunarity  = settings.Lacunarity;
        baseMap.Seed        = settings.Seed;

        Perlin layer2 = new Perlin();

        layer2.OctaveCount = settings.Octaves;
        layer2.Frequency   = settings.Frequency;
        layer2.Lacunarity  = settings.Lacunarity;
        layer2.Seed        = settings.Seed;
        Billow controller = new Billow();

        controller.Frequency = settings.Frequency;
        Blend  blend    = new Blend(baseMap, layer2, controller);
        Invert invert   = new Invert(blend);         //makes heightmap more island like
        Clamp  oceanfix = new Clamp(-.7, 1, invert); //prevent ocean floor from being to low

        //Const black = new Const(-1);
        // holes in surface at top of mountains
        //Select holes = new Select(oceanfix, black, oceanfix);
        //holes.SetBounds(.85, 1, .01); //get highest elevation with little falloff
        this.heightCache = new Cache(oceanfix);

        var final = new Noise2D(chunkSettings.mapHeight, chunkSettings.mapWidth, oceanfix);

        //turbulance = new Turbulence(12, baseMap);
        final.GeneratePlanar(chunkSettings.left, chunkSettings.right, chunkSettings.top, chunkSettings.bottom, isSeamless: true);
        //final.GenerateSpherical(1, 3,1, 3);

        /*
         * for (int x=0; x<mapWidth; x++)
         * {
         *  for (int y=0;y<mapHeight;y++)
         *  {
         *      noiseData[x,y] = (float)(baseMap.GetValue(x,0,y));
         *  }
         * }
         */
        noiseData = final.GetData();
    }
コード例 #5
0
    private void fill(worldChunkSettings chunkSettings, moistureMapSettings settings, IMap heightmap)

    {
        RidgedMultifractal baseMap = new RidgedMultifractal();

        baseMap.OctaveCount = settings.Octaves;
        baseMap.Frequency   = settings.Frequency;
        baseMap.Lacunarity  = settings.Lacunarity;
        baseMap.Seed        = settings.Seed;
        Turbulence distortion       = new Turbulence(.2, baseMap);
        Add        adjustedMoisture = new Add(distortion, heightmap.GetCache());

        this.moistureCache = new Cache(adjustedMoisture);
        Noise2D final = new Noise2D(chunkSettings.mapHeight, chunkSettings.mapWidth, adjustedMoisture);

        final.GeneratePlanar(chunkSettings.left, chunkSettings.right, chunkSettings.top, chunkSettings.bottom, isSeamless: true);
        noiseData = final.GetData();
    }
コード例 #6
0
ファイル: heatMap.cs プロジェクト: johnmcmahonart/2dMapGen
    private void fill(worldChunkSettings chunkSettings)

    {
        var          min        = chunkSettings.top;
        var          max        = chunkSettings.bottom;
        gradientHack baseMap    = new gradientHack(min, max);
        Turbulence   distortion = new Turbulence(.05, baseMap);

        //Curve lower = new Curve(distortion);
        //lower.Add(-.6, -.8);
        //lower.Add(-.2, -.6);
        //lower.Add(0.0, .2);
        this.heatCache = new Cache(distortion);

        Noise2D final = new Noise2D(chunkSettings.mapHeight, chunkSettings.mapWidth, distortion);

        final.GeneratePlanar(chunkSettings.left, chunkSettings.right, chunkSettings.top, chunkSettings.bottom, isSeamless: true);
        noiseData = final.GetData();
    }
コード例 #7
0
    public static int[,] GenerateBiomeMap(int width, int height, int numBiomes, int seed = 1992)
    {
        int        valueOffset = (numBiomes - 1) / 2;
        ModuleBase mod         = new Voronoi(3, valueOffset + 1, seed, false);
        Noise2D    sound       = new Noise2D(width, height, mod);

        sound.GeneratePlanar(-1, 1, -1, 1, false);
        float[,] plane = sound.GetData();
        List <float> heights = new List <float>();

        int[,] biomeMap = new int[width, height];

        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                int value = (int)Math.Round((double)plane[i, j], 1) + valueOffset;
                biomeMap[i, j] = value;
            }
        }
        return(biomeMap);
    }
コード例 #8
0
    void GenerateObject()
    {
        body = Instantiate(terrain);
        if (body)
        {
            this.name                    = "Terrain";
            body.transform.parent        = transform;
            body.name                    = "body";
            body.transform.localPosition = new Vector3(-250.0f, 0.0f, -250.0f);
        }
        else
        {
            Debug.LogError("Failed to created body on " + this.name + " object.");
            return;
        }

        if (generateWater)
        {
            sea = Instantiate(water);
            if (sea)
            {
                sea.transform.parent        = transform;
                sea.name                    = "water";
                waterHeight                 = Random.Range(seaLevel.x, seaLevel.y);
                sea.transform.localPosition = new Vector3(0.0f, waterHeight, 0.0f);
            }
            else
            {
                Debug.LogError("Failed to created water on " + this.name + " object.");
                return;
            }
        }

        //Get the terrain data of the currently active terrain
        var terrainData = Terrain.activeTerrain.terrainData;

        #region One Generator

        ////Create a new ridged multifractal generator with the settings, and a random seed
        //var generator = new RidgedMultifractal(frequency, lacu, octaves, Random.Range(0, 0xffffff), QualityMode.High);

        ////Create a 2D noise generator for the terrain heightmap, using the generator we just created
        //var noise = new Noise2D(terrainData.heightmapResolution, generator);

        #endregion

        #region Scaling

        ////Create a new perlin noise generator with the given settings.
        //var perlinGenerator = new Perlin(frequency, lacu, persist, octaves, Random.Range(0, 0xffffff), QualityMode.High);

        ////Create a constant value generator - every sampled point will be 0.8.
        //var constGenerator = new Const(0.8f);

        ////Combine the perlin noise generator and the const generator through multiplication -(perlin[x, y] * 0.8) for all x, y
        //var mixedGenerator = new Multiply(perlinGenerator, constGenerator);

        ////Create a new noise map
        //var noise = new Noise2D(terrainData.heightmapWidth, terrainData.heightmapHeight, mixedGenerator);

        #endregion

        #region Adding Two Functions

        //To scale each point by half
        var constGenerator = new Const(0.3f);

        //Create a new perlin noise generator with the given settings.
        var perlinGenerator = new Perlin(frequency, lacu, persist, octaves, Random.Range(0, 0xffffff), QualityMode.High);

        //Create a second perlin noise generator with some different settings.
        var perlinGenerator2 = new Perlin(frequency * 2, lacu, persist, octaves, Random.Range(0, 0xffffff) + 1, QualityMode.High);

        //Add together both generators scaled by 0.5f (so they add up to 1)
        var finalGenerator = new Add(new Multiply(perlinGenerator, constGenerator), new Multiply(perlinGenerator2, constGenerator));

        var constGenerator2 = new Const(0.8f);

        var finalGenerator2 = new Multiply(constGenerator2, finalGenerator);

        //Create a new noise map
        var noise = new Noise2D(terrainData.heightmapWidth, terrainData.heightmapHeight, finalGenerator2);

        #endregion

        //Generate a plane from [0, 1] on x, [0, 1] on y
        noise.GeneratePlanar(0, 1, 0, 1);

        //Get the data in an array so we can use it to set the heights
        var data = noise.GetData(true, 0, 0, true);

        //.. and actually set the heights
        terrainData.SetHeights(0, 0, data);
    }