static void NoiseToArray(NoiseInfo info, int seed, Vector2[] positions, Vector2 positionOffset, float[] result) { float amplitude = 1f; float frequency = 1f; for (int i = 0; i < info.layerCount; i++) { for (int j = 0; j < positions.Length; j++) { Vector2 position = (positions[j] + positionOffset) / info.spread * frequency + Vector2.one * (seed + i); if (i == 0) { result[j] = 0f; } result[j] += Mathf.PerlinNoise(position.x, position.y) * amplitude; } amplitude *= info.persistence; frequency *= info.lacunarity; } //Set the noise range from 0 to 1 result.InverseLerp(0f, NoiseInfo.GetMaxHeight(info.layerCount, info.persistence)); }
static void NoiseToArray(NoiseInfo info, int seed, Vector2 positionOffset, float[,] result) { Int2 size = new Int2(result.GetLength(0), result.GetLength(1)); float amplitude = 1f; float frequency = 1f; for (int i = 0; i < info.layerCount; i++) { for (int x = 0; x < size.x; x++) { for (int y = 0; y < size.y; y++) { Vector2 position = (new Vector2(x, y) + positionOffset) / info.spread * frequency + Vector2.one * (seed + i); if (i == 0) { result[x, y] = 0f; } result[x, y] += Mathf.PerlinNoise(position.x, position.y) * amplitude; } } amplitude *= info.persistence; frequency *= info.lacunarity; } //Set the noise range from 0 to 1 result.InverseLerp(0f, NoiseInfo.GetMaxHeight(info.layerCount, info.persistence)); }