How I (try to) create entire, scientifically realistic worlds, with MATH!

Published May 04, 2017
Advertisement

UPDATE: I ran a test with more realistic colors, crudely applied. Before reading, view the results here (click to enlarge)!

Someone recently responded to a post of mine by asking if they could see my code. This sent me into a deep existential conflict! Fact is, I am a huge proponent of open source. I believe it to be the wave of the future and the only way that the digital part of our civilization can progress. But I also don't want to give away all my secrets :(

Instead, I sort of picked a middle ground. It's a bit of a copout, but there are a few reasons why I would rather not just post a thousand lines of code. Firstly.... mine. Mine mine mine mine mine. But seriously, I am a bit protective, because I know how easy it is for someone from the outside to scrounge forums and blogs for code to snatch. I've seen it before, and I bet others in here have horror stories of people presenting copied code as their own. I don't like that. Secondly, the code is a mess right now, and much of it only barely works. I'd rather not spend too much time discussing or, gasp, explaining code that is poorly put together and will soon be obsolete. I don't like to share what I can't defend honorably. And thirdly, I really like to discuss the ideas and science behind it much better, and if people get the code, they want to discuss that code, instead. And IIIIII dun wanna!! In time, though, I hope to open up more. Share my feelings, talk about my dreams and such. *group hug*

And now........... SCIENCE (biatch)!!

The images atop this entry are from the latest test run of the world creation engine. They show mountain ranges, rift canyons, cliffs, and a variety of ways those things interact with each other (the typical one: You run face first into a sudden wall of rock). The entire thing is based on tectonic plates, which is the accepted theory of geology on how continents move over time. To make a long science short, our planet's surface is broken into many distinct 'plates', which are moved by, among other things, molten rock moving around beneath the planet's surface (the semi-liquid 'mantle' under the solid 'crust' that we live on). Where they move into each other, they push their material up to become mountains and other raised features. Where they pull apart, 'rifts', deep cracks in the surface, form, until molten rock from beneath it rise up and cool to become new rock on the edge of the plates. Where they just slip by one another, the plates cause earthquakes due to friction, but this is not simulated here, because this particular bit of world generation creates a static, unchanging planet. For now.

So how does one create a planet of tectonic plates and have them shape the surface? First, let's divide the surface into plates. Simply generate a number of random points on the surface. We call these 'cratons', the name of the first hardened pieces of rock that long ago formed the plates. Whichever craton is closest to a point on the surface, that point is assigned to. The points assigned to a craton make up that one tectonic plate. Easy enough.

Next, how do we make things form along the edges of a tectonic plate? First, we set a maximum distance of the effect. Then we have every point on the surface check not just which craton is the closest, but also which one is the second closest. The closer the distance between the point and the closest craton matches the distance between the point and the second closest craton, the more we raise the point above the surface. That means that points close to mdiways between closest and second closest craton get raised a lot, while points farther away continually get raised less. The result: Basic mountains. The greater the maximum distance of the effect, the flatter (wider, not lower) the mountains become.

But that gives us mountains along all tectonic edges. We want some places to meet as mountains, but others to glide past each other, and others yet to pull apart and create deep rifts! How that??

Firstly, every craton gets a vector that defines its movement over the last millions of years. Once it has that, we can take the dot product of that vector against the vector we get from the closest craton to the point exactly between it and the second closest. In more layman's terms, we check how closely the plate's (craton's) movement matches the direction from it to the point right between the two plates. The greater the result, the more the points on the surface rise (i.e. you multiply the dot product with the amount of rise). And since a craton moving away from the other craton means a negative result, points that used to rise will drop, creating rifts, like valleys.

It took a little while to put all these things together, put for basic tectonics, they seem to work quite nicely. I am now trying to figure out how to make mountains and valleys more interesting, without compromising the simple but scientifically based generation. In real geology, converging plates (plates that move into each other, creating mountains) crack and splinter at the edge, making pieces of them shoot up at different rates, creating not a single straight line of mountain, but jagged ridges and splintered paths of mountain ranges. Rifts, on the other hand, have chunks break off at the edges, forming a kind of 'crumbling stairway' effect, rather than just a clean slope. And where plates slide along each other, they snake up and down against one another, creating weird patterns of rock shooting up and then dropping down, like two rags tangled up in one another. I am hoping all of this can be boiled down to a single, coherent algorithm, much like the stuff above. But science is a cruel mistress, and she will no doubt have her wicked way with me.....

Other than posting long sections of code, I am very open for questions on this, including thoughts on geological effects I have not yet implemented. The practice of converting science to computer algorithms is hard, but amazing to be part of, and I love discussing it and learning the perspectives of other people! I hope before long to have a more solid methodology for converting science into games, but for now, I must take it bit by bit, making each work the best I can. Once it truly clicks, I will let you know..!

7 likes 4 comments

Comments

Awoken

OOhh, I like it. Looking good man. I can see what I assume to be tessellation in action.

O.k, here's something I'd love to see in a space game, if you're doing continents, what do you think about doing volcanic activity? That would be bad ass.

May 05, 2017 02:09 AM
DaSutt
Looks really interesting. A few years back I read something similar which was only 2d https://www.gamedev.net/topic/623145-terrain-generation-with-plate-tectonics/ . I am assuming the points distributed on the surface are stationary and only change their height value? If so do you have to update their nearest craton each iteration? Structural differences inside of plates would also be interesting. So that you could simulate something like the Himalaya where a large chunk breaks of and is moved up.
May 05, 2017 07:10 AM
Embassy of Time

OOhh, I like it. Looking good man. I can see what I assume to be tessellation in action.

O.k, here's something I'd love to see in a space game, if you're doing continents, what do you think about doing volcanic activity? That would be bad ass.

I WANT VOLCANOES!!!!! I want them so baaaaad.... But I want them to be rooted in real volcanology, which is why I've actually been studied that, along with the tons of other sciences I have or will implement in the game. Right now, I am learning about volcanic island creation, bringing a lot of my own physics knowledge to bear on the amazing ways volcanoes work. Just knowing how Hawaii was formed blew my mind. Then again, the things I learn these days for the game has serial-blown my mind all over the place! I should be starting on hotspot volcanoes today, but I don't know how long before I find a way to implement subduction-made volcanoes, as in the Pacific Ring of Fire.

And yes, the tesselation seems to be working nicely. The one problem is that it is sphericaal 2.5D, i.e. it can go up and down compared to the center of the planet, but it cannot tesselate based on height. So while long stretches of flat 'grassland' (it's not real grassland, just default colored green) is heavily tesselated, near-vertical cliffs are not. Until I find my true 3D tesselation method (I am researching metaspheres, but everything seems to be built around the marching cubes algorithm, which seems inadequate for a planet IMHO), flatland will tesselate more, raised slopes will tesselate less :/

May 05, 2017 01:11 PM
Embassy of Time

Looks really interesting. A few years back I read something similar which was only 2d https://www.gamedev.net/topic/623145-terrain-generation-with-plate-tectonics/ . I am assuming the points distributed on the surface are stationary and only change their height value? If so do you have to update their nearest craton each iteration? Structural differences inside of plates would also be interesting. So that you could simulate something like the Himalaya where a large chunk breaks of and is moved up.

I'll dig through that link for anything I can use, thanks!

The surface points only vary in elevation, yes. Like I mentioned in the comment I just wrote for Awoken (right above this one, I believe), I have not yet settled on a true 3D method of substance creation. Marching cubes algorithms seem lacking, and they are apparently the industry standard (I used them before, they are excellent on truly flat land, but the planet is spherical on larger scale, which is bad). I am fiddling with an alternate method of metaspheres, allowing me to create modifiable masses of any size and shape, but it takes a lot of reimagining, a lot of math, and will require a lot of experimentation, so I stick to a spherical 'height map' for the time being.

However, cratons are completely static. Points are raised and lowered based on a set of calculations based around the position of the two nearest cratons (which creates the middle-line of mountain, valley or other running between them) and the vector for imagined plate movement. Points basically 'fake' tectonic movement in a way inspired slightly by how water fakes movement during non-cresting waves (or people in a stadium fake movement while doing 'the wave', if you get my drift). The impact of the supposed plate movement simply 'runs through' the points and raises or lowers them accordingly. This works well enough that I may stick to it for a very long time....

The structural differences are a biiig to-do on my list. Basically, it will take especially the mountains to a new level, creating fracture zones that raise different chunks in a mountain pattern, rather than the current single mass. But to limit processor time and to keep it available to the on-the-fly tesselation, it cannot be a full-scale simulation. I need to reverse engineer the effect of it into a point-by-point algrithm. I have some parts already noted down (I can drop chunks of mountain closer to the fault line, basically saying "the outer zone rose because the inner zone had some of its rise retracted"), but I need some holes filled in to make it work. And testing. So much testing. One problem is that I don't really know how much of this fracturing is tectonics, how much is magmatic pressure from beneath, and how much is massive erosion. More research is needed!

Keep the ideas coming, btw. I so rarely find chances to discuss this at a real level. Either people know the science but don't code, or people code but don't know the science. Or neither, as most normal people :p

May 05, 2017 01:25 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement