public void GetCellData(Column column) { int chunkSize = World.chunkSize; column.edgeMap = new FastNoise.EdgeData[chunkSize, chunkSize]; float currentCellValue = 0; // Iterate over height map for (int x = 0; x < chunkSize; x++) { for (int z = 0; z < chunkSize; z++) { // Global voxel column coordinates int gx = (int)(x + column.position.x); int gz = (int)(z + column.position.z); // Get cellular noise data FastNoise.EdgeData edgeData = worldBiomes.edgeNoiseGen.GetEdgeData(gx, gz); column.edgeMap[x, z] = edgeData; // Store list of all cellValues present in this column if (edgeData.currentCellValue != currentCellValue) { currentCellValue = edgeData.currentCellValue; if (!column.cellValues.Contains(currentCellValue)) { column.cellValues.Add(currentCellValue); } } } } }
static Color DebugBlockColor(int x, int z, Column column) { Color color; FastNoise.EdgeData edge = column.edgeMap[x, z]; if (edge.distance2Edge < 0.002f) { color = Color.black; } else { if (edge.currentCellValue >= 0.5f) { color = Color.red; } else { color = Color.cyan; } } color -= color * (float)(Mathf.InverseLerp(0, 0.1f, edge.distance2Edge) / 1.5); if (edge.distance2Edge < TerrainGenerator.worldBiomes.smoothRadius) { color -= new Color(0.1f, 0.1f, 0.1f); } return(color); }
// Get biome topology and smooth between biomes if necessary // using Cellular value and distance-to-edge noise respectively public void GetTopologyData(Column column) { int chunkSize = World.chunkSize; column.heightMap = new int[chunkSize, chunkSize]; // Iterate over height map for (int x = 0; x < chunkSize; x++) { for (int z = 0; z < chunkSize; z++) { // Global voxel column coordinates int gx = (int)(x + column.position.x); int gz = (int)(z + column.position.z); // Get cellular noise data FastNoise.EdgeData edgeData = column.edgeMap[x, z]; // Get current biome type TerrainLibrary.Biome currentBiome = worldBiomes.GetBiome(edgeData.currentCellValue); // Get adjacent biome type TerrainLibrary.Biome adjacentBiome = worldBiomes.GetBiome(edgeData.adjacentCellValue); // Get topology for this pixel Topology currentTolopogy = GetBiomeTopology(x, z, column, currentBiome); Topology finalTopology; // Within smoothing radius and adjacent biome is different if (edgeData.distance2Edge < worldBiomes.smoothRadius && currentBiome != adjacentBiome) { if (!column.biomeBoundary) { column.biomeBoundary = true; } float InterpValue = Mathf.InverseLerp(0, worldBiomes.smoothRadius, edgeData.distance2Edge); // Get topology for this pixel if adjacent biome type Topology adjacentTopology = GetBiomeTopology(x, z, column, adjacentBiome); // Smooth between topologys finalTopology = SmoothTopologys(currentTolopogy, adjacentTopology, InterpValue); } else { finalTopology = currentTolopogy; } int POIheight = 0; // Where points of interest exist, flatten terrain if (column.POIHeightGradient != null && column.POIHeightGradient[x, z] != 0) { float interpValue = (float)column.POIHeightGradient[x, z] / chunkSize; Topology POITopology = new Topology(0.5f, finalTopology.height, 0.5f); finalTopology = SmoothToPOI(POITopology, finalTopology, interpValue); // Adjust heighest point POIheight = column.POIType.wallHeight; } // Generate final height value for chunk data column.heightMap[x, z] = (int)Mathf.Lerp(0, finalTopology.height, finalTopology.baseNoise * finalTopology.noise); // Update highest and lowest block in chunk column column.CheckHighest(column.heightMap[x, z] + POIheight); column.CheckLowest(column.heightMap[x, z]); } } }