Hello,
So, like many others here, I’m also working on a procedural terrain system. Just thought I’d show how it’s going so far, and hopefully get a few helpful pointers from everyone while I’m at it
My attempt has so far been targeted at making the terrain infinite, reproduceable (no randoms) and light-weight… The system creates a N by N grid of tiles around the reference transform (usually a camera), and shifts the tiles around as needed to keep the grid centered…
The tiles are just planes (for now), and deform themselves according to a heightmap.
The relief map is generated by a series of noise functions from libNoise (and the very convenient port to unity I found here on the forums)… The big thing here is that each vertex get’s it’s noise coordinates from it’s global position, so the amount of polygons and the tile’s position or size is irrelevant to the system… it will always conform to the heightmap below.
Each tile also calculates an RGBA texture map to be used as a blending mask for the terrain shader I found on the Unify Wiki… one of the channels is based on the vertex normal’s alignment to the up axis, so it blends in rock textures for steep terrain. The others are all based on height (so far), and switch the textures between sand, grass, and, uh… another kind of grass
There are also LOD meshes, and the system swaps them out according to distance, in the example below I’m using a 20x20 tile near the player, then a 10x10 for medium distances, and finally a 4x4.
Also, all the updating, moving and refreshing cycles are done in coroutines, so it never lags the game (although it’s kind of a tradeoff, since updating also takes a while longer to complete). The system keeps track of how much time it has spent on a given loop, and if it exceeds the predefined threshold, it yields until the next update cycle.
Performance wise I can say it’s going relatively well… It draws the entire 19x19 tile setup in 0.2 seconds, and everything else is done in the coroutines, so they don’t really weigh much at all… My dev rig isn’t exactly an average spec machine, so it’s possible this will perform worse in lower-spec computers… but I expect it to have a reasonable performace in any case.
There are a couple of issues still, though…
The tiles need to average their normals with their neighbours, to prevent hard edges where there shouldn’t be any… The thing is that, since the tiles shift around to remain centered, finding the neighbours isn’t so trivial as adding one to the index… I’ll probably have to maintain a reference map so I can retrieve the neighbours…
Also, I have to find a way to generate a spherical world from these tiles… that’s probably gonna require some major restructuring, and I’m scared just to think of it :shock:
Anyways, let me know what you think
Cheers
EDIT: Fixed image link… hopefully