With this tool it started out as exploring procedural generation that I had delved into previously (just with some basic geometry). Wanting to expand into some larger terrains and more complex shapes, I decided to explore some compute shaders to utilise the GPU in helping the optimisation of this process.
Starting off looking into the science of tectonic plates, I wanted to create a simulated environment showing the creation of terrain through tectonics. That became quite a divergence from the intended purpose of this project as I was delving into several heavy research papers on the topic. Taking a step back to look at it more simply is how I developed this tool.
I arrived at the concept that what I wanted to start with is a set of "plates" and populate them from random points. I setup a list of scriptable objects of plate data to keep track of:
The Vector2 coordinate of the random point
The elevation of the plate as a float
A random colour (For visualising like the picture to the right)
A Vector2 direction
To make the plates from these random points I implemented a Jump-Flood fill algorithm within a compute shader. Once the random points are generated I also defined an array containing the amount of empty plate scriptable objects as there is pixels in the size of render texture I was using to generate the height maps for the unity Terrain component. Fed into the compute shader with the list of plates the algorithm fills in these empty points and and generates the voronoi diagram that you see to the right.
Once I have the voronoi diagram, to make it more of a smoothed terrain I process all of the elevations of the list of points within the compute shader. During this processing I have each pixel's elevation become an average of its neighbours. Each are remapped to be a value between 0-1 to generate the height map you see to the left. (It's actually the height map of the voronoi diagram above!) The 0-1 float value is necessary for the Terrain component within unity other wise it just is a flat component.
Now with most of the calculations all being solved on the GPU through the compute shader, generating some interesting landscapes is as quick as pushing a button.
To make it useable with Unity's Terrain Component I developed a fresh inspector look for the tool. The Terrain component's inspector view is rather complicated and has a fair bit of excessive controls for what this tool does so I limit it within the generator to the bar minimum, with tooltips explaining each section.
To help access as well, I made it have the ability to not be randomised for more control of the landscape being generated. If there is not a terrain object contained in the scene it will generate one.
Other values that the tool allows the user to define values for are:
The Resolutions of which sections of the Terrain component need with tooltips describing what each section is for
Amount of plates being simulated.
Min - max values for elevation (Can be any integer value but will be remapped to 0-1 for the height map)
A height scale based on high the terrain will be in world units. The Y axis values of Unity's terrain system are the height map 0-1 values multiplied by this value.
A smooth value which is how many times the system will run the initial average of neighbours elevation function.
Whether to save out PNGs of the coloured map and the height map texture.
The thing with tectonics, they shift terrain about. Getting that working has been a goal to which I have had some successes with. It is currently updating by moving the points according to their plate's direction, checking the point that exists there and resolving it based on rudimentary tectonic plate definitions:
If the new position is contained on the same plate as the current position, the elevation is just moved to that point.
If they're colliding plates there is some transference of the elevation as a difference between the two points.
If it checks that the next position is on the same plate and that going in the opposite direction would mean that plates are separating then it lowers a little bit behind it forming a crevasse
I am planning with this tool to expand my knowledge further on procedural terrain generation with this too. I would really like to remove it from Unity's terrain system and generate the actual mesh as well. I have had success with this on a smaller scale and I am looking into mass generation and how best to connect them so that it isn't one large object rendering constantly.
I would also like to get a bit more of the actual tectonics happening, while the basic simulation is happening, things like fault lines and volcanoes are not simulated.
In addition to that I would like to add other erosion forms like water