Why does this piece of code run at 300ms? I can’t see how it is doing anything expensive:
IEnumerator PaintTheTerrain() {
int aw = Chunk.terrainData.alphamapWidth;
for (int x = 0; x < aw; x++) {
float normalPosX = (x * 1f) / (aw * 1f);
for (int y = 0; y < aw; y++) {
float normalPosY = (y * 1f) / (aw * 1f);
float angle = Chunk.terrainData.GetSteepness (normalPosX, normalPosY);
float height = Chunk.terrainData.GetInterpolatedHeight (normalPosX, normalPosY);
Biome Biome = Biomes.GetPoint (x, y);
if (height < WaterLevel + 2) {
map [y, x, 2] = 1;
} else if (angle > 25) {
map [y, x, 1] = 1;
} else {
map [y, x, Biome.SplatIndex] = 1;
}
}
if (x % 10 == 0) {
progress = (x * 1f) / (aw * 1f);
yield return null;
}
}
Chunk.terrainData.SetAlphamaps(0,0,map);
}