[Suggestion] Fix the terrain height algorithm

Discussion in 'Planetary Annihilation General Discussion' started by aevs, April 3, 2014.

  1. aevs

    aevs Post Master General

    Messages:
    1,051
    Likes Received:
    1,150
    [​IMG]
    Two planets with seeds 16 and 33 that share nearly identical topology. Even at larger scales, their topology will remain extremely similar.

    As some of you may know, I made a thread discussing similar planets generated by different seeds with the planet generator not long ago. What I found was that the probability of generating nearly identical topology was much higher than expected, especially for larger maps (I 'll get to why I think that is in a second). While this was very interesting and I found it pretty cool at first, the implications of it are that the terrain generator is very limited as it stands, and while there are 2^15 seeds available, there are probably only a few hundred significantly different seeds (it's hard to say without the code), and many interesting terrain combinations are probably impossible right now.

    Before I go into what I think the problem is: I can't say for certain why this is the case, but I have a pretty good idea of what the cause might be. This post is conjecture, but it's conjecture that makes a whole lot of sense with what information I do have.

    Now, it is obvious from testing that achieving near-identical results is quite common. This implies that the total possible variation between planets is actually quite small (practically identical planets can be found in a group of only a few dozen), especially compared to the number of seeds available (2^15). Similar planets at one scale will remain similar at all scales, and so the variation between large planets is reduced significantly from the potential variation of truly random terrain.
    After a bit more testing, it also seemed that planets could be somewhat similar without being identical, and in these cases they often appeared to be combinations of two planets' topology.

    What all this suggests is that the algorithm for terrain height (which is 3D or modified 2D simplex noise IIRC) uses a single permutation table for all planets, and that the gradient vectors are what is set based on the seed.

    Here's a 2D example of how this works (if this is indeed the case):

    Let's say you have 4 different gradient vectors of either limited or of constant magnitude. Every time you use a new seed, these are set to random vectors. Let's say they're vectors R, G, B and W.
    So far so good. Now, the permutation table isn't necessarily even a table here, but whatever the case the results will be something like this:
    [​IMG]
    This represents a 2D grid with gradient vectors R, G, B and W randomly distributed at different grid points. These vectors represent the slope of the terrain at their positions, and the slope between points is calculated based on those slopes. In reality 2D simplex noise uses a grid of equilateral triangles instead of a square grid (which would be perlin noise), but that's not important.

    The problem is that this 'grid' appears to be the exact same for all planets of a given size. With some seeds, green will be an eastward slope, red may be south-west, white may be northward, etc. With others, the direction of these 4 vectors are scrambled, but there are only 4 vectors to scramble. Even if you're trying to use half a million different seeds to generate different combinations of vectors, the actual variation you get out of it is pretty small. You will only get a couple hundred significantly different terrains, and even then many of those will be 75% similar to one-another.
    For an 8x8 grid, maybe a couple hundred combinations isn't that unreasonable. The vast majority of possible terrains you could get from an 8x8 grid aren't possible, however.
    A bigger problem arises when you have a 1024x1024 grid. Now you still only have a couple hundred significantly different maps, even though the map size is very large.

    Of course, the longer the list of gradient vectors, the more variety there will be in maps, but using the same permutation table for all planets will always limit the potential of the terrain generator.

    Well, this post ended up a lot longer than I thought it was going to be, so...

    tl;dr: If you think the planet generator isn't generating as much variety in terrain as it could be, that's because you're right, it actually isn't right now.
  2. nightbasilisk

    nightbasilisk Active Member

    Messages:
    194
    Likes Received:
    103
    I can see something like three approaches to procedural generation:
    • use noise and pray
    • build it using a grid by attaching prefabs with dependencies
    • construction
    • simulate it
    The noise method has the very unfortunate problem of well... looking like noise. There are some really interesting noise algorithms out there if we're talking planet generation, but for the most part sadly up close the results aren't so great, and everything looks different but at the same time it looks very much the same too (ie. noisy). Don't get me wrong the "different but the same" effect can be desirable under the right circumstances, such as "stars in the sky" and "asteroid fields," it's just probably the worst way for planet generation when you actually have to play on said planet.

    The grid+prefab method is kind of okey looking and generally makes sense. You can usually see it in games such as Civilization and it does prevent the terrain from looking noisy or not making much sense. I gave Civ5 as an example but it really isn't necessary to follow the civ5 way of having only a single size, you could essentially have very large groups that are placed as a single entity.

    Construction is kind of like prefab, but more focused on actually having rules. Think of a system that would build a maze or build a city. If you applied the prefab route you would miss a lot of important details such as roads making sense or in the case of the maze there actually being a route to the center and every other route leading to a dead end. You don't really need to have a lot of props with construction method but you need to have a lot more "rules" and complex algorithms, unlike prefab where it can be as simple as "pick random part out of all parts that are allowed to fit on this side of the current piece."

    Simulation is a lot trickier. If say we're simulating a earth planet:
    • you start with a cloud of matter
    • you simulate the the matter forming a planet
    • you simulate potential impacts (ie. formation of moons, etc)
    • you simulate the elements of the planet forming into layers
    • you simulate the crust cooling
    • you simulate temperature variation and ocasionally seed life
    • you simulate the likelihood of said life actually surving
    • you simulate tectonic movement and air cooling
    • you simulate planetary air currents
    • you simulate glacials and their movement
    • you simulate water (ocean currents, effect of rain, etc)
    • you simulate erosion effects
    • you simulate sand movement
    etc.

    As you can tell by the theme of it the simulation method is a giant pain in the ***. Of the top of my head one of the more famous games to actually use "simulation" as part of it's world generation is Dwarf Fortress. Another problem with simulation is that it can take a long time and be absurdly demanding, Dwarf Fortress being one of the more demanding games, even by todays standards, with what is essentially a text interface by virtue of constantly running a complex simulation instead of (what what everyone else does) cheating.
    Last edited: April 15, 2014
  3. neutrino

    neutrino low mass particle Uber Employee

    Messages:
    3,123
    Likes Received:
    2,687
    The terrain generation algorithm uses simplex noise BTW. It's possible we aren't permuting it enough but if you use the same seed you are going to be sampling the same set of noise but over a larger area.

    I'm going to be spending some time soon re-jiggering some of this stuff so I'll have more comments after I've had time to review what we currently have.
  4. aevs

    aevs Post Master General

    Messages:
    1,051
    Likes Received:
    1,150
    Alright, and thanks!

    EDIT: Also, not sure if I was clear enough, but when I said 'similar' in the OP regarding the seeds 16 and 33, I meant similar between them. The terrain changes when you change the planet's size, but if you change both of their sizes, they'll still be the same as one-another.
    Last edited: April 15, 2014
  5. nightbasilisk

    nightbasilisk Active Member

    Messages:
    194
    Likes Received:
    103
    A few questions,
  6. aevs

    aevs Post Master General

    Messages:
    1,051
    Likes Received:
    1,150
    I'm gonna be honest, that algorithm generates pretty bad noise.

    As for 'fractals', I don't see the point. Similarity at multiple scales isn't some inherent feature of terrain, and I really don't understand how 'fractal' terrain is supposed to to be 'better'. With that said, the planet in the kickstarter clearly features swirls of varying scales, and decals in PA feature swirls in a similar way, but unless the plan is for fractal patterns for the sake of fractal patterns (if you want swirls in the terrain, for example) I don't see the point.

    Off topic: my favourite fractal pattern is the dragon curve, which can tile itself in a number of ways, and looks really cool. I've had one as my background for a couple years now.
  7. nightbasilisk

    nightbasilisk Active Member

    Messages:
    194
    Likes Received:
    103
    I know. But really simplex noise is the better choices out there, outside a few of the more funny named ones with higher implementation complexity that escape me at the moment (they dont produce substantially different results so doesn't matter much).

    My point wasn't that it's better, just that regardless of better or worse it would be nice to have different types so that two earth planets for example can feel different. Change a color or two and voila more "alien planet types."

    I was thinking of it as a replacement for height maps, which currently are based on noise unless I'm mistaken. Outside of that and vegetation, I wasn't really implying anything more with them. (Hopefully I'm not misunderstanding them, as I've never implemented them myself)

    Off topic: dragon curve is my favorite as well
  8. stuart98

    stuart98 Post Master General

    Messages:
    6,009
    Likes Received:
    3,888
    Bumpy bump of bumpy bumpyness.
  9. brianpurkiss

    brianpurkiss Post Master General

    Messages:
    7,879
    Likes Received:
    7,438
    [​IMG]

    Thread necro!!!

    I would love an update on this.

    I really want increased terrain height. It looks so awesome and could add an awesome aspect to gameplay.
  10. stuart98

    stuart98 Post Master General

    Messages:
    6,009
    Likes Received:
    3,888
    Bro, read the thread.
  11. brianpurkiss

    brianpurkiss Post Master General

    Messages:
    7,879
    Likes Received:
    7,438
    I skimmed it and a lot of it was stuff I didn't understand.

    What I did gather is that there's something wrong with the height algorithm.

    If it gets fixed, then maybe we could get more height.

    *shrugs*
  12. aevs

    aevs Post Master General

    Messages:
    1,051
    Likes Received:
    1,150
    This issue really isn't related to max height, sorry to say. It can be summarized as "you don't get nearly as much terrain variety as the number of seeds may lead you to believe".
    stuart98 likes this.
  13. brianpurkiss

    brianpurkiss Post Master General

    Messages:
    7,879
    Likes Received:
    7,438
    Don't crush my hopes and dreams!!! :-(
    stuart98 likes this.

Share This Page