Feasibility of generating complex terrain at onset

Hey, I was wondering if anyone has attempted complicated terrain generation in unity. I know there are floating point issues with terrain size, so I’m looking to generate a fixed size terrain, but do it all at initialization so the player can walk level chunk to level chunk and just load in the data. I’d like to generate the terrain on many layers, i.e. base terrain, erosion, vegetation, road networks, rivers, settlements, etc etc. Obviously a lot of work, things that would take too long to do on the fly, but could intense terrain generation like that be done at start for large terrain (something like 20km x 20km)?

It seems like there might be memory issues, even with cutting the terrain into chunks, but I’ve never attempted any generation this large so I’m looking for some pointers.

By doing it on onset, you can take as long as you want. Code it well, and you could have the player doing other stuff while it generates (character selection, ectect).

For massive terrains - you’re going to need some way to offload the data from memory to the harddrive, but once you have that you can start doing a lot more complex things. Eventually you will hit unity’s 32bit limit, but at 2gigs that is a shitload of data, and there’s definitely ways around that as well.

There are many, many engines that have procedural road generators - a simple tool that lets you plot a road and than it places it on the terrain. I’m sure there are papers on this - you could use it to instead of storing road data on terrain generate the roads (and terrain deformation) when the terrain is needed ingame. Same with buildings and towns.

You may have detail at like 32meters for a 20kmx20km, but for towns or landmarks you obviously need more detail. So some kind of splat system would be needed. Separate chunk of information that is used when the terrain is brought up for gameplay, hooking into when random detail is added.

Lastly, a thing a lot of terrains do is generate procedural noise for detail.

Good luck, I’m pretty bad at programming but I’ve tried several times at this. The terrain part wasn’t hard, it was the natural order of things. Rivers, roads, bridges, towns, ect.

About the floating point issues…you get 7 digits of precision. So ifyour object coordinates are less than 10k, you get 4 digits for the whole part and 3 for the fractional part. That allows you to place things at .001 meter precision. Thats very precise.
If you go past 10k, but less than 100k meters, you get precision down to the centimeter. That is still pretty precise! I would think that would give you plenty of distance, but still good precision?

Could I use a database with a table for each chunk of terrain? Then in each table I have rows with object positions and states so that whenever a chunk is loaded it can read the table to see where the buildings and such should be place?

You sure can. I would have:

One queue (Save Queue) for item information to save to the database.
One queue for items that need to be drawn, loaded from the database. (Load Queue)
One thread that saves information to the database from the save queue, and it also loads information into the Load queue.

Main unity thread monitors the load queue for gameobjects to instantiate to the scene.

Your data class would look something like:
Class ObjectData
{
public int Id; // Unique item id in the database.
public Vector3 position;
public float YRotation; // If you only rotate things on the Y axis. Otherwise, you can store all three angels.
public int Model; // Having a dictionary that links model number to the actual prefab would be handy.
}

You can use a dictionary<Id, GameObject> to track which gameobject belongs to which id, when you instantiate them in Unity.

You certainly can generate geometry fairly quickly at runtime, but you have to remember also that it has to be pushed to the graphics card and there is a bit of a bottleneck to that… you can’t expect to create many thousands of triangles and multiple meshes and have them appear instantly, so you’re going to have to split it up into smaller tasks and upload in batches over the course of time while something else is being shown to the user. It you balance it carefully they’ll never know it was generated in the background.