public void DrawMap() { MapData mapData = GenerateMapData(Vector2.zero); MapDisplay mapDisplay = FindObjectOfType <MapDisplay>(); switch (drawMode) { default: case DrawMode.NoiseMap: mapDisplay.DrawTexture(TextureGenerator.FromHeightMap(mapData.heightMap)); break; case DrawMode.ColorMap: mapDisplay.DrawTexture(TextureGenerator.FromColorMap(mapData.colorMap, mapChunkSize, mapChunkSize)); break; case DrawMode.FalloffMap: mapDisplay.DrawTexture(TextureGenerator.FromHeightMap(FalloffMapGenerator.GenerateFalloffMap(mapChunkSize))); break; case DrawMode.Mesh: mapDisplay.DrawMesh( MeshGenerator.GenerateTerrainMeshData(mapData.heightMap, terrainData.meshHeightMultiplier, terrainData.meshHeightCurve, editorLevelOfDetail, terrainData.applyFlatShading), TextureGenerator.FromColorMap(mapData.colorMap, mapChunkSize, mapChunkSize) ); break; } }
void OnValidate() { if (lacunarity < 1) { lacunarity = 1; } if (octaves < 0) { octaves = 0; } falloffMap = FalloffMapGenerator.GenerateFalloffMap(mapChunkSize); }
private void ApplyFalloffMap(int size, float[,] mapData) { if (m_falloffMap == null) { m_falloffMap = FalloffMapGenerator.GenerateFalloffMap(size, size); } for (int x = 0; x < size; x++) { for (int y = 0; y < size; y++) { mapData[x, y] = Mathf.Clamp01(mapData[x, y] - m_falloffMap[x, y]); } } }
private void OnValidate() { if (noiseData != null) { noiseData.OnValuesUpdated -= OnValuesUpdated; noiseData.OnValuesUpdated += OnValuesUpdated; } if (terrainData != null) { terrainData.OnValuesUpdated -= OnValuesUpdated; terrainData.OnValuesUpdated += OnValuesUpdated; } if (_falloffMap == null) { _falloffMap = FalloffMapGenerator.GenerateFalloffMap(mapChunkSize); } }
public void DrawMapInEditor() { MapData mapData = GenerateMapData(Vector2.zero); DrawMap display = FindObjectOfType <DrawMap> (); if (drawMode == DrawMode.NoiseMap) { display.DrawTexture(TextureSampler2D.TextureFromHeightMap(mapData.heightMap)); } else if (drawMode == DrawMode.ColourMap) { display.DrawTexture(TextureSampler2D.TextureFromColourMap(mapData.colourMap, mapChunkSize, mapChunkSize)); } else if (drawMode == DrawMode.Mesh) { display.DrawMesh(MeshGenerator.GenerateTerrainMesh(mapData.heightMap, meshHeightMultiplier, meshHeightCurve, editorPreviewLOD), TextureSampler2D.TextureFromColourMap(mapData.colourMap, mapChunkSize, mapChunkSize)); } else if (drawMode == DrawMode.FalloffMap) { display.DrawTexture(TextureSampler2D.TextureFromHeightMap(FalloffMapGenerator.GenerateFalloffMap(mapChunkSize))); } }
private void Awake() { m_falloffMap = FalloffMapGenerator.GenerateFalloffMap(MapChunkSize() + 2, MapChunkSize() + 2); }
void Awake() { falloffMap = FalloffMapGenerator.GenerateFalloffMap(mapChunkSize); }
//public static HeightMap GenerateHeightMap(HeightMapSettings settings, Vector2 sampleCenter, int mapWidth, int mapHeight = -1, NoiseGeneratorType type = NoiseGeneratorType.fBmNoiseMap) public static HeightMap GenerateHeightMap(HeightMapSettings settings, Vector2 sampleCenter, int mapWidth, int mapHeight = -1) { if (mapHeight == -1) { mapHeight = mapWidth; } float[,] values; //switch (type) switch (settings.applyingNoiseType) { case NoiseGeneratorType.fBmNoiseMap: values = Noise.GenerateNoiseMap(mapWidth, mapHeight, settings.noiseSettings, sampleCenter); break; case NoiseGeneratorType.octavesNoiseMap: values = Noise.GenerateNoiseMap(mapWidth, mapHeight, settings.octavesSettings, sampleCenter); break; case NoiseGeneratorType.boxFilteredNoiseMap: values = Noise.GenerateBoxLinearFilteredNoiseMap(mapWidth, mapHeight, settings.boxFilteredSettings); break; case NoiseGeneratorType.uniformNoiseMap: //values = Noise.GenerateUniformNoiseMap(mapWidth, mapHeight, mapWidth * 0.5f, mapWidth * 0.5f, sampleCenter.y); values = Noise.GenerateUniformNoiseMap(mapWidth, mapHeight, mapWidth * 0.5f, mapWidth * 0.5f, sampleCenter.y); break; default: Debug.LogError("Noise generetion type doesn't set. Use fractal Brounian moution by default."); values = Noise.GenerateNoiseMap(mapWidth, mapHeight, settings.noiseSettings, sampleCenter); break; } if (settings.applyFalloffMap) { if (falloffMap == null) { falloffMap = FalloffMapGenerator.GenerateFalloffMap(mapWidth, mapHeight); } } AnimationCurve heightCurveThreadsafe = new AnimationCurve(settings.heightCurve.keys); float minValue = float.MaxValue; float maxValue = float.MinValue; if (settings.applyFalloffMap) { for (int i = 0; i < mapWidth; i++) { for (int j = 0; j < mapHeight; j++) { values[i, j] *= heightCurveThreadsafe.Evaluate(values[i, j] - falloffMap[i, j]) * settings.heightMultiplier; if (values[i, j] < minValue) { minValue = values[i, j]; } if (values[i, j] > maxValue) { maxValue = values[i, j]; } } } } else { for (int i = 0; i < mapWidth; i++) { for (int j = 0; j < mapHeight; j++) { values[i, j] *= heightCurveThreadsafe.Evaluate(values[i, j]) * settings.heightMultiplier; if (values[i, j] < minValue) { minValue = values[i, j]; } if (values[i, j] > maxValue) { maxValue = values[i, j]; } } } } return(new HeightMap(values, minValue, maxValue)); }