Monthly Archives: February 2016

Sick weekend: terrain generation

This weekend I’m sick and it sucks. As good a time as any to try myself at terrain generation.

I’m a lousy programmer and it’s the first time I ever dabble with this but here’s the thought process I went through.
Also, It’s not finished, but I figured I’d give myself a motivational boost!

The first step was for me to draw a grid and use the vertices’ coordinates to create triangles. Triangles are then combined into a single mesh.

  • The lines and yellow handles are just there as visual guides.
  • I used coroutines to show the processes step by step (useful for debugging and to make fancy gifs)
  • The two pics below show some various steps in the work. I gradually simplified things and replaced coroutines with methods to go faster.

gen02

gen

Up to this point I was adding height noise with a basic Random.Range but switched to Perlin noise to create the terrain-like topography . Thanks Mr.Perlin! <3
I rounded the height values to int to achieve the “ground ladder” effect.

gen03

Then some fanciness. I created a basic texture with the terrain color and figured out a basic algorithm to match the mesh’s vertices uvs to the texture.

terra

By far this was the most painful and not funny bit. And my algorithm sucks.

  • I need to remove the “spiky color corners” (tech-savvy language FTW)
  • I need to figure out how flat shading works to make this look appropriately old-school

gen07

I also added an arbitrary water plane.

gen05

Same thing with noise not rounded to int.

gen06


Quick note/question:

I’m quickly limited in mesh vertices count. The limit is set at 65000 meaning that a 275*275 units terrain is already out of bounds. I guess the way to fix this is to generate the terrain data and when creating the mesh, switch to a new mesh when the vertex cap is reached?