示例#1
0
        public override void Update(float dt)
        {
            if ((Game1.Instance.last_mouse_state.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed) &&
                (Game1.Instance.current_mouse_state.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Released))
            {
                for (int i = 0; i < Buttons.Length; i++)
                {
                    if (Buttons[i].Contains(Game1.Instance.current_mouse_state.X, Game1.Instance.current_mouse_state.Y))
                    {
                        switch (i)
                        {
                        case 0:
                        {
                            zoom -= 0.05f;
                            m_noiseMap.GeneratePlanar(-1 * zoom, 1 * zoom, -1 * zoom, 1 * zoom);
                            m_textures[3] = m_noiseMap.GetTexture(m_graphics, Gradient.Terrain);
                        }
                        break;

                        case 1:
                        {
                            zoom += 0.05f;
                            m_noiseMap.GeneratePlanar(-1 * zoom, 1 * zoom, -1 * zoom, 1 * zoom);
                            m_textures[3] = m_noiseMap.GetTexture(m_graphics, Gradient.Terrain);
                        }
                        break;
                        }
                    }
                }
            }
        }
示例#2
0
 private void GenerateWorldMap()
 {
     planarNoiseMap = null;
     module         = moduleCreation();
     planarNoiseMap = new Noise2D(mapWidth, mapHeight, module);
     planarNoiseMap.GeneratePlanar(-1, 1, -1, 1, true);
 }
示例#3
0
        public Map GenerateMap(Vector2 offset)
        {
            Debug.Log(string.Format("Generating map with offset {0}:{1}, seed: {2}", offset.x, offset.y, seed));
            var perlin = new Perlin();

            perlin.OctaveCount = octaves;
            perlin.Frequency   = frequency;
            perlin.Lacunarity  = lacunarity;
            perlin.Persistence = persistence;
            perlin.Seed        = seed;

            var heightMapBuilder = new Noise2D(ChunkSize, ChunkSize, perlin);
            var halfShift        = new Vector2(0.5f / noiseScale.x, 0.5f / noiseScale.y);

            heightMapBuilder.GeneratePlanar(
                (offset.x + noiseShift.x) / noiseScale.x - halfShift.x,
                (offset.x + noiseShift.x) / noiseScale.x + halfShift.x,
                (-offset.y + noiseShift.y) / noiseScale.y - halfShift.y,
                (-offset.y + noiseShift.y) / noiseScale.y + halfShift.y
                );

            // prepare texture
            var colorMap = heightMapBuilder.GetTexturePixels(terrainColors);

            Debug.Log("Texture created");
            // preare height map
            var heightMap = new HeightMap(
                data: heightMapBuilder.GetNormalizedData(),
                heightMultiplier: meshHeightMultiplier,
                heightCurve: new AnimationCurve(meshHeightCurve.keys)
                );


            return(new Map(heightMap, colorMap));
        }
    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());
    }
示例#5
0
    public void generate()
    {
        // Get the terrain data of the currently active terrain
        var terrainData = Terrain.activeTerrain.terrainData;

        // A new ridged multifractal generator
        var generator = new RidgedMultifractal(frequency, lacu, octaves, (int)(Random.value * 0xffffff), QualityMode.High);

        // The thresholded output -- choose either 0.0 or 1.0, based on the output
        var clamped = new LibNoise.Operator.Select(new Const(0.0f), new Const(1.0f), generator);

        // Set the threshold and falloff rate
        clamped.SetBounds(0f, threshold);
        clamped.FallOff = falloff;

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

        // 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);
        var data = noise.GetNormalizedData();

        // .. and actually set the heights
        terrainData.SetHeights(0, 0, data);
    }
示例#6
0
    //  Other Functions
    //    ----------------------------------------------------------------------------


    void Generate()
    {
        Perlin myPerlin = new Perlin();

        ModuleBase myModule = myPerlin;



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

        // - Generate -

        // this part generates the heightmap to a texture,
        // and sets the renderer material texture of a cube to the generated texture


        Noise2D heightMap;

        heightMap = new Noise2D(mapSizeX, mapSizeY, myModule);

        heightMap.GeneratePlanar(
            sampleOffsetX,
            sampleOffsetX + sampleSizeX,
            sampleOffsetY,
            sampleOffsetY + sampleSizeY
            );

        texture = heightMap.GetTexture(grad);
        texture.Apply();

        cubeRenderer.material.SetTexture("_BaseMap", texture);
    }
示例#7
0
    void GenerateOwnBlend()
    {
        ModuleBase perlin  = new Perlin(1, 2, .5, 6, 42, QualityMode.Medium);
        ModuleBase voronoi = new Voronoi(Frequency, Displacement, 42, true);
        //ModuleBase blend = new Add(perlin, voronoi);
        Curve curve = new Curve(perlin);

        foreach (var point in Acurve.keys)
        {
            curve.Add(point.time, point.value);
        }

        //curve.Add(0d, .1d);
        //curve.Add(.5d, .5d);
        //curve.Add(1.9d, .9d);

        var perlinbuilder = new Noise2D(Size, Size / 2, perlin);

        perlinbuilder.GeneratePlanar(_left, _right, _top, _bottom);

        var voronoibuilder = new Noise2D(Size, Size / 2, voronoi);

        voronoibuilder.GeneratePlanar(_left, _right, _top, _bottom);

        var blendbuilder = new Noise2D(Size, Size / 2, curve);

        blendbuilder.GeneratePlanar(_left, _right, _top, _bottom);

        Perlin.material.SetTexture("_BaseMap", perlinbuilder.GetTexture(_gradient));
        Voronoi.material.SetTexture("_BaseMap", voronoibuilder.GetTexture(_gradient));
        Mix.material.SetTexture("_BaseMap", blendbuilder.GetTexture(_gradient));
    }
    void Generate()
    {
        Perlin myPerlin = new Perlin();

        ModuleBase myModule = myPerlin;



        // generates a heightmap to a texture,
        // and sets the renderer material texture of a cube to the generated texture

        Noise2D heightMap;

        heightMap = new Noise2D(mapX, mapY, myModule);
        heightMap.GeneratePlanar(
            sampleOffsetX,
            sampleOffsetX + sampleSizeX,
            sampleOffsetY,
            sampleOffsetY + sampleSizeY
            );

        texture = heightMap.GetTexture(GradientPresets.Grayscale);

        GetComponent <Renderer>().material.mainTexture = texture;
    }
        void Calculate(object state)
        {
            Noise = new Noise2D(width, height, module);
            Noise.GeneratePlanar(4.0f, 10.0f, 1.0f, 5.0f);

            Done = true;
        }
示例#10
0
        public static void generateHeightmap(GameObject terrObject, ModuleBase modbase, float alphaAmount, float noiseAmp)
        {
            Vector3 gopos      = terrObject.transform.position;
            float   cwidth     = terrObject.GetComponent <Terrain>().terrainData.size.x;
            int     resolution = terrObject.GetComponent <Terrain>().terrainData.heightmapResolution;

            float[,] hmap = new float[resolution, resolution];
            double  yoffset     = 0 - (gopos.x / cwidth);
            double  xoffset     = (gopos.z / cwidth);
            Noise2D tmpNoiseMap = new Noise2D(resolution, resolution, modbase);

            tmpNoiseMap.GeneratePlanar(xoffset, (xoffset) + (1f / resolution) * (resolution + 1), -yoffset, (-yoffset) + (1f / resolution) * (resolution + 1));
            if (alphaAmount == 1.0f)
            {
                for (int hY = 0; hY < resolution; hY++)
                {
                    for (int hX = 0; hX < resolution; hX++)
                    {
                        hmap[hX, hY] = ((tmpNoiseMap[hX, hY] * 0.5f) + 0.5f) * noiseAmp;
                    }
                }
            }
            else
            {
                hmap = terrObject.GetComponent <Terrain>().terrainData.GetHeights(0, 0, resolution, resolution);
                for (int hY = 0; hY < resolution; hY++)
                {
                    for (int hX = 0; hX < resolution; hX++)
                    {
                        hmap[hX, hY] = ((1.0f - alphaAmount) * hmap[hX, hY]) + (alphaAmount * (((tmpNoiseMap[hX, hY] * 0.5f) + 0.5f) * noiseAmp));
                    }
                }
            }
            terrObject.GetComponent <Terrain>().terrainData.SetHeights(0, 0, hmap);
        }
示例#11
0
    void RenderAndSetImage(ModuleBase generator)
    {
        var heightMapBuilder = new Noise2D(256, 256, generator);

        heightMapBuilder.GeneratePlanar(_left, _right, _top, _bottom);
        var image = heightMapBuilder.GetTexture(_gradient);

        renderer.material.mainTexture = image;
    }
示例#12
0
    //  Other Functions
    //    ----------------------------------------------------------------------------


    void Generate()
    {
        Perlin myPerlin = new Perlin();

        ModuleBase myModule = myPerlin;



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

        // - Generate -

        // this part generates the heightmap to a texture,
        // and sets the renderer material texture of a cube to the generated texture


        Noise2D heightMap;

        heightMap = new Noise2D(mapSizeX, mapSizeY, myModule);

        heightMap.GeneratePlanar(
            sampleOffsetX,
            sampleOffsetX + sampleSizeX,
            sampleOffsetY,
            sampleOffsetY + sampleSizeY
            );


        //Debug.Log(cubeRenderer.material.mainTexture.name);
        texture = heightMap.GetTexture(LibNoise.Unity.Gradient.Grayscale);

        cubeRenderer.material.mainTexture = texture;
        //cubeRenderer.material.SetTexture("MainTexture", texture);
        texture.name = "noise";

        asteroidMaterial.mainTexture = texture;
        GetComponent <Renderer>().material.mainTexture = texture;
        GetComponent <Renderer>().material.SetTexture("_MainTexture", texture);

        /*
         *
         * mat.mainTexture = tex;
         * cubeRenderer.material = mat;
         *
         *
         * cubeRenderer.material.mainTexture = tex;
         * cubeRenderer.material.mainTexture.wrapMode = TextureWrapMode.Clamp;
         * tex.wrapMode = TextureWrapMode.Clamp;
         *
         * Color[] pixels = tex.GetPixels();
         *
         *
         *
         * cubeRenderer.material = asteroidMaterial;
         * asteroidMaterial.SetTexture("_MainTex", texture);*/
    }
    private void UpdateTexture()
    {
        texture.Resize(resolution.x, resolution.y);
        texture.wrapModeU           = wrapModeU;
        texture.wrapModeV           = wrapModeV;
        texture.alphaIsTransparency = true;
        texture.name = "Noise_" + name;

        if (seed == 0)
        {
            seed = Random.Range(int.MinValue, int.MaxValue);
        }

        ModuleBase noiseGenerator;

        switch (noiseType)
        {
        case NoiseType.Billow:
            Billow billow = new Billow(frequency, lacunarity, persistence, octaves, seed, QualityMode.High);
            noiseGenerator = billow;
            break;

        case NoiseType.RidgedMultifractal:
            RidgedMultifractal ridgedMultifractal = new RidgedMultifractal(frequency, lacunarity, octaves, seed, QualityMode.High);
            noiseGenerator = ridgedMultifractal;
            break;

        case NoiseType.Voronoi:
            Voronoi voronoi = new Voronoi(frequency, displacement, seed, distance);
            noiseGenerator = voronoi;
            break;

        default:
            //Default to perlin so the compiled doesn't complain
            Perlin perlin = new Perlin(frequency, lacunarity, persistence, octaves, seed, QualityMode.High);
            noiseGenerator = perlin;
            break;
        }

        Noise2D noiseMap = new Noise2D(resolution.x, resolution.y, noiseGenerator);

        noiseMap.GeneratePlanar(
            offset.x + -1 * 1 / zoom.x,
            offset.x + offset.x + 1 * 1 / zoom.x,
            offset.y + -1 * 1 / zoom.y,
            offset.y + 1 * 1 / zoom.y,
            isSeamless
            );
        Texture2D noiseTexture = noiseMap.GetTexture(colorGradient);

        Color32[] colorArray = noiseTexture.GetPixels32();
        texture.SetPixels32(0, 0, texture.width, texture.height, colorArray);
        texture.Apply();
        AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(texture));
        EditorUtility.SetDirty(this);
    }
    void RenderAndSetImage(ModuleBase generator)
    {
        var heightMapBuilder = new Noise2D(Width, Height, generator);

        heightMapBuilder.GeneratePlanar(Noise2D.Left, Noise2D.Right, Noise2D.Top, Noise2D.Bottom);
        // heightMapBuilder.GenerateSpherical(90, -90, -180, 180);
        // heightMapBuilder.GenerateCylindrical(-180, 180, -1, 1);
        var image = heightMapBuilder.GetTexture();

        GetComponent <Renderer>().material.mainTexture = image;
    }
示例#15
0
    private static void LayerNoise(Noise2D baseNoise, ModuleBase module)
    {
        Noise2D thisNoise = new Noise2D(baseNoise.Width, baseNoise.Height, module);

        thisNoise.GeneratePlanar(
            -1,
            1,
            -1,
            1, true);
        AddNoise(baseNoise, thisNoise);
    }
示例#16
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]);
    }
示例#17
0
        void DrawSelectedNodeDetails(NodeBase node)
        {
            if (previewNeedsUpdate || lastSelected != node)
            {
                preview = new Texture2D(230, 230);
                if (node.Module != null && previewCalculation == null)
                {
                    previewCalculation = new NoiseCalculation(node.Module, 230, 230);
                }
                previewNeedsUpdate = false;
                lastSelected       = node;
            }

            if (previewCalculation != null && previewCalculation.Done)
            {
                preview            = previewCalculation.Noise.GetTexture();
                previewCalculation = null;
            }

            var state = mainEditorState as NoiseDesignerState;

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Selected Node:");
            GUILayout.Box(preview);
            EditorGUILayout.Space();
            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("Apply to terrain:");
            terrain = EditorGUILayout.ObjectField("TerrainData", terrain, typeof(TerrainData), false) as TerrainData;
            if (GUILayout.Button("Apply"))
            {
                Noise2D noise = new Noise2D(terrain.heightmapWidth, terrain.heightmapHeight, node.Module);
                noise.GeneratePlanar(4.0f, 10.0f, 1.0f, 5.0f);
                terrain.SetHeights(0, 0, noise.GetNormalizedData());
            }
            EditorGUILayout.Space();
            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("Export as texture:");
            state.textureSize = EditorGUILayout.Vector2Field("Texture Size", state.textureSize);
            if (GUILayout.Button("Save as PNG"))
            {
                var path = EditorUtility.SaveFilePanelInProject("Save as PNG", "noise", "png", "");
                if (!string.IsNullOrEmpty(path))
                {
                    Noise2D noise = new Noise2D((int)state.textureSize.x, (int)state.textureSize.y, node.Module);
                    noise.GeneratePlanar(4.0f, 10.0f, 1.0f, 5.0f);
                    var texture = noise.GetTexture();
                    File.WriteAllBytes(path, texture.EncodeToPNG());
                    AssetDatabase.Refresh();
                }
            }
        }
示例#18
0
    void RenderAndSetImage(ModuleBase generator)
    {
        var heightMapBuilder = new Noise2D(Noise.Width, Noise.Height, generator);

        heightMapBuilder.GeneratePlanar(Noise.xOrg, Noise.xOrg + 5, Noise.yOrg, Noise.yOrg + 5);
        var image = heightMapBuilder.GetTexture(Noise.Gradient);

        image.Apply();
        image.filterMode = FilterMode.Point;

        Sprite sprite = Sprite.Create(image, new Rect(0, 0, 64, 64), Vector2.zero, 32, 1);

        transform.GetComponent <SpriteRenderer>().sprite = sprite;
    }
    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();
    }
示例#20
0
        public override void Initialise(GraphicsDevice device, ContentManager content)
        {
            m_graphics    = device;
            m_spriteBatch = new SpriteBatch(device);
            m_content     = content;

            // Create the module network

            add = new Add(perlin, rigged);

            // Initialize the noise map
            m_noiseMap = new Noise2D(256, 256, add);
            m_noiseMap.GeneratePlanar(-1, 1, -1, 1);

            // Generate the textures
            m_textures[0] = m_noiseMap.GetTexture(m_graphics, Gradient.Grayscale);
            m_textures[1] = m_noiseMap.GetTexture(m_graphics, Gradient.Terrain);
            m_textures[2] = m_noiseMap.GetNormalMap(m_graphics, 3.0f);

            // Zoom in or out do something like this.

            m_noiseMap.GeneratePlanar(-1 * zoom, 1 * zoom, -1 * zoom, 1 * zoom);
            m_textures[3] = m_noiseMap.GetTexture(m_graphics, Gradient.Terrain);
        }
示例#21
0
    void GenerateOwnTests()
    {
        ModuleBase perlin  = new Perlin(1, 2, .5, 6, seed, QualityMode.Medium);
        ModuleBase voronoi = new Voronoi(Frequency, Displacement, seed, true);
        ModuleBase add     = new Add(perlin, voronoi);

        Terrace terrace = new Terrace(false, add);

        terrace.Add(0f);
        terrace.Add(one);
        terrace.Add(two);

        var perlinbuilder = new Noise2D(Size, Size / 2, perlin);

        perlinbuilder.GeneratePlanar(_left, _right, _top, _bottom);

        var voronoibuilder = new Noise2D(Size, Size / 2, voronoi);

        voronoibuilder.GeneratePlanar(_left, _right, _top, _bottom);

        var addbuilder = new Noise2D(Size, Size / 2, add);

        addbuilder.GeneratePlanar(_left, _right, _top, _bottom);

        var terracebuilder = new Noise2D(Size, Size / 2, terrace);

        terracebuilder.GeneratePlanar(_left, _right, _top, _bottom);

        var perlintex  = perlinbuilder.GetTexture(_gradient);
        var voronoitex = voronoibuilder.GetTexture(_gradient);
        var addtex     = addbuilder.GetTexture(_gradient);
        var terracetex = terracebuilder.GetTexture(_gradient);

        perlintex.Apply();
        voronoitex.Apply();
        addtex.Apply();
        terracetex.Apply();

        Perlin.material.SetTexture("_BaseMap", perlintex);
        Voronoi.material.SetTexture("_BaseMap", voronoitex);
        Mix.material.SetTexture("_BaseMap", addtex);
        Terrace.material.SetTexture("_BaseMap", terracetex);

        //Perlin.material.SetTexture("_BaseMap", perlinbuilder.GetTexture(_gradient));
        //Voronoi.material.SetTexture("_BaseMap", voronoibuilder.GetTexture(_gradient));
        //Mix.material.SetTexture("_BaseMap", addbuilder.GetTexture(_gradient));
        //Terrace.material.SetTexture("_BaseMap", terracebuilder.GetTexture(_gradient));
    }
示例#22
0
    void RenderAndSetImage(ModuleBase generator, MeshRenderer rend)
    {
        var heightMapBuilder = new Noise2D(256, 256, generator);

        heightMapBuilder.GeneratePlanar(_left, _right, _top, _bottom);

        //heightMapBuilder.GenerateSpherical(
        //    south,
        //    north,
        //    west,
        //    east);

        var image = heightMapBuilder.GetTexture(_gradient);

        rend.material.SetTexture("_BaseMap", image);
    }
示例#23
0
    public void cavegen()
    {
        mapWidth  = 64;
        mapHeight = 64;
        Vector2 centre = new Vector2(mapWidth / 2, mapHeight / 2);

        tiles = new TileType[mapWidth, mapHeight];

        var perlin = new Perlin();

        perlin.OctaveCount = _octaveCount;
        perlin.Frequency   = _frecuency;
        perlin.Persistence = _persistence;
        perlin.Seed        = UnityEngine.Random.seed;

        var heightMapBuilder = new Noise2D(mapHeight, mapWidth, perlin);

        heightMapBuilder.GeneratePlanar(_west, _east, _north, _south);

        var image = heightMapBuilder.GetTexture(_gradient);

        for (int y = 0; y < mapHeight; y++)     //Starts an itteration for all y coordinates
        {
            for (int x = 0; x < mapHeight; x++) //Starts an itteration of all x coordinates for the given y coordinate
            {
                //Creates a tile at the given location
                double e = image.GetPixel(x, y).grayscale;

                tiles[x, y] = CaveTileSelector(e, x, y, mapWidth, centre);
            }
        }

        setWallTiles(64, 64);

        tiles[mapWidth / 2, mapHeight / 2] = TileType.Entrance;

        placeTiles(64, 64);

        enemyCountRange = new IntRange(0, 4);
        createEnemies();

        mainGameLoc = new Vector2(32, 32);

        CurrentCamera.transform.position = new Vector3(32 * 1.28f, 32 * 1.28f, -10);
        nextCameraLoc = CurrentCamera.transform.position;
    }
示例#24
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();
    }
    public static float[,] GenerateLibNoiseMap(int mapWidth, int mapHeight, int seed, float scale, int sheets, float persistance, float lacunarity, Vector2 offset)
    {
        RiggedMultifractal rmf = new RiggedMultifractal();

        Voronoi vor = new Voronoi();

        Perlin perlin = new Perlin(scale, lacunarity, persistance, sheets, seed, QualityMode.High);

        Const constGen = new Const(0.5f);

        var finalGenerator = new Add(new Multiply(perlin, constGen), new Multiply(rmf, constGen));

        Noise2D noiseGenerator = new Noise2D(mapWidth, mapHeight, finalGenerator);

        noiseGenerator.GeneratePlanar(0f, 1f, 0f, 1f);

        return(noiseGenerator.getData());
    }
示例#26
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();
    }
示例#27
0
    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();
    }
示例#28
0
    public MakePerlin(float seed)
    {
        perlin = new Texture2D(256, 256);
        ModuleBase moduleBase;

        moduleBase = new Perlin(m_frequency, m_lacunarity, m_persistence, m_octaveCount, (int)seed, m_quality);
        noiseMap   = new Noise2D(perlin.width, perlin.height, moduleBase);

        float zoom   = 1f;
        float offset = 0f;

        noiseMap.GeneratePlanar(
            offset + -1 * 1 / zoom,
            offset + offset + 1 * 1 / zoom,
            offset + -1 * 1 / zoom,
            offset + 1 * 1 / zoom);

        perlin = noiseMap.GetTexture();
    }
示例#29
0
    //function to create a new world.
    public void NewWorld()
    {
        //Sets up the perlin instance as defined above.
        var perlin = new Perlin();          //Creates a new instance of perlin noise

        perlin.OctaveCount = _octaveCount;  //Sets the octave count
        perlin.Frequency   = _frecuency;    //Sets the frquency
        perlin.Persistence = _persistence;  //Sets the persistence

        perlin.Seed = GetLevelSeed();       //Sets the seed for the world.

        //If the seed entry was left blank generate a random seed.
        if (perlin.Seed == 0)
        {
            perlin.Seed = UnityEngine.Random.seed; //Gets and sets the random seed.
        }

        var heightMapBuilder = new Noise2D(mapHeight, mapWidth, perlin); //Screates an instance of the heightmap builder from the perlin noise

        heightMapBuilder.GeneratePlanar(_west, _east, _north, _south);   //Generates a planar image.

        var image = heightMapBuilder.GetTexture(_gradient);              //Makes the colour range of the heighmap too be grayscale and exports it as an image

        //Will assign a sprite to each x and y value
        for (int y = 0; y < mapHeight; y++)     //Starts an itteration for all y coordinates
        {
            for (int x = 0; x < mapHeight; x++) //Starts an itteration of all x coordinates for the given y coordinate
            {
                //Creates a tile at the given location
                double e = image.GetPixel(x, y).grayscale;           //Gets the greyscale value of the given pixel

                map[x, y] = TileSelector(e, x, y, mapWidth, centre); //Selects a tile based upon the height value of the pixel
            }
        }

        mainGameLoc = new Vector2(128, 128);                                           //Sets the main game location to be the centre of the map.

        CurrentCamera.transform.position = new Vector3(128 * 1.28f, 128 * 1.28f, -10); //Sets the camera lcoation to be the centre of the map.
        nextCameraLoc = CurrentCamera.transform.position;                              //Sets the next loaction of the camera to be the current as it is not moving.

        SaveWorld();                                                                   //Saves the newly generated world.
    }
示例#30
0
    void Start()
    {
        var perlin = new Perlin();
        // Unlike on the base LibNoise tutorial, we don't have a separate heightMap target
        // to set - we will instead build it after.  We also initialize the resulting size
        // on the constructor instead of passing a separate destination size.
        var heightMapBuilder = new Noise2D(256, 256, perlin);

        heightMapBuilder.GeneratePlanar(_left, _right, _top, _bottom);

        // Get the image
        var image = heightMapBuilder.GetTexture(_gradient);

        // Set it. It may appear inverted from the example on the LibNoise site depending
        // on the angle at which the object is rotated/viewed.
        GetComponent <Renderer>().material.mainTexture = image;

        // We don't do the light changes for the texture, since that's beyond the scope of
        // this port
    }