public static ChunkData GenerateChunkData(Vector2 startPoint, Vector2 chunkCoord, WorldSettings worldSettings) { int width = worldSettings.meshSettings.numVertsPerLine; int height = worldSettings.meshSettings.numVertsPerLine; int extraBorderSize; Region biomeMap = GetBiomeMap(chunkCoord, worldSettings, out extraBorderSize); Region worldHeightMap = worldSettings.globalHeightMapSettings == null ? new Region(new float[width, height], 0, 0) : RegionGenerator.GenerateRegion(width, height, worldSettings.globalHeightMapSettings, startPoint); float[,] combinedHeightMap = new float[width, height]; List <int> activeBiomes = new List <int>(); MinMaxFloat minMax = new MinMaxFloat(); Material material = null; float worldEdgeSmoothing = worldSettings.globalBiomeSettings.heightMapEdgeSmoothing; // Add global world height for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { combinedHeightMap[x, y] += worldHeightMap.values[x, y]; } } //string debug = ""; // Add biome height foreach (BiomeSettings biome in worldSettings.biomes) { // @TODO: apply masking to materials/texturing, too (one material/shader for entire world?) if (material == null) { material = biome.TerrainMaterial; } Region heightMap = RegionGenerator.GenerateRegion(width, height, biome.heightSettings, startPoint); /* * if (Mathf.Approximately(biome.worldMapBiomeValue, 0f) && startPoint.x >= -150 && startPoint.x <= -50 && startPoint.y >= -150 && startPoint.y <= -50) * { * debug = "chunkPosition" + startPoint + " "; * } */ float[,] biomeBlurMask = CalculateBlurredBiomeMask(biomeMap.values, width, height, biome.worldMapBiomeValue, worldEdgeSmoothing * biome.heightMapEdgeSmoothingModifier);//, debug); minMax.AddValue(heightMap.minValue + worldHeightMap.minValue); minMax.AddValue(heightMap.maxValue + worldHeightMap.maxValue); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { float biomeBlurValue = biomeBlurMask[x, y]; if (biomeBlurValue <= 0) { continue; } activeBiomes.Add(biome.id); combinedHeightMap[x, y] += heightMap.values[x, y] * biomeBlurValue; } } } return(new ChunkData { heightMap = new Region(combinedHeightMap, minMax.Min, minMax.Max), material = material }); }