As I said at the start of the project, I’m not aiming for realism. I’m looking for whimsical, retro, and fantastic. My goal is to have something interesting, as opposed to something realistic.
I mentioned before the detail layer of the terrain. It adds the continuous rolling hills across the world. These hills are irregular, but for the sake of illustration let’s imagine they are perfect sine waves:
These hills produce a landscape that is attractive, but lacking in variety:
That’s kind of nice to look at, but seeing that stretch all the way to the horizon would be boring. We need to mix it up. However, we can’t do anything too fancy. Anything we do here is going to be happening while the game is running. We don’t have time to muck around with erosion or operations that need to analyze large sections of terrain. We need something cheap and fast which gives attractive results.
Let’s try messing with the detail map. If we take values above a certain height, and invert them, we can easily turn hills into craters:
Which ends up looking like this:
So, occasionally we can flag a region to produce craters. We have to keep them rare, obviously. This is exceptionally “cheap” from a processing standpoint. It’s just a filter. As points are created, it checks if the point falls inside of a region with craters. If so, it does a couple of very simple math operations. No need to check neighboring points or perform some sort of recursive operation. Set a flag, do a subtract. Boom. Done.
There are a lot of these sorts of operations we can do. We can take values above a certain point and pull them up even more. This…
Ends up giving us landscape shaped like this:
If we take values from a narrow range and pull them down…
We can produce cracks in the earth:
You get the idea. A couple of simple flags and some basic math and we can make a huge variety of different shapes.
Also, if you squint at the screenshots you might notice it’s displaying information like “moisture” and “temperature”. Those don’t DO anything yet, of course. Those are placeholders for the climate system I have in mind. Let’s work on that now.
Currently the program generates only dry land. If you keep going, you eventually end up at the edge. (The world is only a couple of kilometers right now, although I can make it much bigger by just changing a single variable.)
I like the idea of making the world a single continent, so that the “edges” of the world are all ocean. That’s so much more pleasing than the Oblivion / Fallout 3 / New Vegas approach of “invisible wall”. (Fie!)
So, I make our island by measuring the distance from the center of the world. Elevations fall off on a curve. I have it generate a little map of the place. Check it out:
Note that each pixel represents a single region, which is a large-ish area. (I change this often as I experiment.) Right now regions are 48 meters on a side. The green ones show what grass color is used in the given region. The beige ones are obviously coastal areas, where points close to sea level will have sand applied. Blue is ocean, darker = deeper.
This stretch of coastline represents two regions – two pixels in the map above. The water itself is a super-simple single polygon that stretches from one end of the world to the other. I just put it there so I could see what I was doing. I don’t know what the ocean will look like in the final product, although I’m reasonably sure it won’t look like a swimming pool.
Aside: In an earlier entry Tizzy said that not all coastline should be sandy beaches. Using the detail-modifying tricks I talked about earlier, this is no problem:
Anyway, I imagine you have noticed that in some cases, natural continents and islands come in shapes other than geometrically perfect circles. Well, remember that cool elevation data I created back in step one? We can use that on any scale we like. I can just add it to our circle island and get something like…
If I want a different island, I just need to draw from a different spot on the detail map.
Now we want to add some climate. For climate, we have two goals:
- Variety. We want a bit of everything. The world should be visually diverse.
- Visual plausibility. We do NOT want to simulate an entire planet of tectonic plate shifts, jet steams, and ocean currents. At the same time, we don’t want to see a foggy swamp directly adjacent to a Sahara-style desert, or tundra next to a tropical beach.
So what we need is a very simplistic simulation, just something to give us numbers in the right ballpark.
We can assume the wind comes from the west, carrying moisture from the sea. The further you move in, the drier it will be. I average out these results (blur them) so that coastal regions can be wetter and so you don’t get overly abrupt changes in climate. Here is a map showing the moisture. (Green = wet. Red = dry.)
I add a few spots on the map to block rainfall. (Eventually these will be mountains.)
Now we calculate temperature. Arctic at the top of the map. Tropical at the bottom. (We’re going for variety, not realism, remember.) The ocean has a moderating effect on temperature.
In a later version I might randomize the direction of rainfall / temp, but this should work for now.
The next step is to take this climate information and put it to use. I start with making the grass color trend towards the yellows as it gets drier. It’s not an absolute shift. You’ll still find green in the desert, but I want reds and yellows to prevail. (At least, when it comes to grass.) Wet areas should be deep green.
Next up, I have things trend towards pale green / blue-green in colder climates. I doubt this is strictly correct, but it seems to look right.
Now that we have our data, we can put it to use.
Right now, the program has some hard-coded thresholds for slopes. Once they get too steep, it will color the ground as dirt instead of grass. A little steeper, and it changes from dirt to rock. If I lower this threshold as it gets drier, then arid climates will look like barren scrublands:
In hot, humid areas we can have deep greens:
I tried adding snow. The colder it is, the more grass gets replaced with snow.
That still needs work. Part of the problem is the golden yellow sunlight shining on the snow, making it feel “warm” here. I’ll need to shift the palette to blue as it gets colder.
Unrelated, but while zipping around looking for screenshots I found this bay, which I thought was pretty cool:
There’s a lot of work to do, but I’m happy with how it’s going so far.
Here is a 13 part series where I talk about programming games, programming languages, and programming problems.
A Star is Born
Remember the superhero MMO from 2009? Neither does anyone else. It was dumb. So dumb I was compelled to write this.
WAY back in 2005, I wrote about a D&D campaign I was running. The campaign is still there, in the bottom-most strata of the archives.
Programming Language for Games
Game developer Jon Blow is making a programming language just for games. Why is he doing this, and what will it mean for game development?
Dear Hollywood: Do a Mash Reboot
Since we're rebooting everything, MASH will probably come up eventually. Here are some casting suggestions.