Provides a two-dimensional noise map.
This covers most of the functionality from LibNoise's noiseutils library, but the method calls might not be the same. See the tutorials project if you're wondering which calls are equivalent.
Inheritance: IDisposable
    private Texture2D texture; // texture created for testing

    #endregion Fields

    #region Methods

    void Generate(bool addToSeed)
    {
        Voronoi mySphere = new Voronoi();
        mySphere.Seed = seedToModify;

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

        // - Compiled Terrain -

        Debug.LogError ("Not fetching seed data for planets!");
        ModuleBase myModule;

        myModule = mySphere;

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

        // - Generate -

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

        Noise2D heightMap;
        heightMap = new Noise2D( mapSizeX, mapSizeY, myModule );
        heightMap.GenerateSpherical( south, north, west, east );
        texture = heightMap.GetTexture(GradientPresets.RGBA);
        sphereRenderer.material.mainTexture = texture;

        sphereRenderer.material.SetTexture("_Normals",texture);
    }
Beispiel #2
0
    /// <summary>
    /// Gets the height map data.
    /// </summary>
    /// <returns>The height map data.</returns>
    /// <param name="w">The width.</param>
    /// <param name="h">The height.</param>
    public override float[,] GetHeightmapData(int w, int h, int x, int z)
    {
        heightMapBuilder = new Noise2D(w, h, finalTerrain);
        heightMapBuilder.GeneratePlanar(left, right, top, bottom);

        return(heightMapBuilder.GetData());
    }
Beispiel #3
0
    /// <summary>
    /// Gets the height map data.
    /// </summary>
    /// <returns>The height map data.</returns>
    /// <param name="w">The width.</param>
    /// <param name="h">The height.</param>
    public override float[,] GetHeightmapData(int w, int h, int x, int z)
    {
        heightMapBuilder = new LibNoise.Noise2D(w, h, perlinNoiseGenerator);
        heightMapBuilder.GeneratePlanar(left, right, top, bottom);

        return(heightMapBuilder.GetData());
    }
Beispiel #4
0
    private Texture2D texture; // texture created for testing

    #endregion Fields

    #region Methods

    void Generate(bool addToSeed)
    {
        Perlin mySphere = new Perlin();
        mySphere.Seed = seedToModify;
        mySphere.OctaveCount = octaves;
        // modify the frequency
        mySphere.Frequency = frequency;
        // modify the persistence
        mySphere.Persistence = persistence;

        ModuleBase myModule;

        myModule = mySphere;
        mySphere.Lacunarity = 2.5;

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

        // - Generate -

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

        Noise2D heightMap;
        heightMap = new Noise2D( mapSizeX, mapSizeY, myModule );
        heightMap.GenerateSpherical( south, north, west, east );
        texture = heightMap.GetTexture(GradientPresets.Grayscale);
        sphereRenderer.material.mainTexture = texture;

        texture = heightMap.GetTexture(GradientPresets.planetColors);

        sphereRenderer.material.SetTexture("_Normals",heightMap.GetNormalMap(3));
        texture = heightMap.GetTexture(GradientPresets.planetLightColors);
        sphereRenderer.material.SetTexture("_Lights",texture);
    }
    private Texture2D texture; // texture created for testing

    #endregion Fields

    #region Methods

    //  Other Functions
    //    ----------------------------------------------------------------------------
    void Generate(bool addToSeed)
    {
        Perlin mySphere = new Perlin();
        mySphere.Seed = seedToModify;
        mySphere.OctaveCount = octaves;
        // modify the frequency
        mySphere.Frequency = frequency;
        // modify the persistence
        mySphere.Persistence = persistence;
        // ------------------------------------------------------------------------------------------

        // - Compiled Terrain -

        //		Debug.LogError ("Not fetching seed data for planets!");
        ModuleBase myModule;

        myModule = mySphere;

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

        // - Generate -

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

        Noise2D heightMap;
        heightMap = new Noise2D( mapSizeX, mapSizeY, myModule );
        heightMap.GenerateSpherical( south, north, west, east );
        texture = heightMap.GetTexture(GradientPresets.Grayscale);
        sphereRenderer.material.mainTexture = texture;
        //Debug.LogWarning("Removed Generate Planet Clouds to save on load times for now till I optimize it and make it run better.");
    }
	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;
	}
Beispiel #7
0
    public void UpdateTerrainPreview()
    {
        Perlin baseNoise = new Perlin()
        {
            Frequency = _noiseFreq, Lacunarity = _noiseLac, OctaveCount = _noiseOct
        };

        if (_seed != "")
        {
            baseNoise.Seed = Convert.ToInt32(_seed);
        }
        else
        {
            baseNoise.Seed = UnityEngine.Random.Range(int.MinValue, int.MaxValue);
        }


        LibNoise.Noise2D noise2D = new LibNoise.Noise2D(_previewTex.width, baseNoise);

        float mOff = 0.01f;

        noise2D.GeneratePlanar(-1 - _mouseOffset.y * mOff, 1 - _mouseOffset.y * mOff, -1 - _mouseOffset.x * mOff, 1 - _mouseOffset.x * mOff);

        _previewTex = noise2D.GetTexture();
        _terDrawing = new EditorTerrainDrawing(_previewTex);
        _terDrawing.Update();


        _previewTex.Apply();
    }
    private Texture2D texture; // texture created for testing

    #endregion Fields

    #region Methods

    public void Generate()
    {
        Perlin mySphere = new Perlin();
        mySphere.Seed = seedHandler.currentSeed;
        seedModifier = Random.Range(0,2048);
        mySphere.Seed = mySphere.Seed + seedModifier + specialSeedModifier; // modify the seed with the variable declared in the editor (default 0, or no change)

        mySphere.OctaveCount = octaves;
        // modify the frequency
        mySphere.Frequency = frequency;
        // modify the persistence
        mySphere.Persistence = persistence;
        // ------------------------------------------------------------------------------------------

        // - Compiled Terrain -

        Debug.LogError ("Not fetching seed data for planets!");
        ModuleBase myModule;

        myModule = mySphere;

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

        // - Generate -

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

        Noise2D heightMap;

        heightMap = new Noise2D( mapSizeX, mapSizeY, myModule );
        heightMap.GeneratePlanar(
            sampleOffsetX,
            sampleOffsetX + sampleSizeX,
            sampleOffsetY,
            sampleOffsetY + sampleSizeY
            );
        heightMap.GenerateSpherical( south, north, west, east );
        potentialRandomGradiants = Random.Range (0,3);
        if(potentialRandomGradiants == 0){
            texture = heightMap.GetTexture(GradientPresets.nebulaColorsD);

        }
        else if(potentialRandomGradiants == 1){

            texture = heightMap.GetTexture(GradientPresets.nebulaColorsD);
        }
        else if(potentialRandomGradiants == 2){
            texture = heightMap.GetTexture(GradientPresets.nebulaColorsD);

        }
        else {
            texture = heightMap.GetTexture(GradientPresets.nebulaColorsD);

        }
        //nebulaColorsB, C, A, D
        sphereRenderer.material.mainTexture = texture;
    }
	void Start() 
	{
		var perlin = new Perlin();

		var heightMapBuilder = new Noise2D(512, 256, perlin);
		heightMapBuilder.GenerateSpherical(_north, _south, _west, _east);

		var image = heightMapBuilder.GetTexture(_gradient);
		renderer.material.mainTexture = image;



	}
Beispiel #10
0
    void RandomizeTerrainHeights()
    {
        int noiseSeed   = Random.Range(0, int.MaxValue);
        var noiseMap    = new LibNoise.Noise2D(m_TerrainData.heightmapWidth, m_TerrainData.heightmapHeight);
        var noiseModule = new LibNoise.Generator.Perlin();

        // Configure the noise parameters
        noiseModule.OctaveCount = 20;
        noiseModule.Persistence = 0.45f;
        noiseModule.Seed        = noiseSeed;
        noiseMap.Generator      = noiseModule;

        // Generate the noise map
        noiseMap.GeneratePlanar(-1.5f, 1.5, -1.5, 1.5f, true);

        // Get a two-dimensional array of heights from the noise map
        float borderHeight = m_TerrainBorderHeight / m_TerrainData.size.y;

        float[,] heights = noiseMap.GetData();

        // Loop through every "pixel" and set the height to a random value
        for (int x = 0; x < m_TerrainData.heightmapWidth; x++)
        {
            for (int y = 0; y < m_TerrainData.heightmapHeight; y++)
            {
                // Divide the height by 2 so it doesn't flow over the top of the arena
                heights[x, y] /= 2f;

                // Fill in flat areas with random noise
                if (heights[x, y] <= borderHeight &&
                    heights[x, y] >= borderHeight / 2)
                {
                    float newHeight = Random.Range(0f, borderHeight / 2);
                    heights[x, y] = Mathf.Lerp(heights[x, y], newHeight, 0.5f);
                }

                // Update the maxHeight variable if the current height point breaks the previous record
                if (heights[x, y] > m_MaxHeight)
                {
                    m_MaxHeight = heights[x, y];
                }
            }
        }

        // Debug.Log("Max Height: " + m_MaxHeight);

        // Store the result back into terrainData
        m_TerrainData.SetHeights(0, 0, heights);
    }
	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.
		renderer.material.mainTexture = image;

		// We don't do the light changes for the texture, since that's beyond the scope of 
		// this port
	}
Beispiel #12
0
    private Texture2D texture; // texture created for testing

    #endregion Fields

    #region Methods

    public void Generate()
    {
        Perlin mySphere = new Perlin();
        mySphere.Seed = seedHandler.currentSeed;
        seedModifier = Random.Range(0,2048);
        mySphere.Seed = mySphere.Seed + seedModifier + specialSeedModifier; // modify the seed with the variable declared in the editor (default 0, or no change)

        mySphere.OctaveCount = octaves;
        // modify the frequency
        mySphere.Frequency = frequency;
        // modify the persistence
        mySphere.Persistence = persistence;

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

        // - Compiled Terrain -
        ModuleBase myModule;

        myModule = mySphere;

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

        // - Generate -

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

        Noise2D heightMap;

        heightMap = new Noise2D( mapSizeX, mapSizeY, myModule );
        heightMap.GeneratePlanar(
            sampleOffsetX,
            sampleOffsetX + sampleSizeX,
            sampleOffsetY,
            sampleOffsetY + sampleSizeY
            );
        heightMap.GenerateSpherical( south, north, west, east );
        //Somewhere this is f*****g up
        texture = heightMap.GetTexture(GradientPresets.nebulaColorsB);
        sphereRenderer.material.mainTexture = texture;
    }
    //  Other Functions
    //    ----------------------------------------------------------------------------
    void Generate()
    {
        //Perlin mySphere = new Perlin();

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

        // - Compiled Terrain -

        ModuleBase myModule;

        myModule = Generator.LibnoiseModualGen.GetRTSGenerator(1);

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

        // - Generate -

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

        Noise2D heightMap;

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

        heightMap.GenerateSpherical( south, north, west, east );

        texture = heightMap.GetTexture(GradientPresets.Grayscale);

        ///

        #if !UNITY_WEBPLAYER
        byte[] bytes = texture.EncodeToPNG();
        File.WriteAllBytes(Application.dataPath + "/Terain/TextureGenOutput/sphere/"+TextureName+".png", bytes);
        #endif
        ///

        sphereRenderer.material.mainTexture = texture;
    }
Beispiel #14
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);
	    }
    IEnumerator GenerateHeightMap()
    {
        int hresolution = ThisTerain.terrainData.heightmapResolution;
        yield return new WaitForEndOfFrame();
        Noise2D heightMap = new Noise2D(hresolution, hresolution, 
            new Select(0, 1, 1, 
                new ScaleBias(0.125, -1, new Perlin(0.125, 2, 0.5, 4, DataBaseHandler.DataBase.Seed, QualityMode.High)),
                new Select(0, 1, 0.25,
                    new Invert(new ScaleBias(1, riverFullNess, new RidgedMultifractal(riverDensity, 2, 1, DataBaseHandler.DataBase.Seed, QualityMode.High))),
                    new ScaleBias(0.5, islandFullNess, new Perlin(freq, lan, pers, octaves, DataBaseHandler.DataBase.Seed, QualityMode.High)), 
                    new Invert(new ScaleBias(1, riverFullNess, new RidgedMultifractal(riverDensity, 2, 1, DataBaseHandler.DataBase.Seed, QualityMode.High)))), 
                new CircleMask(0.25))
                );
        yield return new WaitForEndOfFrame();

        yield return StartCoroutine(heightMap.GeneratePlanarCoRoutine(-4, 4, -4, 4));

        yield return new WaitForEndOfFrame();

        float[,] hmap = new float[hresolution, hresolution];
        for (int y = 0; y < hresolution; y++)
        {
            for (int x = 0; x < hresolution; x++)
            {
                hmap[x, y] = (((heightMap[x, y]) * 0.5f) + 0.5f);
            }
        }
        ThisTerain.terrainData.SetHeights(0, 0, hmap);
        ThisTerain.Flush();
        int aresolution = ThisTerain.terrainData.alphamapResolution;
        float[, ,] amap = new float[aresolution, aresolution, ThisTerain.terrainData.splatPrototypes.Length];
        List<TreeInstance> trees = new List<TreeInstance>();
        System.Random rnd = new System.Random(DataBaseHandler.DataBase.Seed + 1);
        for (int y = 0; y < aresolution; y++)
        {
            for (int x = 0; x < aresolution; x++)
            {
                if (hmap[(int)(x * ((float)hresolution / (float)aresolution)), (int)(y * ((float)hresolution / (float)aresolution))] < 0.4)
                {
                    amap[x, y, 2] = 1;
                }
                else if (hmap[(int)(x * ((float)hresolution / (float)aresolution)), (int)(y * ((float)hresolution / (float)aresolution))] < 0.7)
                {
                    amap[x, y, 4] = 1;
                    int r = rnd.Next(0, 100);
                    if (r < treeDensity)
                    {
                        GameObject go = (GameObject)GameObject.Instantiate(DataBaseHandler.DataBase.Foliage[0]);
                        go.transform.position = new Vector3(y * 2, ThisTerain.terrainData.GetHeight(y, x), x * 2);
                        go.transform.parent = this.transform;
                        
                    }
                }
                else if (hmap[(int)(x * ((float)hresolution / (float)aresolution)), (int)(y * ((float)hresolution / (float)aresolution))] < 0.8)
                {
                    amap[x, y, 8] = 1;
                }
                else
                {
                    amap[x, y, 0] = 1;
                }
            }
        }
        yield return new WaitForEndOfFrame();

        ThisTerain.terrainData.SetAlphamaps(0, 0, amap);


        ThisTerain.Flush();
    }
Beispiel #16
0
    void GenerateRainShadow()
    {
        RainShadow = new float[ThisTerain.terrainData.alphamapResolution, ThisTerain.terrainData.alphamapResolution];

        Noise2D RainCalcMap = new Noise2D((DataBaseHandler.BiomeMapSize + (MaxWindSpeed * 2)), (DataBaseHandler.BiomeMapSize + (MaxWindSpeed * 2)), new Perlin(0.125, 2, 0.5, 10, DataBaseHandler.DataBase.Seed, QualityMode.High));
        RainCalcMap.GeneratePlanar(xOffset - ((double)MaxWindSpeed / (double)DataBaseHandler.BiomeMapSize), (xOffset + 1) + ((double)MaxWindSpeed / (double)DataBaseHandler.BiomeMapSize), yOffset - ((double)MaxWindSpeed / (double)DataBaseHandler.BiomeMapSize), (yOffset + 1) + ((double)MaxWindSpeed / (double)DataBaseHandler.BiomeMapSize));

        for (int i = -MaxWindSpeed; i < RainCalcMap.Width - MaxWindSpeed; i++)
        {
            for (int j = -MaxWindSpeed; j < RainCalcMap.Height - MaxWindSpeed; j++)
            {
                if (RainCalcMap[i + MaxWindSpeed, j + MaxWindSpeed] <= 0.5f)
                {
                    Bresenham(i, i + (int)(WindDirection[j + MaxWindSpeed, i + MaxWindSpeed].x * MaxWindSpeed), j, j + (int)(WindDirection[j + MaxWindSpeed, i + MaxWindSpeed].y * MaxWindSpeed));
                }
            }
        }
    }
Beispiel #17
0
    void GenerateBiomes()
    {
        int resolution = ThisTerain.terrainData.alphamapResolution;

        Noise2D heightMap = new Noise2D(resolution, resolution, new Perlin(0.125, 2, 0.5, 10, DataBaseHandler.DataBase.Seed, QualityMode.High));
        heightMap.GeneratePlanar(yOffset, yOffset + 1.0f, xOffset, xOffset + 1.0f);

        Noise2D rainfall = new Noise2D(resolution, resolution, new Perlin(0.125, 2, 0.5, 10, DataBaseHandler.DataBase.Seed, QualityMode.High));
        rainfall.GeneratePlanar(yOffset, yOffset + 1.0f, xOffset, xOffset + 1.0f);

        Humidity = new float[ThisTerain.terrainData.alphamapResolution, ThisTerain.terrainData.alphamapResolution];
        biomes = new BiomeTypes[ThisTerain.terrainData.alphamapResolution, ThisTerain.terrainData.alphamapResolution];
        Temperature = new float[ThisTerain.terrainData.alphamapResolution, ThisTerain.terrainData.alphamapResolution];

        for (int i = 0; i < ThisTerain.terrainData.alphamapResolution; i++)
        {
            for (int j = 0; j < ThisTerain.terrainData.alphamapResolution; j++)
            {
                Temperature[i, j] = -50.0f + (((((heightMap[i, j] * 0.5f) + 0.5f) + (CosGradient(i + (yOffset * (float)(resolution)), (float)(resolution), 0.25f) * 0.5f) + 0.5f) / 2.0f) * 100.0f);
                Humidity[i, j] = ((((CosGradient(i + (yOffset * (float)(resolution)), (float)(resolution), 0.25f) * 0.5f) + 0.5f)) * 100.0f) * (((rainfall[i, j] * 0.5f) + 0.5f));
                //Humidity[i, j] = ((((rainfall[i, j] * 0.5f) + 0.5f)) * 100.0f);// *(((((heightMap[i, j] * 0.75f) + 0.5f) + (CosGradient(i + (yOffset * (float)(resolution)), (float)(resolution), 0.5f) * 0.25f) + 0.5f) / 2.0f));
                //Old Biome Selector
                //biomes[i, j] = DataBaseHandler.DataBase.BiomeDiagram[Mathf.RoundToInt((((heightMap[i, j] * 0.5f) + 0.5f) + (CosGradient(i + (yOffset * (float)(resolution)), (float)(resolution), 0.5f) * 0.5f) + 0.5f) / 2), Mathf.RoundToInt((RainShadow[i, j] + ((rainfall[i, j] * 0.5f) + 0.5f) / 2) * 2)];
                biomes[i, j] = Biome.DecideBiome(Temperature[i, j], Humidity[i, j]);
                if (!availblebiomes.Contains(biomes[i, j]))
                {
                    availblebiomes.Add(biomes[i, j]);
                }
            } //tmpNoiseMap.GeneratePlanar(xoffset, (xoffset) + (1f / resolution) * (resolution + 1), -yoffset, (-yoffset) + (1f / resolution) * (resolution + 1));

		}
    }
    void Start()
    {
        // defines noise type
        NoiseSelector();

        // setup terrain data
        TerrainData terrain = Terrain.activeTerrain.terrainData;
        int hmArea = terrain.heightmapWidth;
        float[,] heightmapData = terrain.GetHeights(0, 0, hmArea, hmArea);

        // create the noise map
        Noise2D noiseMap = new Noise2D(maxArea, maxArea, generate);
        noiseMap.GeneratePlanar(0, maxArea, 0, maxArea);

        // send noise to texture
        Texture2D textMap = noiseMap.GetTexture(_gradient);

        // texture data to heightmap
        for (int y = 0; y < hmArea; y++)
        {
            for (int x = 0; x < hmArea; x++)
            {
                heightmapData[y, x] = textMap.GetPixel(x, y).grayscale;
            }
        }

        // set terrain heights from heightmap data
        terrain.SetHeights(0, 0, heightmapData);
    }
Beispiel #19
0
    void GenerateHeightmap(BiomeTypes[,] biomes)
    {
        int resolution = ThisTerain.terrainData.heightmapResolution;
        Heightmap = new float[resolution, resolution];
        List <LibNoise.ModuleBase> modules = new List<ModuleBase>();
        for (int i = 0; i < availblebiomes.Count; i++)
        {
            if (!modules.Contains(Biome.FindBiome(availblebiomes[i]).Generate(noisehelper)))
            {
                modules.Add(Biome.FindBiome(availblebiomes[i]).Generate(noisehelper));
            }
        }
        
        for (int i = 1; i < modules.Count; i++)
        {
            if (modules[i] != null)
            {
                modules[i][0] = modules[i - 1];
            }
        }
        Noise2D heightMap = new Noise2D(resolution, resolution, modules[0]);
        heightMap.GeneratePlanar(yOffset, yOffset + 1.0f, xOffset, xOffset + 1.0f);

        for (int y = 0; y < resolution; y++)
        {
            for (int x = 0; x < resolution; x++)
            {
                Heightmap[x, y] = (((heightMap[x, y]) * 0.5f) + 0.5f);// (float)((FlatNoiseMap[x, y] * 0.5f) + 0.5f);
            }
        }

        ThisTerain.terrainData.SetHeights(0, 0, Heightmap);
        ThisTerain.Flush();
    }
Beispiel #20
0
    public static void genNoise(int channelId)
    {
        moduleBase[channelId] = new Perlin();
        if (teNoiseChanTypeIndex[channelId] == 1)
        {
            int tIdx = teNoiseTypeIndex[channelId];
            if (tIdx == 0) { moduleBase[channelId] = new Perlin(frequency[channelId], lacunarity[channelId], persistance[channelId], octaves[channelId], seed[channelId], QualityMode.High); }
            if (tIdx == 1) { moduleBase[channelId] = new Billow(frequency[channelId], lacunarity[channelId], persistance[channelId], octaves[channelId], seed[channelId], QualityMode.High); }
            if (tIdx == 2) { moduleBase[channelId] = new RidgedMultifractal(frequency[channelId], lacunarity[channelId], octaves[channelId], seed[channelId], QualityMode.High); }
            if (tIdx == 3) { moduleBase[channelId] = new Voronoi(frequency[channelId], displacement[channelId], seed[channelId], distance[channelId]); }
            if (tIdx == 4) { moduleBase[channelId] = new BrownianMotion(frequency[channelId], lacunarity[channelId], octaves[channelId], seed[channelId], QualityMode.High); }
            if (tIdx == 5) { moduleBase[channelId] = new HeterogeneousMultiFractal(frequency[channelId], lacunarity[channelId], octaves[channelId], persistance[channelId], seed[channelId], offset[channelId], QualityMode.High); }
            if (tIdx == 6) { moduleBase[channelId] = new HybridMulti(frequency[channelId], lacunarity[channelId], octaves[channelId], persistance[channelId], seed[channelId], offset[channelId], gain[channelId], QualityMode.High); }
            if (tIdx == 7) { moduleBase[channelId] = new LinearGradientNoise(frequency[channelId]); }
        }
        if (teNoiseChanTypeIndex[channelId] == 2)
        {
            int fIdx = teFunctionTypeIndex[channelId];
            if (fIdx == 0) { moduleBase[channelId] = new Add(moduleBase[srcChannel1Id[channelId]], moduleBase[srcChannel2Id[channelId]]); }
            if (fIdx == 1) { moduleBase[channelId] = new Subtract(moduleBase[srcChannel1Id[channelId]], moduleBase[srcChannel2Id[channelId]]); }
            if (fIdx == 2) { moduleBase[channelId] = new Multiply(moduleBase[srcChannel1Id[channelId]], moduleBase[srcChannel2Id[channelId]]); }
            if (fIdx == 3) { moduleBase[channelId] = new Min(moduleBase[srcChannel1Id[channelId]], moduleBase[srcChannel2Id[channelId]]); }
            if (fIdx == 4) { moduleBase[channelId] = new Max(moduleBase[srcChannel1Id[channelId]], moduleBase[srcChannel2Id[channelId]]); }
            if (fIdx == 5) { moduleBase[channelId] = new Blend(moduleBase[srcChannel1Id[channelId]], moduleBase[srcChannel2Id[channelId]], moduleBase[srcChannel3Id[channelId]]); }
            if (fIdx == 6) { moduleBase[channelId] = new Clamp((double)noiseFuncMin[channelId], (double)noiseFuncMax[channelId], moduleBase[srcChannel1Id[channelId]]); }
			if (fIdx == 7) { moduleBase[channelId] = new Power(moduleBase[srcChannel1Id[channelId]],moduleBase[srcChannel2Id[channelId]]);}
			if (fIdx == 8) { Curve tmpCurve = new Curve(moduleBase[srcChannel1Id[channelId]]);
				double adjust = double.Parse((controlpointcount[channelId]-1).ToString())*0.5;
				for(int i=0;i<controlpointcount[channelId];i++){
					tmpCurve.Add(double.Parse(i.ToString())-adjust,(double)cpval[channelId,i]);
					moduleBase[channelId] = tmpCurve;
				}
			}
			if(fIdx==9){Terrace tmpTerrace = new Terrace(invertTerrace[channelId],moduleBase[srcChannel1Id[channelId]]);
				for(int i=0;i<controlpointcount[channelId];i++){
					tmpTerrace.Add((double)cpval[channelId,i]-0.5);
					moduleBase[channelId] = tmpTerrace;
				}
			}
            if (fIdx == 18) { moduleBase[channelId] = new Mask(moduleBase[srcChannel1Id[channelId]], (double)noiseFuncMin[channelId], (double)noiseFuncMax[channelId]); }
            if (fIdx == 17) { moduleBase[channelId] = new WindexWarp(moduleBase[srcChannel1Id[channelId]]); }
			if (fIdx == 16) { moduleBase[channelId] = new TEWarp(moduleBase[srcChannel1Id[channelId]]); }
            if (fIdx == 15) { moduleBase[channelId] = new Select((double)noiseFuncMin[channelId], (double)noiseFuncMax[channelId], falloff[channelId], moduleBase[srcChannel1Id[channelId]], moduleBase[srcChannel2Id[channelId]], moduleBase[srcChannel3Id[channelId]]); }
			if (fIdx == 14) { moduleBase[channelId] = new Turbulence(power[channelId],moduleBase[srcChannel1Id[channelId]]); }
			if (fIdx == 13) { moduleBase[channelId] = new ScaleBias(scale[channelId],bias[channelId],moduleBase[srcChannel1Id[channelId]]); }
			if (fIdx == 12) { moduleBase[channelId] = new Invert(moduleBase[srcChannel1Id[channelId]]);}
			if (fIdx == 11) { moduleBase[channelId] = new Exponent(exponent[channelId],moduleBase[srcChannel1Id[channelId]]); }
			if (fIdx == 10) { moduleBase[channelId] = new Abs(moduleBase[srcChannel1Id[channelId]]);}
		}
        int resolution = 64;
        int xoffset = 0; int yoffset = 0;
        m_noiseMap[channelId] = new Noise2D(resolution, resolution, moduleBase[channelId]);
        float x1 = xoffset * zoom[channelId];
        float x2 = (xoffset * zoom[channelId]) + ((zoom[channelId] / resolution) * (resolution + 1));
        float y1 = -yoffset * zoom[channelId];
        float y2 = (-yoffset * zoom[channelId]) + ((zoom[channelId] / resolution) * (resolution + 1));
        m_noiseMap[channelId].GeneratePlanar(x1, x2, y1, y2);
        m_textures[channelId] = m_noiseMap[channelId].GetTexture();
        m_textures[channelId].Apply();
    }
Beispiel #21
0
	public override void sceneEvents(SceneView sceneview){
		if(teNoisePaint==false){return;}
		if(Event.current.type==EventType.MouseDown){
			Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
			RaycastHit hit = new RaycastHit();
			if(Physics.Raycast(ray, out hit, 7000.0f)){
				GameObject go = hit.collider.gameObject;
				TerrainData td = go.GetComponent<Terrain>().terrainData;
				Undo.RegisterUndo(td,"Paste Noise");
				int x = (int)hit.point.x - (int)go.transform.position.x;
				int z = (int)hit.point.z - (int)go.transform.position.z;
				int heightres = td.heightmapResolution;
				float heightMult = (1.0f / td.size.x)*(float)heightres;
				int heiX = ((int)(heightMult*(float)x))+heightres; //x:z coords for other map resolutions
				int heiZ = ((int)(heightMult*(float)z))+heightres;
				Event.current.Use();
				heights = TerrainEdge.getNeighborhoodHeights(go);
				float strengthmult =1.0f;
				int channelId = teNoiseChanIndex;
				Vector3 gopos = go.transform.position;
		        float cwidth = go.GetComponent<Terrain>().terrainData.size.x;
		        yoffset = (1f) - (gopos.x / cwidth);
		        xoffset = (-1f) + (gopos.z / cwidth);
		        tmpNoiseMap = new Noise2D(heightres*3, heightres*3, moduleBase[channelId]);
		        tmpNoiseMap.GeneratePlanar(xoffset, xoffset + (1f / heightres) * (heightres*3) + 3, -yoffset, -yoffset + (1f / heightres) * (heightres*3) + 3);
		        tmpTexture = tmpNoiseMap.GetTexture();
		        tmpTexture.Apply();
	        	int pasteregionoffset = (int)((float)teNoiseBrushSize);
				for(int paintZ=(heiZ)-pasteregionoffset;paintZ<(heiZ)+(pasteregionoffset+1);paintZ++){
					for(int paintX=(heiX)-pasteregionoffset;paintX<(heiX)+(pasteregionoffset+1);paintX++){
						if(paintZ>=0&&paintZ<=(heightres*3)-2&&paintX>=0&&paintX<=(heightres*3)-2){
							strengthmult = falloffMult(paintX,heiX,paintZ,heiZ,pasteregionoffset);
							float tmpval = (tmpNoiseMap[paintZ, paintX] + 0.5f) * noiseAmp;
							if(heights[paintZ,paintX]>tmpval){ 
								heights[paintZ,paintX]-=(heights[paintZ,paintX]-tmpval) * strengthmult;
							} else {
								heights[paintZ,paintX]+=(tmpval-heights[paintZ,paintX]) * strengthmult;
							}
						}
					}
				}
				TerrainEdge.setNeighborhoodHeights(go,heights);
			}
		}
	}
Beispiel #22
0
    void GenerateWind()
    {
        Noise2D WindMap = new Noise2D((DataBaseHandler.BiomeMapSize + (MaxWindSpeed * 2)), (DataBaseHandler.BiomeMapSize + (MaxWindSpeed * 2)), new Perlin(0.125, 2, 0.5, 10, DataBaseHandler.DataBase.Seed, QualityMode.High));
        WindMap.GeneratePlanar(yOffset - ((double)MaxWindSpeed / (double)DataBaseHandler.BiomeMapSize), (yOffset + 1) + ((double)MaxWindSpeed / (double)DataBaseHandler.BiomeMapSize), xOffset - ((double)MaxWindSpeed / (double)DataBaseHandler.BiomeMapSize), (xOffset + 1) + ((double)MaxWindSpeed / (double)DataBaseHandler.BiomeMapSize));

        WindDirection = new Vector2[(DataBaseHandler.BiomeMapSize + (MaxWindSpeed * 2)), (DataBaseHandler.BiomeMapSize + (MaxWindSpeed * 2))];
        for (int i = 0; i < DataBaseHandler.BiomeMapSize + (MaxWindSpeed * 2); i++)
        {
            for (int j = 0; j < DataBaseHandler.BiomeMapSize + (MaxWindSpeed * 2); j++)
            {
                float val = ((((CosGradient((i - 50) + (yOffset * (float)(DataBaseHandler.BiomeMapSize)), (float)(DataBaseHandler.BiomeMapSize), 0.125f) * 0.5f) + 0.5f) + (((WindMap[i, j]) * 0.5f) + 0.5f) / 2) * 12.0f);
                if (val >= 0 && val < 2)
                {
                    if (val >= 1)
                    {
                        WindDirection[i, j] = new Vector2(-1.0f, (val - 2.0f));
                    }
                    else
                    {
                        WindDirection[i, j] = new Vector2(val * -1.0f, -1.0f);
                    }
                }
                else if (val >= 2 && val < 4)
                {
                    if (val >= 3)
                    {
                        WindDirection[i, j] = new Vector2((4.0f - val), 1.0f);
                    }
                    else
                    {
                        WindDirection[i, j] = new Vector2(1.0f, val - 2.0f);
                    }
                }
                else if (val >= 4 && val < 6)
                {
                    if (val >= 5)
                    {
                        WindDirection[i, j] = new Vector2(-1.0f, (val - 6.0f));
                    }
                    else
                    {
                        WindDirection[i, j] = new Vector2((val - 4.0f) * -1.0f, -1.0f);
                    }
                }
                else if (val >= 6 && val < 8)
                {
                    if (val >= 7)
                    {
                        WindDirection[i, j] = new Vector2(val - 8.0f, 1.0f);
                    }
                    else
                    {
                        WindDirection[i, j] = new Vector2(-1.0f, (val - 6.0f));
                    }
                }
                else if (val >= 8 && val < 10)
                {
                    if (val >= 9)
                    {
                        WindDirection[i, j] = new Vector2(1.0f, (10.0f - val) * -1.0f);
                    }
                    else
                    {
                        WindDirection[i, j] = new Vector2((val - 8.0f), -1.0f);
                    }
                }
                else if (val >= 10 && val <= 12)
                {
                    if (val >= 11)
                    {
                        WindDirection[i, j] = new Vector2((val - 12.0f), 1.0f);
                    }
                    else
                    {
                        WindDirection[i, j] = new Vector2(-1.0f, (val - 10.0f));
                    }
                }
            }
        }
    }
        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();
                }
            }
        }
Beispiel #24
0
	public void Generate ()
	{	
		// Create the module network
		ModuleBase moduleBase;
		switch (noise) {
		case NoiseType.Billow:	
			moduleBase = new Billow ();
			break;
            	
		case NoiseType.RidgedMultifractal:	
			moduleBase = new RidgedMultifractal ();
			break;   
            	
		case NoiseType.Voronoi:	
            	// moduleBase = new Voronoi();
			seed = UnityEngine.Random.Range (0, 100);
			moduleBase = new Voronoi (frequency, displacement, seed, false);
			
			break;             	         	
            	
		case NoiseType.Mix:            	
			Perlin perlin = new Perlin ();
			var rigged = new RidgedMultifractal ();
			moduleBase = new Add (perlin, rigged);
			break;
			
		case NoiseType.Practice:
			var bill = new Billow ();
			bill.Frequency = frequency;
			moduleBase = new Turbulence (turbulence / 10, bill);

			
			break;
			
			
            	
		default:
			var defPerlin = new Perlin ();
			defPerlin.OctaveCount = perlinOctaves;
			moduleBase = defPerlin;
			
			break;
            	
		}
		
		// Initialize the noise map
		this.m_noiseMap = new Noise2D (resolution, resolution, moduleBase);
		this.m_noiseMap.GeneratePlanar (
			offset + -1 * 1 / zoom, 
			offset + offset + 1 * 1 / zoom, 
			offset + -1 * 1 / zoom,
			offset + 1 * 1 / zoom, true);
		
		// Generate the textures
		this.m_textures [0] = this.m_noiseMap.GetTexture (GradientPresets.Grayscale);
		this.m_textures [0].Apply ();
            
		this.m_textures [1] = this.m_noiseMap.GetTexture (GradientPresets.Terrain);
		this.m_textures [1].Apply ();
             
		this.m_textures [2] = this.m_noiseMap.GetNormalMap (3.0f);
		this.m_textures [2].Apply ();
        		
		//display on plane
		renderer.material.mainTexture = this.m_textures [0];
            

		//write images to disk
		File.WriteAllBytes (Application.dataPath + "/../Gray.png", m_textures [0].EncodeToPNG ());
		File.WriteAllBytes (Application.dataPath + "/../Terrain.png", m_textures [1].EncodeToPNG ());
		File.WriteAllBytes (Application.dataPath + "/../Normal.png", m_textures [2].EncodeToPNG ());

		Debug.Log ("Wrote Textures out to " + Application.dataPath + "/../");
            
        
	}