« Specific Designs | Main | Generating Terrain in Realtime; Really This Time »

Generating Terrain in Realtime

Yesterday it was decided that generating world tiles in realtime based upon heightmaps would be an easier way of transmitting them over the network and would save us from the problems we were having with Unity's terrain objects not being able to rotate. So now, when a client loads a tile they will be loading three 128x128 images; a heightmap, a texture map, and an object map. The heightmap is used both for generating the tiles and as a lookup table used for physics checks to keep players on the ground. The texture map allows for Ethan to paint the terrain using 4 different textures blended together with each texture being represented by a different channel (r,g,b,a). The object map keeps track of the locations of buildings, resources, and environment objects in the tile.
Of course, while this solution in many ways makes the networking easier and provides us with a very expandable framework for adding new features it means a lot more work is required up front on the client. Now that the terrain needs to be generated on demand instead of merely loaded from a preexisting object we have to do a lot more calculation. It also turns out that the tricky part is not calculating the vertices, nor the uv coordinates, but rather calculating the normals for all the faces.
This is what happens when you don't have any normals: