public void DrawMapInEditor() { textureData.ApplyToMaterial(terrainMaterial); textureData.UpdateMeshHeights(terrainMaterial, heightMapSettings.minHeight, heightMapSettings.maxHeight); HeightMap heightMap = HeightMapGenerator.GenerateHeightMap(meshSettings.numVerticesPerLine, meshSettings.numVerticesPerLine, heightMapSettings, heightMapSettings.edgesData, 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.numVerticesPerLine), 0, 1))); } else if (drawMode == DrawMode.EdgeMap) { DrawTexture(TextureGenerator.TextureFromHeightMap(new HeightMap(EdgeMapGenerator.GenerateEdgeMap(heightMapSettings.edgesData, meshSettings.numVerticesPerLine), 0, 1))); } }
public static HeightMap GenerateHeightMap(int width, int height, HeightMapSettings settings, EdgesData edgesData, Vector2 sampleCenter) { float[,] values = Noise.GenerateNoiseMap(width, height, settings.noiseSettings, sampleCenter); float[,] edgeMap = EdgeMapGenerator.GenerateEdgeMap(edgesData, width); AnimationCurve heightCurve_threadsafe = new AnimationCurve(settings.heightCurve.keys); float minValue = float.MaxValue; float maxValue = float.MinValue; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { float value = Mathf.Clamp01(values[i, j] - edgeMap[i, j]); values[i, j] *= heightCurve_threadsafe.Evaluate(value) * settings.heightMultiplier; if (values[i, j] > maxValue) { maxValue = values[i, j]; } if (values[i, j] < minValue) { minValue = values[i, j]; } } } return(new HeightMap(values, minValue, maxValue)); }