/// <summary> /// Applies a random material distribution to the terrain grid. /// </summary> public void ApplyMaterialLayer(GridMaterial mat, float scale, Vector2 seed, float chance) { int s2 = Size * 2; for (int i = 1; i < s2; i++) { for (int j = 0; j < Size; j++) { GridFace face = new GridFace(i, j); Vector2 pos = face.ToCartesianCoords2D(); // pos += face.PointsUp() ? new Vector2(0f, 0.333f * 0.866f) : pos += new Vector2(0f, 0.667f * 0.866f); if (SimplexNoise.Generate(seed.X + pos.X * scale, seed.Y + pos.Y * scale) < chance) { Materials[i, j] = mat; } } } }
/// <summary> /// Applies a material distribution to the terrain grid, based on height. /// </summary> public void ApplyLowMaterialLayer(GridMaterial mat, float scale, Vector2 seed, float clamp, float mul) { int s2 = Size * 2; for (int i = 1; i < s2; i++) { for (int j = 0; j < Size; j++) { GridFace face = new GridFace(i, j); double h = 0; foreach (GridVertex vert in face.Corners()) { h += HeightMap[vert.U, vert.V]; } h *= 0.333f; Vector2 pos = face.ToCartesianCoords2D(); // pos += face.PointsUp() ? new Vector2(0f, 0.333f * 0.866f) : pos += new Vector2(0f, 0.667f * 0.866f); if ((SimplexNoise.Generate(seed.X + pos.X * scale, seed.Y + pos.Y * scale) - 0.5) * mul + h < clamp) { Materials[i, j] = mat; } } } }