I generated a terrain using a technique from this blog post, everything worked well and I got the wanted result. This is what my generated island looks like:
As you can see the terrain have a polygon structure. Here is the graph that generated this mesh:
This is the code used to generate this mesh from the graph:
void DrawPolygons(){
List<Vector3> vertices = new List<Vector3>();
List<int> triangles=new List<int>();
List<Color32> colors = new List<Color32>();
foreach(Center c in centers){
float zp = zScale*c.elevation;
vertices.Add(new Vector3(((Vector2)c.point).x,zp,((Vector2)c.point).y));
Color c0 = getColor(c);
colors.Add(c0);
int centerIndex=vertices.Count-1;
var edges = c.borders;
int lastIndex = 0;
int firstIndex = 0;
for(int i =0;i<c.borders.Count;i++){
if(edges[i].v0 == null && edges[i].v1 == null)
break;
//get voronoi edge
Corner corner0 = edges[i].v0;
Corner corner1 = edges[i].v1;
//get vertices height
float z0 = zScale*corner0.elevation;
float z1 = zScale*corner1.elevation;
//add color
if(edges[i].river>0){
c0 = Color.cyan;
}else{
c0 = getColor(c);
}
colors.Add(c0);
colors.Add(c0);
//creat voronoi edge points
Vector3 v0 = new Vector3(((Vector2)corner0.point).x,z0,((Vector2)corner0.point).y);
Vector3 v1 = new Vector3(((Vector2)corner1.point).x,z1,((Vector2)corner1.point).y);
//add points to vertices
vertices.Add(v0);
var i2 = vertices.Count - 1;
vertices.Add(v1);
var i3 = vertices.Count - 1;
//add triangles calculating surface normals so i can always add triangles clockwise correctly
var surfaceNormal = Vector3.Cross (v0-(new Vector3(((Vector2)c.point).x,zp,((Vector2)c.point).y)), v1-(new Vector3(((Vector2)c.point).x,zp,((Vector2)c.point).y)));
if(surfaceNormal.y>0)
AddTriangle(triangles, centerIndex, i2, i3);
else
AddTriangle(triangles, centerIndex, i3, i2);
firstIndex = i2;
lastIndex = i3;
}
}
//calculating uv's
Vector2[] uvs = new Vector2[vertices.Count];
for (int i = 0; i < uvs.Length; i++)
{
uvs[i] = new Vector2(vertices[i].x / SIZE, vertices[i].z / SIZE);
}
mesh.Clear();
mesh.vertices = vertices.ToArray();
mesh.triangles = triangles.ToArray();
mesh.uv = uvs;
mesh.colors32 = colors.ToArray();
mesh.RecalculateNormals();
mesh.RecalculateBounds();
meshFilter.sharedMesh = mesh;
meshCollider.sharedMesh = mesh;
}
I would like to know if it's possible to have a noisy/realistic looking terrain from this. How would I implement such a thing?
Basically I want something with no hard edges, terrain that looks smooth but not too smooth, something like this video shows: