TextureFromHeightMap() public static method

public static TextureFromHeightMap ( float heightMap ) : Texture2D
heightMap float
return UnityEngine.Texture2D
Esempio n. 1
0
    public void DrawMapInEditor()
    {
        textureData.ApplyToMaterial(terrainMaterial);
        textureData.UpdateMeshHeights(terrainMaterial, heightMapSettings.minHeight, heightMapSettings.maxHeight);

        HeightMap heightMap = HeightMapGenerator.Generate(meshSettings.numVertsPerLine, meshSettings.numVertsPerLine, heightMapSettings, Vector2.zero);

        switch (drawMode)
        {
        case DrawMode.NoiseMap:
            DrawTexture(TextureGenerator.TextureFromHeightMap(heightMap));
            break;

        case DrawMode.Mesh:
            DrawMesh(MeshGenerator.GenerateTerrainMesh(heightMap.values, meshSettings, editorPreviewLOD));
            break;

        case DrawMode.Falloff:
            DrawTexture(TextureGenerator.TextureFromHeightMap(
                            new HeightMap(FalloffGenerator.GenerateFalloffMap(meshSettings.numVertsPerLine), 0, 1)));
            break;

        default:
            break;
        }
    }
Esempio n. 2
0
    public void DrawMapInEditor()
    {
        textureData.ApplyToMaterial(terrainMaterial);
        textureData.UpdateMeshHeights(terrainMaterial,
                                      heightMapSettings.minHeight, heightMapSettings.maxHeight);

        HeightMap heightMap = HeightMapGenerator.GenerateHeightMap(
            meshSettings.numVerticesPerLine,
            meshSettings.numVerticesPerLine,
            heightMapSettings,
            Vector2.zero
            );

        if (drawMode == DrawMode.NoiseMap)
        {
            DrawTexture(TextureGenerator.TextureFromHeightMap(heightMap));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            DrawMesh(MeshGenerator.GenerateTerrainMesh(
                         heightMap.values,
                         editorPreviewLOD,
                         meshSettings
                         )
                     );
        }
        else
        {
            float[,] values = FalloffGenerator.GenerateFalloffMap(meshSettings.numVerticesPerLine);
            DrawTexture(TextureGenerator.TextureFromHeightMap(new HeightMap(values, 0, 1)));
        }
    }
Esempio n. 3
0
    public void GenerateMap()
    {
        float[,] noiseMap = Noise.GenerateNoiseMap(mapSize, mapSize, scale, octaves, persistance, lacunarity, offsetSeed, offset);
        Color[] colorMap = new Color[mapSize * mapSize];
        for (int y = 0; y < mapSize; y++)
        {
            for (int x = 0; x < mapSize; x++)
            {
                float currentHeight = noiseMap[x, y];
                for (int i = 0; i < regions.Length; i++)
                {
                    if (currentHeight <= regions[i].mapHeight)
                    {
                        colorMap[y * mapSize + x] = regions[i].mapColor;
                        break;
                    }
                }
            }
        }
        MapDisplay display = FindObjectOfType <MapDisplay>();

        if (drawMode == DrawMode.NoiseMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(noiseMap));
        }
        else if (drawMode == DrawMode.ColorMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromColorMap(colorMap, mapSize, mapSize));
        }
        else if (drawMode == DrawMode.MeshMap)
        {
            display.DrawMesh(MeshGenerator.GenerateterrainMesh(noiseMap, meshHeight, heightCurve, levelofDetail), TextureGenerator.TextureFromColorMap(colorMap, mapSize, mapSize));
        }
    }
    void UpdatePreview()
    {
        FalloffGenerator generator = (FalloffGenerator)target;

        float[,] noiseMap = generator.Generate(120, 120);
        texture           = TextureGenerator.TextureFromHeightMap(noiseMap);
    }
Esempio n. 5
0
    public void drawTexture()
    {
        switch (this.selectedDrawMode)
        {
        case DrawMode.RoadMap:
            colorSet[0] = Color.black;
            colorSet[1] = Color.red;
            break;

        case DrawMode.RZone:
            colorSet[0] = Color.green;
            colorSet[1] = Color.red;
            break;

        case DrawMode.CZone:
            colorSet[0] = Color.blue;
            colorSet[1] = Color.red;
            break;

        case DrawMode.IZone:
            colorSet[0] = Color.yellow;
            colorSet[1] = Color.red;
            break;

        default:
            colorSet[0] = Color.green;
            colorSet[1] = Color.red;
            break;
        }
        if (map != null)
        {
            Texture2D tex = TextureGenerator.TextureFromHeightMap(map[(int)SelectedDrawMode], colorSet);
            GetComponent <MeshRenderer>().sharedMaterial.mainTexture = tex;
        }
    }
Esempio n. 6
0
    public void DrawMapInEditor()
    {
        textureData.ApplyToMaterial(terrainMaterial);
        textureData.UpdateMeshHeights(terrainMaterial, heightMapSettings.minHeight, heightMapSettings.maxHeight);
        HeightMap heightMap = HeightMapGenerator.GenerateHeightMap(meshSettings.numVertsPerLine, meshSettings.numVertsPerLine, heightMapSettings, Vector2.zero);
        HeatMap   heatMap   = HeatMapGenerator.GenerateHeatMap(meshSettings.numVertsPerLine, meshSettings.numVertsPerLine, heightMap, heatMapSettings, Vector2.zero);
        TreeMap   treeMap   = TreeMapGenerator.generateVegetationMap(meshSettings.numVertsPerLine, meshSettings.numVertsPerLine, heightMap, heatMap, treeMapSettings, Vector2.zero);

        DestroyTrees();          //temporary fix

        if (drawMode == DrawMode.HeightMap)
        {
            DrawTexture(TextureGenerator.TextureFromHeightMap(heightMap));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            DrawMesh(MeshGenerator.GenerateTerrainMesh2(heightMap.values, meshSettings, editorPreviewLOD, heatMap.values));
            DrawTrees(heightMap.values, meshSettings, treeMap.values);
        }
        else if (drawMode == DrawMode.FalloffMap)
        {
            DrawTexture(TextureGenerator.TextureFromHeightMap(new HeightMap(FalloffGenerator.GenerateFalloffMap(meshSettings.numVertsPerLine), 0, 1)));
        }
        else if (drawMode == DrawMode.HeatMap)
        {
            DrawTexture(TextureGenerator.TextureColorizedFromHeatMap(heatMap));
        }
        else if (drawMode == DrawMode.TreeMap)
        {
            DrawTexture(TextureGenerator.TextureFromTreeMap(treeMap));
        }
    }
Esempio n. 7
0
    public void DrawMap()
    {
        var display = GetComponent <MapDisplay>();

        var noiseMap = Noise.GenerateNoiseMap(meshSize, meshSize, seed, scale, octaves, amplitude, frequency, offsets);

        if (useFalloff)
        {
            var falloffData = FalloffGenerator.GenerateFalloffMap(meshSize);
            for (int y = 0; y < meshSize; y++)
            {
                for (int x = 0; x < meshSize; x++)
                {
                    noiseMap[x, y] = Mathf.Clamp01(noiseMap[x, y] - falloffData[x, y]);
                }
            }
        }

        switch (drawMode)
        {
        case DrawMode.NoiseMap:
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(noiseMap, layers));
            break;

        case DrawMode.Mesh:
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(noiseMap, layers));
            display.DrawMesh(MeshGenerator.GenerateTerrianMesh(noiseMap, meshHeightMulti, lod, heightAdjuestCurve));
            break;

        case DrawMode.FalloffMap:
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(FalloffGenerator.GenerateFalloffMap(meshSize), layers));
            break;
        }
    }
Esempio n. 8
0
    // Draw noisemap to the plane
    void DrawNoiseToPlane()
    {
        GPUNoiseGenerator.NoiseData noiseData = new GPUNoiseGenerator.NoiseData {
            frequency      = frequency,
            octaves        = octaves,
            side           = side,
            quarter        = quarter,
            persistence    = persistance,
            lacunarity     = lacunarity,
            maxNoiseHeight = maxNoiseHeight,
            amplitude      = amplitude,
            resolution     = noiseResolution
        };

        heightMap = Noise.GenerateNoiseMap(seed, offset, noiseData, noiseScale, noiseSource, gridSize, zoom, noisePerformanceTestLoopTimes, radius);

        if (!useRenderTextureForDrawingTexture)
        {
            Texture2D noiseTexture = TextureGenerator.TextureFromHeightMap(heightMap);
            planeRenderer.material.mainTexture = noiseTexture;
        }
        else
        {
            rt = GPUNoiseGenerator.GenerateNoise(seed, noiseData, radius);
            planeRenderer.material.mainTexture = rt;
        }
    }
Esempio n. 9
0
    public void GenerateMap()
    {
        //float[,] noiseMap = Noise.
        float[,] noiseMap = Noise.GenerateNoiseMap(MapWidht, MapHeight, Seed, NoiseScale, Octaves, Persistance, Lacunarity, Offset);

        //Loop through the noiseMap, get the height and if the Region has that certain height then print the color
        Color[] colourMap = new Color[MapWidht * MapHeight];
        for (int y = 0; y < MapHeight; y++)
        {
            for (int x = 0; x < MapWidht; x++)
            {
                float currentHeight = noiseMap[x, y];

                for (int i = 0; i < Regions.Length; i++)
                {
                    if (currentHeight <= Regions[i].Height)
                    {
                        colourMap[y * MapWidht + x] = Regions[i].Color;
                        break;
                    }
                }
            }
        }

        MapDisplay display = FindObjectOfType <MapDisplay>();

        if (drawMode == DrawMode.NoiseMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(noiseMap));
        }
        else if (drawMode == DrawMode.ColorMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromColourMap(colourMap, MapWidht, MapHeight));
        }
    }
Esempio n. 10
0
    public void DrawMapInEditor()
    {
        textureData.ApplyToMaterial(terrainMaterial);
        textureData.UpdateMeshHeights(terrainMaterial, heightMapSettings.MinHeight, heightMapSettings.MaxHeight);
        HeightMap heightMap = HeightMapGenerator.GenerateHeightMap(meshSettings.NumberOfVerticesPerLine,
                                                                   meshSettings.NumberOfVerticesPerLine, heightMapSettings, Vector2.zero);

        switch (drawMode)
        {
        case DrawMode.NoiseMap:
            DrawTexture(TextureGenerator.TextureFromHeightMap(heightMap));
            break;

        case DrawMode.Mesh:
            DrawMesh(
                MeshGenerator.GenerateTerrainMesh(heightMap.values, meshSettings, editorPreviewLevelOfDetail));
            break;

        case DrawMode.FallofMap:
            DrawTexture(
                TextureGenerator.TextureFromHeightMap(
                    new HeightMap(FallofGenerator.GenerateFallofMap(meshSettings.NumberOfVerticesPerLine), 0, 1)));
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }
    }
Esempio n. 11
0
    public void GenerateMap()
    {
        float[,] noiseMap = PerlinNoise.GenerateNoise(mapChankSize, seed, Scale, octaves, persistance, lacunarity, offset);
        Color[] colorMap = new Color[mapChankSize * mapChankSize];
        for (int y = 0; y < mapChankSize; y++)
        {
            for (int x = 0; x < mapChankSize; x++)
            {
                float currentHeight = noiseMap[x, y];
                for (int i = 0; i < Regions.Length; i++)
                {
                    if (currentHeight <= Regions[i].height)
                    {
                        colorMap[y * mapChankSize + x] = Regions[i].color;
                        break;
                    }
                }
            }
        }
        MapDisplay mapDisplay = FindObjectOfType <MapDisplay>();

        if (drawMode == DrawMode.PerlinNoise)
        {
            mapDisplay.DrawTexture(TextureGenerator.TextureFromHeightMap(noiseMap));
        }
        else if (drawMode == DrawMode.ColorMap)
        {
            mapDisplay.DrawTexture(TextureGenerator.TextureFromColorMap(colorMap, mapChankSize));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            mapDisplay.DrawMesh(MeshGeneration.GenerareTerrainMesh(noiseMap, heightMultipler, curve), TextureGenerator.TextureFromColorMap(colorMap, mapChankSize), !GenerationAllTime);
        }
    }
Esempio n. 12
0
    public void DrawMapInEditor()
    {
        MapData mapData = GenerateMap(Vector2.zero);

        MapDisplay display = FindObjectOfType <MapDisplay>();

        planeObj = GameObject.Find("Plane");
        meshObj  = GameObject.Find("Mesh");
        if (drawMode == DrawMode.NoiseMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(mapData.heightMap));
            planeObj.transform.position = new Vector3(0, 1, 0);
            meshObj.transform.position  = new Vector3(0, -200, 0);
        }
        else if (drawMode == DrawMode.ColourMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromColourMap(mapData.colourMap, mapChunkSize, mapChunkSize));
            planeObj.transform.position = new Vector3(0, 1, 0);
            meshObj.transform.position  = new Vector3(0, -200, 0);
        }
        else if (drawMode == DrawMode.Mesh)
        {
            display.DrawMesh(MeshGenerator.GenerateTerrainMesh(mapData.heightMap, meshHeightMultiplier, meshHeightCurve, levelOfDetail), TextureGenerator.TextureFromColourMap(mapData.colourMap, mapChunkSize, mapChunkSize));
            planeObj.transform.position = new Vector3(0, -200, 0);
            meshObj.transform.position  = new Vector3(0, 1, 0);
        }
        else if (drawMode == DrawMode.FallOfMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(FallOffGenerator.GenerateFallOffMap(mapChunkSize)));
        }
    }
Esempio n. 13
0
    public void DrawMapInEditor()
    {
        MapData mapData = GenerateMapData(Vector2.zero);

        //Referencing the MapDisplay method
        MapDisplay display = FindObjectOfType <MapDisplay>();

        //Saying which drawMode we are in and whether to draw the colours or not
        if (drawMode == DrawMode.NoiseMap)
        {
            //Displaying the noise map
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(mapData.heightMap));
        }
        else if (drawMode == DrawMode.ColourMap)
        {
            //Displaying the colour map
            display.DrawTexture(TextureGenerator.TextureFromColourMap(mapData.colourMap, mapChunkSize, mapChunkSize));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            //Displaying the mesh map
            display.DrawMesh(MeshGenerator.GenerateTerrainMesh(mapData.heightMap, meshHeightMultiplier, meshHeightCurve, editorPreviewLOD), TextureGenerator.TextureFromColourMap(mapData.colourMap, mapChunkSize, mapChunkSize));
        }
        else if (drawMode == DrawMode.FallOffMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(FallOffGenerator.GenerateFalloffMap(mapChunkSize)));
        }
    }
Esempio n. 14
0
    void GenerateTerrain()
    {
        float[,] noiseMap = Noise.GenerateNoiseMap(mapChunkSize, mapChunkSize, seed, noiseScale, octaves, persistance, lacunarity, offset);

        Color[] colorMap = new Color[mapChunkSize * mapChunkSize];
        for (int y = 0; y < mapChunkSize; y++)
        {
            for (int x = 0; x < mapChunkSize; x++)
            {
                float currentHeight = noiseMap[x, y];
                for (int i = 0; i < regions.Length; i++)
                {
                    if (currentHeight <= regions[i].height)
                    {
                        colorMap[y * mapChunkSize + x] = regions[i].color;
                        break;
                    }
                }
            }
        }

        if (drawMode == DrawMode.NoiseMap)
        {
            terrainDisplay.DrawTexture(TextureGenerator.TextureFromHeightMap(noiseMap));
        }
        else if (drawMode == DrawMode.ColourMap)
        {
            terrainDisplay.DrawTexture(TextureGenerator.TextureFromColorMap(colorMap, mapChunkSize, mapChunkSize));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            terrainDisplay.DrawMesh(MeshGenerator.GenerateTerrainMesh(noiseMap, meshHeightMultiplier, meshHeightCurve, levelOfDetail), TextureGenerator.TextureFromColorMap(colorMap, mapChunkSize, mapChunkSize));
        }
    }
Esempio n. 15
0
    public void DrawMapInEditor()
    {
        MapData mapData = GenerateMapData(Vector2.zero);

        MapDisplay display = FindObjectOfType <MapDisplay>();

        if (drawMode == DrawMode.NoiseMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(mapData.heightMap));
        }
        else if (drawMode == DrawMode.ColourMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromColourMap(mapData.colourMap, mapChunkSize, mapChunkSize));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            display.DrawMesh
                (MeshGenerator.GenerateTerrainMesh
                    (mapData.heightMap, meshHeightMultiplier, meshHeightCurve, editorPreviewLOD),
                TextureGenerator.TextureFromColourMap(mapData.colourMap, mapChunkSize, mapChunkSize));
        }
        else if (drawMode == DrawMode.FalloffMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(FalloffGenerator.GenerateFalloffMap(mapChunkSize)));
        }
    }
Esempio n. 16
0
    public void DrawMapInEditor()
    {
        textureData.ApplyToMaterial(terrainMaterial);
        textureData.UpdateMeshHeights(terrainMaterial, heightMapSettings.minHeight, heightMapSettings.maxHeight);

        ChunkBorderInfo chunkBorderInfo = new ChunkBorderInfo(false, FalloffGenerator.Corner.TOPLEFT, false, FalloffGenerator.Edge.TOP);
        HeightMap       heightMap       = HeightMapGenerator.GenerateHeightMap(meshSettings.numberVerticesPerLine, meshSettings.numberVerticesPerLine, heightMapSettings, mapRulesSettings, Vector2.zero, chunkBorderInfo);

        CleanScene();

        if (drawMode == DrawMode.NoiseMap)
        {
            DrawTexture(TextureGenerator.TextureFromHeightMap(heightMap));
        }
        else if (drawMode == DrawMode.FalloffMap)
        {
            DrawTexture(TextureGenerator.TextureFromHeightMap(new HeightMap(FalloffGenerator.GenerateFalloffMap(meshSettings.numberVerticesPerLine, mapRulesSettings), 0, 1)));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            DrawMesh(MeshGenerator.GenerateTerrainMesh(heightMap.values, meshSettings, editorPreviewLOD));
        }
        else if (drawMode == DrawMode.Map)
        {
            DrawMesh(MeshGenerator.GenerateTerrainMesh(heightMap.values, meshSettings, editorPreviewLOD));
            DrawMap();
        }
    }
Esempio n. 17
0
    private Texture2D CreateTexture()
    {
        //Generate Noise Map and ColourMap
        int width  = gridSize + 1;
        int height = gridSize + 1;

        noiseMap  = Noise.GenerateNoiseMap(width, height, seed, scale, octaves, persistance, lacunarity, offset);
        colourMap = new Color[width * height];

        for (int i = 0; i < height; i++)
        {
            for (int j = 0; j < width; j++)
            {
                float currentHeight = noiseMap[j, i];
                for (int k = 0; k < regions.Length; k++)
                {
                    if (currentHeight <= regions[k].height)
                    {
                        colourMap[i * width + j] = regions[k].colour;
                        break;
                    }
                }
            }
        }

        Texture2D texture = TextureGenerator.TextureFromHeightMap(noiseMap, colourMap);

        return(texture);
    }
Esempio n. 18
0
    public void DrawMapInEditor()
    {
        textureData.ApplyToMaterial(terrainMaterial);
        textureData.UpdateMeshHeights(terrainMaterial, heightMapSettings.minHeight, heightMapSettings.maxHeight);
        HeightMap heightMap;

        if (eastSettings != null && westSettings != null && westLocation != null && westLocation != null)
        {
            Region east = new Region(eastSettings, eastLocationPos);
            Region west = new Region(westSettings, westLocationPos);
            heightMap = HeightMapGenerator.GenerateHeightMap(meshSettings, new Region(heightMapSettings, east, west, Vector3.zero, power), Vector2.zero);
        }
        else
        {
            heightMap = HeightMapGenerator.GenerateHeightMap(meshSettings, heightMapSettings, Vector2.zero);
        }

        if (drawMode == DrawMode.NoiseMap)
        {
            DrawTexture(TextureGenerator.TextureFromHeightMap(heightMap));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            DrawMesh(MeshGenerator.GenerateTerrainMesh(heightMap.values, meshSettings, editorPreviewLOD));
        }
        else if (drawMode == DrawMode.FalloffMap)
        {
            DrawTexture(TextureGenerator.TextureFromHeightMap(new HeightMap(FalloffGenerator.GenerateFalloffMap(meshSettings.numVertsPerLine), 0, 1)));
        }
    }
Esempio n. 19
0
    public void GenerateMap()
    {
        float[,] noiseMap = Noise.GenerateNoiseMap(_mapWidth, _mapHeight, _seed, _noiseScale, _octaves, _persistance, _lacunarity, _offset);

        Color[] colormap = SetColorMap(noiseMap);

        // Display
        if (_drawMode == DrawMode.NoiseMap)
        {
            _mapDisplay.DrawTexture(TextureGenerator.TextureFromHeightMap(noiseMap));
        }
        else if (_drawMode == DrawMode.RegionColorMap)
        {
            _mapDisplay.DrawTexture(TextureGenerator.TextureFromColormap(colormap, _mapWidth, _mapHeight));
        }
        else if (_drawMode == DrawMode.Mesh)
        {
            var meshData = MeshGenerator.GenerateTerrainMesh(noiseMap, _regions[0].height);
            _mapDisplay.DrawMesh(meshData, TextureGenerator.TextureFromColormap(colormap, _mapWidth, _mapHeight));
            if (_generateObstacles)
            {
                ObstacleGenerator.GenerateObstacleMesh(meshData);
            }
        }
        else if (_drawMode == DrawMode.Mesh3D)
        {
            _mapDisplay.DrawMesh3D(MeshGenerator3D.GenerateTerrainMesh(noiseMap), TextureGenerator.TextureFromColormap(colormap, _mapWidth, _mapHeight));
        }
    }
Esempio n. 20
0
    void UpdatePreview()
    {
        NoiseGenerator generator = (NoiseGenerator)target;

        float[,] noiseMap = generator.Generate(120, 120, Vector2.zero);
        texture           = TextureGenerator.TextureFromHeightMap(noiseMap);
    }
Esempio n. 21
0
    public void GenerateMap()
    {
        //float[,] noiseMap = Noise.WhiteNoise(mapWidth, mapHeight,seed);
        float[,,] noiseResultMap = Noise.GenerateNoiseMap(mapChunkSize, mapChunkSize, noiseData.seed, noiseData.noiseScale, noiseData.octaves, noiseData.persistance, noiseData.lacunarity, noiseData.offset);
        float[,] noiseMap        = new float[mapChunkSize, mapChunkSize];
        Color[] colorMap = new Color[mapChunkSize * mapChunkSize];
        for (int y = 0; y < mapChunkSize; y++)
        {
            for (int x = 0; x < mapChunkSize; x++)
            {
                noiseMap [x, y] = noiseData.valueNoise * noiseResultMap [0, x, y] + noiseData.perlinNoise * noiseResultMap [1, x, y] + noiseData.simplexeNoise * noiseResultMap [2, x, y];
            }
        }
        if (erosionData.thermalcycle > 0)
        {
            noiseMap = Erosion.thermalErosion(noiseMap, erosionData.thermalcycle, erosionData.thermalslopeLimit, erosionData.termalStrength, mapChunkSize);
        }
        if (erosionData.fastcycle > 0)
        {
            noiseMap = Erosion.fastErosion(noiseMap, erosionData.fastcycle, erosionData.fastslopeLimit, erosionData.fastStrength, mapChunkSize);
        }
        if (erosionData.hydraulicCycle > 0)
        {
            noiseMap = Erosion.hydraulicErosion(noiseMap, erosionData.hydraulicCycle, erosionData.amountRain / 10f, erosionData.solubility, erosionData.evaporation, mapChunkSize);
        }
        for (int y = 0; y < mapChunkSize; y++)
        {
            for (int x = 0; x < mapChunkSize; x++)
            {
                if (terrainData.useIslandFallOff)
                {
                    noiseMap [x, y] = Mathf.Clamp01(noiseMap [x, y] - fallofMap [x, y]);
                }
                float currentHeight = noiseMap[x, y];
                for (int i = 0; i < regions.Length; i++)
                {
                    if (currentHeight <= regions[i].height)
                    {
                        colorMap[x + y * mapChunkSize] = regions[i].color;
                        break;
                    }
                }
            }
        }
        MapDisplay display = FindObjectOfType <MapDisplay>();

        if (drawMode == DrawMode.NoiseMAp)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(noiseMap));
        }
        else if (drawMode == DrawMode.ColorMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromColorMap(colorMap, mapChunkSize, mapChunkSize));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            display.DrawMesh(MeshGenerator.GenerateTerrainMesh(noiseMap, terrainData.meshHeightMultiplier, terrainData.meshHeightCurve, levelOfDetail), TextureGenerator.TextureFromColorMap(colorMap, mapChunkSize, mapChunkSize));
        }
        textureData.UpdateMeshHeights(terrainMaterial, 10 * terrainData.minHeight, 10 * terrainData.maxHeight);
    }
Esempio n. 22
0
    public void DrawMapInEditor()
    {
        MapData mapData = GenerateMapData(Vector2.zero);

        textureData.UpdateMeshHeights(
            terrainMaterial, terrainData.minHeight, terrainData.maxHeight);

        MapDisplay display = FindObjectOfType <MapDisplay>();

        if (drawMode == DrawMode.NoiseMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(
                                    mapData.heightMap)
                                );
        }
        else if (drawMode == DrawMode.Mesh)
        {
            display.DrawMesh(
                MeshGenerator.GenerateTerrainMesh(
                    mapData.heightMap, terrainData.meshHeightMultiplier,
                    terrainData.meshHeightCurve, editorPreviewLOD,
                    terrainData.useFlatShading
                    )
                );
        }
        else if (drawMode == DrawMode.FalloffMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(
                                    FalloffGenerator.GenerateFalloffMap(mapChunkSize))
                                );
        }
    }
Esempio n. 23
0
    public void GenerateMap()
    {
        float[,] NoiseMap = Noise.GenerateNoiseMap(MapWidth, MapHeight, Seed, NoiseScale, Octaves, Persistance, Lacunarity, Offset);

        Color[] ColourMap = new Color[MapWidth * MapHeight];
        for (int y = 0; y < MapHeight; y++)
        {
            for (int x = 0; x < MapWidth; x++)
            {
                float CurrentHeight = NoiseMap[x, y];
                for (int i = 0; i < Regions.Length; i++)
                {
                    if (CurrentHeight <= Regions[i].Height)
                    {
                        ColourMap[y * MapWidth + x] = Regions[i].Colour;
                        break;
                    }
                }
            }
        }

        MapDisplay Display = FindObjectOfType <MapDisplay>();

        if (DMode == DrawMode.NoiseMap)
        {
            Display.DrawTexture(TextureGenerator.TextureFromHeightMap(NoiseMap));
        }
        else if (DMode == DrawMode.ColourMap)
        {
            Display.DrawTexture(TextureGenerator.TextureFromColourMap(ColourMap, MapWidth, MapHeight));
        }
    }
Esempio n. 24
0
    public void DrawMapInEditor()
    {
        MapData[] mapData = new MapData[6];
        int       i       = ((int)Mathf.Pow(4, divisions));

        for (int j = 0; j < 6; j++)
        {
            int k = (int)Mathf.Pow(i, 0.5f);
            mapData[j] = GenerateMapData(new Vector2(0, (j * gridSize * k) + 1), (gridSize * k) + 1);
        }

        MapDisplay display = FindObjectOfType <MapDisplay>();

        if (drawMode == DrawMode.NoiseMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(mapData[0].heightMap));
        }
        else if (drawMode == DrawMode.ColorMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromColorMap(mapData[0].colorMap, mapChunkSize, mapChunkSize));
        }
        //else if (drawMode == DrawMode.Mesh) { display.DrawMesh(MeshGenerator.GenerateTerrainMesh(mapData[0].heightMap, meshHeightmultiplier, meshHeightCurve, previewLOD), TextureGenerator.TextureFromColorMap(mapData.colorMap, mapChunkSize, mapChunkSize)); }
        else if (drawMode == DrawMode.Sphere)
        {
            display.DrawSphere(sphereMapping.getSphere(i, gridSize, mapData, meshHeightmultiplier, meshHeightCurve, regions, flat_shading), i);
        }
    }
    public void DrawMapInEditor()
    {
        textureData.UpdateMeshHeights(terrainMaterial, terrainData.minHeight, terrainData.maxHeight);

        MapData mapData = GenerateMapData(Vector2.zero);

        MapDisplay display = FindObjectOfType <MapDisplay>();

        if (drawMode == DrawMode.NoiseMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(mapData.heightMap));
        }

        /*else if (drawMode == DrawMode.ColorMap)
         * {
         *  display.DrawTexture(TextureGenerator.TextureFromColorMap(mapData.colorMap, mapChunkSize, mapChunkSize));
         * }*/
        else if (drawMode == DrawMode.Mesh)
        {
            display.DrawMesh(MeshGenerator.GenerateTerrainMesh(mapData.heightMap, terrainData.meshHeightMultiplier, terrainData.meshHeightCurve, editorPreviewLevelOfDetail, terrainData.useFlatShading) /*, TextureGenerator.TextureFromColorMap(mapData.colorMap, mapChunkSize, mapChunkSize)*/);
        }
        else if (drawMode == DrawMode.FalloffMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(falloffMap));
        }
    }
    /// <summary>
    /// Draws the preview map in the scene.
    /// </summary>
    public void DrawMapInEditor()
    {
        // applies the texture settings to the material
        textureSettings.ApplyToMaterial(terrainMaterial);
        textureSettings.UpdateMeshHeights(terrainMaterial, heightMapSettings.MinHeight, heightMapSettings.MaxHeight);
        // generates a height map from the mesh, height map and noise settings at location (0, 0)
        HeightMap heightMap = HeightMapGenerator.GenerateHeightMap(meshSettings.NumVertsPerLine, meshSettings.NumVertsPerLine, heightMapSettings, Vector2.zero);

        // draws a noise map on a texture
        if (drawMode == DrawMode.NoiseMap)
        {
            DrawTexture(TextureGenerator.TextureFromHeightMap(heightMap));
        }
        // generates a mesh from the height map
        else if (drawMode == DrawMode.Mesh)
        {
            DrawMesh(MeshGenerator.GenerateTerrainMesh(heightMap.values, meshSettings, editorPreviewLOD));
        }
        // draws a falloff map on a texture
        else if (drawMode == DrawMode.FalloffMap)
        {
            // passes in a height map generated from the falloff generator
            DrawTexture(TextureGenerator.TextureFromHeightMap(new HeightMap(FalloffGenerator.GenerateFalloffMap(meshSettings.NumVertsPerLine), 0, 1)));
        }
    }
Esempio n. 27
0
    public void DrawMapInEditor()
    {
        MapData mapData = GenerateMapData(new Vector2(0, 0));        //pass the position zero

        MapDisplayBehaviour display = FindObjectOfType <MapDisplayBehaviour> ();

        if (Mode == DrawMode.NoiseMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(mapData.HeightMap));
        }
        if (Mode == DrawMode.ColorMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromColorMap(mapData.ColorMap, MAP_CHUNK_SIZE,
                                                                     MAP_CHUNK_SIZE));
        }
        if (Mode == DrawMode.Mesh)
        {
            display.DrawMesh(MeshGenerator.GenerateTerrainMesh(mapData.HeightMap, MeshHeightMultiplier,
                                                               MeshHeightCurve, EditorPreviewLOD),
                             TextureGenerator.TextureFromColorMap(mapData.ColorMap, MAP_CHUNK_SIZE, MAP_CHUNK_SIZE));
        }
        if (Mode == DrawMode.FalloffMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(
                                    FallofGenerator.GenerateFalloffMap(MAP_CHUNK_SIZE)));
        }
    }
Esempio n. 28
0
    public void DrawMapInEditor()
    {
        if (newSeed)
        {
            heightMapSettings.noiseSettings.seed = rng.Next();
        }
        else
        {
            heightMapSettings.noiseSettings.seed = seed;
        }
        textureData.ApplyToMaterial(terrainMaterial);
        textureData.UpdateMeshHeights(terrainMaterial, heightMapSettings.minHeight, heightMapSettings.maxHeight);
        HeightMap heightMap = HeightMapGenerator.GenerateHeightMap(meshSettings.numVertsPerLine, meshSettings.numVertsPerLine, heightMapSettings, Vector2.zero);

        if (drawMode == DrawMode.NoiseMap)
        {
            DrawTexture(TextureGenerator.TextureFromHeightMap(heightMap));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            DrawMesh(MeshGenerator.GenerateTerrainMesh(heightMap.values, meshSettings, editorPreviewLOD));
        }
        else if (drawMode == DrawMode.FalloffMap)
        {
            DrawTexture(TextureGenerator.TextureFromHeightMap(new HeightMap(FalloffGenerator.GenerateFalloffMap(meshSettings.numVertsPerLine), 0, 1)));
        }
    }
Esempio n. 29
0
    public void GenerateMap()
    {
        float[,] noiseMap = Noise.GenerateNoiseMap(mapWidth, mapHeight, seed, noiseScale, octaves, persistance, lacunarity, offset);

        Color[] colourMap = new Color[mapWidth * mapHeight];
        for (int y = 0; y < mapHeight; y++)
        {
            for (int x = 0; x < mapWidth; x++)
            {
                float currentHeight = noiseMap [x, y];
                for (int i = 0; i < regions.Length; i++)
                {
                    if (currentHeight <= regions [i].height)
                    {
                        colourMap [y * mapWidth + x] = regions [i].colour;
                        break;
                    }
                }
            }
        }

        MapDisplay display = FindObjectOfType <MapDisplay> ();

        if (drawMode == DrawMode.NoiseMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromHeightMap(noiseMap));
        }
        else if (drawMode == DrawMode.ColourMap)
        {
            display.DrawTexture(TextureGenerator.TextureFromColourMap(colourMap, mapWidth, mapHeight));
        }
    }
    public void DrawMapInEditor()
    {
        MapData    mapData    = GenrateMapData(Vector2.zero);
        MapDisplay mapDisplay = FindObjectOfType <MapDisplay>();

        switch (drawMode)
        {
        case DrawMode.HEIGHT_MAP:
            mapDisplay.DrawTexture(TextureGenerator.TextureFromHeightMap(mapData.heightMap));

            break;

        case DrawMode.COLOR_MAP:
            mapDisplay.DrawTexture(TextureGenerator.TextureFromColorMap(mapData.colorMap, mapChunkSize, mapChunkSize));
            break;

        case DrawMode.MESH:
            mapDisplay.DrawMesh(MeshGenerator.GenerateTerrainMesh(mapData.heightMap, terrainData.meshHeightMultiplier, terrainData.meshHeightCurve, editorPreviewlod, terrainData.useFlatShading), TextureGenerator.TextureFromColorMap(mapData.colorMap, mapChunkSize, mapChunkSize));
            break;

        case DrawMode.FALLOFF_MAP:
            mapDisplay.DrawTexture(TextureGenerator.TextureFromHeightMap(FalloffGenerator.GenerateFallOffMap(mapChunkSize)));
            break;
        }
    }