Thursday, November 17, 2022

Weird worlds

Suppose we want a planet that looks something like what Mars might look like if it had water and life. Such a world has no tectonic activity, so there are no continental plates and no mountain ranges like there are on Earth. How do we make interesting terrain?

The obvious place to begin is with the trusty diamond-square algorithm, which, like the more widely-used Perlin Noise, can give us a randomised height map of this kind:

Stick in some sea below a certain elevation and we get this:

We've seen maps of this kind plenty of times already, of course, and we've also seen why they're not really suitable for world maps. There isn't proper structure to them - land and sea (and different elevations in general) are spread more or less evenly throughout the world.

Well, in fact that's not completely true - you can see on the map above that there's an area of ocean just left of centre - and this is because my diamond-square fractals are rather more complicated than usual. The parameters by which the elevation may be changed vary throughout the map, giving it a bit more variety than you would usually find in such images. If we increase this effect, we get areas where the image is more blurry:

That adds some variety, but it doesn't really make for a realistic map. Luckily there are more techniques at our disposal. One of the simplest but most effective is domain warping. I used this previously in Undiscovered Worlds to create noise at the local level, but subsequently got rid of it in favour of a more effective method for that purpose. But now let's bring it back! Briefly, we create three fractals: one as the source image, one to represent X-axis warping, and one to represent Y-axis warping. Each point on the map is then taken from the corresponding point on the source image, but displaced according to the other two fractals. We can easily control the strength of the warp by multiplying the two warp fractals by a constant.

Applying this to the last fractal shown above, with strength=20, we get this:


And strength=80:

This is starting to look pleasingly weird! Note in particular how this technique creates ridges and valleys as it pulls the image about. This could make for interestingly alien-looking terrain.

We can also do another warp on it after the first is finished. Here's what happens if we do a warp of strength=80 and then another one of strength=60:

Even weirder! This effect is probably best used at relatively low strength, but by varying both this and the original warp we can get a variety of interesting terrain that doesn't look like the same old noise.

Another technique is to exaggerate the difference between peaks and valleys. If we read the elevation as varying between 0.0 and 1.0, and simply multiply each point's elevation by itself, we can do this easily. This effectively lowers all of the elevations, but the lower an elevation is to start with, the more it is lowered, causing slopes to be exaggerated. If we do this to the 80-strength single-warped image, we get this:

There's one more step we can take, which is to create a fractal with a very low level of detail, like this:

We can then multiply everything in the terrain by a fractal like this, thus forcing the appearance of large-scale areas of relatively high or relatively low elevation. Not only that, but we can use a similar technique on all of the effects we've tried, to vary their strength throughout the map. That can give more variation across the world. Here's the end result:

Here's part of it enlarged, so you can see the gnarliness in more detail:

I think that's a decent start for an alien-style terrain without too much effort.

One other thing needs to be considered, and that's the ocean. Using a mask to reduce some parts of the map, and also squaring the elevations to get more sharply defined peaks, tend to produce maps that are mostly sea. There's nothing wrong with that in itself, of course, and it's what we'd want if we were making Earthlike maps, but with these ones we don't want them all to be like that. So we'll lower the sea level by random amounts as well. That means we can get worlds with smaller seas, or that are mostly land, like Titan.

For our Earthlike worlds, we use a simple flood fill routine to identify the largest body of water in the map and then turn any separate bodies into land, because we want to have a single ocean. But this wouldn't be appropriate for these more alien worlds with less water, where there could easily be multiple separate seas. However, we don't want really small seas, which will always form when you declare any point on a fractal that's below a certain elevation to be water - as you can see in the last image above, in fact. That does seem unrealistic, and too obviously caused by over-reliance on fractals. So we do want to remove seas that are below a certain size, without necessarily having just a single ocean.

We can randomise what the size threshold is, for different worlds. One side effect of this is that if the size threshold is large, the algorithm may remove all sea altogether, resulting in large expanses of mostly flat plains that contrast with the high land from the fractals. I think this gives a nicely lunar sort of effect:

So what happens if we turn the climates back on? I had to do yet more work on the climate model to allow it to handle worlds without any sea. Briefly, some rain can still fall on such worlds, though not much, and mostly where the land slopes; again, think of Titan, which has no oceans - only methane lakes covering a relatively small proportion of its surface - but which does have methane rain and even rivers flowing into its lakes.

With the climate turned back on, we can get some interesting results. For one thing, the large areas of high land that this new generation method creates tend to lead to extensive snowy regions even in equatorial latitudes (on normal temperature settings). Consider this medium-sized world:

Here, an immense system of linked lowland plains winds around and between areas of towering highlands. The relief map looks like this:

The highlands are uniformly frozen, even though this world has an average temperature only 3°C lower than Earth's, while the lowlands - which are still fairly highly elevated - are frozen in the higher latitudes but warmer elsewhere. Most of this world that isn't frozen or tundra is either hot or cold desert, as you can see from the climate map:

But pockets of rainfall exist, mostly around the steep transitions between highlands and lowlands (even enough for some small patches of rainforest). As result, there are rivers, which flow into a number of saltwater lakes:

If you compare the rivers map with the elevation or relief maps, you'll see that some of these rivers are winding their way a tremendously long distance through the lowland system before ending in a lake (or disappearing off the top or bottom of the map, which is allowable in normal worlds but looks rather weird here, so that will need to be dealt with). Despite their length, the arid nature of the world means these rivers are only modest in size. Here are a couple of the larger salt lakes, near where a series of cliffs leads up to the frozen highlands:

And here is a patch of rainforest along the edge of another part of the highlands:

As is probably evident, I think this is a pretty interesting world. It's very different from the Earthlike worlds that UW has been generating to date, but it's not simply a map of random noise either. It's a plausible-seeming alien planet with meaningful large-scale geographical features, and one can imagine the kinds of civilisations that might exist in these strange conditions.

However, the complete lack of hills and mountains does mean that the regional maps look pretty uniform much of the time. Although the landscapes are weird, they look a bit bland compared to others that UW can produce, and there are even some dreaded grid artefacts making themselves known. So we need to think about what new kinds of smaller-scale features might be found on worlds of this kind, and how to make the regional maps look a little more interesting.

Monday, November 14, 2022


I've always planned Undiscovered Worlds to be not simply a map generator but a world generator, with - ideally - a quasi-realistic sci-fi sort of feel. At the moment it's creating maps of what are effectively alternate Earths. But I'd like to create more variety in the kinds of worlds it can create maps of.

To some extent this has already happened. When I rewrote the continent creating functions, I didn't delete the original ones. They're still in there as a possible variation, so while most worlds use the newer version, a few will still use the original. The original's not as good, but it's worth keeping for the sake of variety.

So in that spirit I've been working on expanding the range of possible worlds that UW can create.

First, worlds of different sizes are now possible. In addition to the roughly Earth-sized worlds that already exist, you can have worlds with a quarter of the surface area (roughly Mars-sized) and worlds with a sixteenth of the surface area (roughly Moon-sized). (Other sizes aren't really possible thanks to the limitations of the diamond-square technique, which I use extensively.)

With worlds of varying sizes come variations in gravity too. In fact gravity can now be anything from 0.05g to 10g. On low-gravity worlds, mountains are taller and wider, while river valleys are wider but shallower:

On high-gravity worlds, by contrast, mountains are small and river valleys are narrow but deep:

In addition to size and gravity, there are several new variables, which mostly affect the climate in various ways:

I've extensively rewritten the climate simulation (again), which really ranks up there with lakes as one of the most gruelling elements of this whole thing. The problem with climates is that there are so very many moving parts that any changes to one element can have knock-on effects with all sorts of other things. This time, I had to rewrite it so that it could handle (with sufficient plausibility, if not real accuracy) not only Earthlike conditions but a huge range of other possibilities as well. Still, I think it worked out just about OK.

The simulation can now handle quite dramatically different circumstances, which can be caused by variations in the planet's orbit. Obliquity, for example, refers to how tilted the planet's rotation is compared to the plane of its orbit around the sun. Earth's is roughly 22.5 degrees, and this is what causes our seasons, as different parts of the planet are angled towards the sun at different times of year. Relatively modest changes to obliquity can yield dramatic results. At low obliquity, there is little or no seasonal change throughout the year, which means no continental climates or subpolar regions, and you tend to get lots of rainforest, deserts, and temperate oceanic regions. At higher obliquity, the seasons get more and more dramatic. Not only that, but as the obliquity gets higher the poles get hotter, because they are spending more of their time pointing towards the sun. At the highest obliquities, the poles are actually hotter on average than the equator, though they experience huge shifts in temperature throughout the year. The equator, meanwhile, has two summers and two winters in every year.

Here's a world with high obliquity, showing permanent sea ice at the equator but not the poles!

Eccentricity, meanwhile, is how elliptical the planet's orbit is around the sun. Low eccentricity means a roughly circular orbit, while high eccentricity means a highly elliptical one like a comet. Earth has an extremely low eccentricity, which means that it is roughly the same distance from the sun all the time. But a planet with a high eccentricity would experience hotter temperatures for part of the year, as it comes close to the sun, and then colder temperatures as it swings away. Moreover, because planets in such orbits move more quickly the closer they are to the sun, the hotter part of the year would be shorter than the colder part, with this effect being more noticeable at higher eccentricities. So with high eccentricities, you get global "seasons" - but the "summer" is shorter than the "winter". To make things more confusing, the "seasonal" difference is greater at the equator than at the poles, rather than the other way around as with seasons caused by obliquity.

Things get really confusing if you raise the eccentricity and the obliquity. Depending on how high you set them, you get a world with seasons similar to our own but where one hemisphere has a short, hot summer and a long, cold winter, while the other has a short, mild winter and a long, mild summer (Mars experiences something like this, to a moderate degree). Here's a world like that:

Finally, all of these new variables are controllable by the user as well. It's now possible to create custom worlds where you specify the size of the world, the approximate proportions of land and sea, and the variables shown above. So you can create worlds with really exotic climates if you want to, or specify worlds with exactly the same variables as Earth or only slightly different, or have an ice-bound moon with an ocean below the surface.

There are still some wrinkles to iron out with all of this, and then the next plan is to create some new terrain types that might be appropriate for worlds that don't resemble Earth so closely.

Saturday, August 13, 2022

Undiscovered Worlds now downloadable

After much additional tinkering, I've posted the latest version of Undiscovered Worlds for anyone to try out. Full details are on the first post of the blog. Many thanks to Frank Gennari for his help with bashing this into something approaching presentable shape!

There are still various bugs, so approach with caution, but I hope people find it interesting to play with!

Tuesday, June 14, 2022

Even smaller update

Just a quick post as I don't want to leave the somewhat downbeat previous post as the last one for too long... With some much-appreciated help it's become clear that NanoGUI, which I was using for the UI, is ridiculously difficult to get working in different development environments. So I've given up trying to do that, and I'm rewriting using Dear ImGui instead. This is a shame as (a) it means I have to rewrite, and (b) NanoGUI is so pretty, and I will miss it; but it's worth it to get the thing to work properly. Dear ImGui is much more intuitive to use (and vastly better documented), so I'm hopeful that this shouldn't be too monumental a task, but we shall see!

Sunday, March 20, 2022

Impasse and need for help!

More bug squashing! This included three entirely distinct lake-related bugs that all coincided in a single regional map. I really hate lakes. I've also made a few more refinements along the way that are too minor to detail.

A couple of recent screenshots:

Anyway, what this means is that I've pretty much finished this stage of Undiscovered Worlds. As I said a million years ago, I envisaged a long-term project in three stages:

  1. terrain generation
  2. flora and fauna generation
  3. civilisation generation

I don't know whether I'll ever get to (3) - and really it's the one that interests me the least right now, especially as so many other people have done it so well - but I do think that (1) is pretty much done now. It's certainly not perfect but it's as good as I can plausibly get it, at least in the foreseeable future.

So I'd like to release this now. I'm planning on putting the source code up on GitHub so that anyone can tinker with it and make it better. I'd also like to make executable versions available so that less technically minded people can use it too. However, there are a couple of problems with this:

  1. The project uses several external libraries: NanoGUISFML, and stb_image. Somehow I've installed these in some eccentric way that allows my code to work fine on my computer, but I can't build an executable that will run anywhere else, because it won't incorporate at least some of these libraries. The fact that I can't manage what ought to be a fairly elementary part of development should indicate my skill level at this sort of thing.
  2. This project is written in C++ using Xcode on a Mac. Even if I manage to solve problem 1, I'll only be able to create an app that runs on Mac. It would be nice to be able to make it for Windows and Linux too, but I don't know how to do that.
So I need some help! - from either somebody who can walk me through solving these problems, or, perhaps more plausibly, somebody who can build the executables themselves if I make the source code available. Is there anyone who might be willing to help?

[EDIT] I've put the source code on GitHub - you can see it in all its ghastly glory here.

Sunday, January 30, 2022

Small update

I've been doing a fair bit of unglamorous bug squashing and general tinkering. Much of this is behind-the-scenes stuff that just makes the code work a bit better and hopefully crash less often, but there are also some visible effects, mostly at regional level:

  • Some river-related bugs have been removed. Plenty remain, naturally.
  • I made some additional tweaks to the climate simulation, to reduce the amount of desert slightly.
  • A long time ago I implemented canyons, which work by creating wide areas of the map where the land is raised up higher than usual around the river valleys. Somehow the effect of these was much reduced when I ported the project over to its current form. I've now made it much stronger and more noticeable.
  • In addition, some of the smoothing routines applied to the regional terrain tended to widen canyons in an unpredictable way which made them look weird. I've stopped that, so now river valleys really look like river valleys.
  • I worked out why - as noted in the previous post - some coastlines had acquired extravagant islands (it was to do with changes to how the sea bed is generated), and toned it down so it only happens sometimes.
  • I also removed a tendency to create lakes right by coastlines, noticeable in (among others) the last image here.
Here are some pictures, in which you can see the river valleys more clearly in some areas, as well as varied coastlines. I think the texture of the land is looking pretty nice now:

And as a bonus, here's an epic river system:

Tuesday, January 4, 2022

Grids revisited

A while ago I posted about a problem with grid-like artefacts cropping up. These are an unavoidable side-effect of relying so heavily on the diamond-square algorithm for generating detail on the regional map: that algorithm is known for a tendency to look a bit grid-like.

Back then I came up with a rather elaborate solution for this problem which involve blending the terrain with a warped fractal. However, while this did eliminate the artefacts, I found that it tended to flatten the terrain too much and remove much of its texture, so I turned it off. That still leaves the artefacts problem.

Here's an uncommonly severe example:

While it doesn't usually look quite this bad, even occasional examples as horrible as this are unacceptable. I've found that this problem usually occurs in coastal areas where there are lots of rivers and a few ranges of hills or low mountains, so this is a typical sort of map to have this problem.

It occurred to me that rather than messing about with adding interference to the terrain to try to mask the grids, there could be a much simpler method. For each tile, I take a random point on each side. I then mark out a circle (with a radius equal to the width of a tile) centred on each point. Then I simply rotate that circle by a random amount. The rotated circle is progressively blended into the original (the closer to the centre it is, the more strongly it's the rotated version; the closer to the edge, the more strongly it's the original). And that's pretty much it. This is done after the basic land elevation is generated, but before the hills and mountains are added, so they aren't affected. Also, for obvious reasons we don't alter any points that are on - or bordering - rivers or lakes, or sea.

Much to my surprise, this not only worked exactly as planned the very first time I tried it but yields what I think are really nice textures for the maps. Here's what the area above looks like with this technique in place:

This is clearly a big improvement - the grid-like features of the original are almost entirely obliterated, but without making the terrain flatter and less interesting. Instead, the texture is more finely grained, while still keeping the general areas of high and low ground in place. (And don't ask me where all those islands have come from - I must have made some other change that caused those, but I can't think what.)

Here are a couple more maps to show off this general look:

As you can see, the new effect is most noticeable in the green areas with high rainfall and more rivers, but it shades nicely into the more arid regions and mountainous areas which are both sometimes associated with the more terraced look you can see in the last two images (and which is applied after the rotation effect). So we've got a bit of variety in the appearance of our maps, which is always good.