Thursday, May 14, 2020

Better rift lakes

This is what real rift lakes look like:


The old version of Undiscovered Worlds made rift lakes that looked a bit like big fuzzy caterpillars. This was because it used a simple method of pasting blobby templates over the river that runs through the rift lake. The problem with that is that you either make the lake look simply like a wide bit of river or you give it jagged edges. But a real rift lake is like neither of these. It has quite straight, smooth edges. So I thought about how this might be simulated more realistically.

I realised that a better lake coastline could be created simply by drawing the outline first and then filling in the lake inside it. The outline could be drawn using our familiar system of splines, which I've already used to work out the sea ice on the global map and the routes of rivers and mountain ridges on the regional map. All we have to do is identify control points for the splines and then draw a loop connecting them all up. Then we can use a flood fill to mark the whole lake surface within that loop.

There's a problem, though, which is that is very hard to do if we're calculating each tile of the regional map by itself. It's especially hard to do if we're dealing with a rift lake that extends beyond the area of the regional map. How will we know how to draw the outline in one of the tiles that's on the edge of the regional map?

I decided that the solution was to create an array that's larger than the regional map. This, the rift lake map, is bigger than the regional map by ten tiles in each direction. The plan is for UW to scan through this tile by tile. If it encounters a tile that is the start of a rift lake (i.e. the upstream end), it then moves downstream, tile by tile, plotting the control nodes for the outline that correspond to each lake tile. After it's done that, it can simply connect them all up using splines. Then, we can copy just the section of the rift lake map that corresponds to the regional map over and discard the bits that lie outside. This will ensure that our lakes are stable and look the same no matter where we scroll.

That's the theory anyway!

Let's start by putting in some simple nodes and then tweaking. For each tile, we'll have two nodes - one on each side of the lake. The start and end tiles will also have one additional node each, for the ends of the lake. We'll put those just where the main river enters the tile (or exits it, in the case of the last tile). For the other nodes, we'll look at which direction the main river is headed from this tile, and just stick them a bit of a distance away from the river in a roughly perpendicular direction from it. Then draw splines between them.

That yields the following:


The pink lines are (what will become) the rift lake outlines, overlaid onto this river map. Notice, in passing, the horrible forms of "normal" large lakes nearby. I'm hoping that if this attempt at a new way of making rift lake outlines works I might be able to adapt it to those as well. Who knows?

Anyway, obviously the rift lake outlines we have here won't do. They are made of straight lines because I've given no variation at all to the control points of the splines. First I double the number of nodes - each tile now has two nodes on each side of the lake. Then I add some random variation to their location, with the same variation being applied to nodes on each side of the lake. Finally, I adjust the ones near each end of the lake to taper towards the point. That gives us:


This is looking closer to what we want. Now it's basically a matter of adding some extra variation to the nodes so that the width of the lake varies, and allowing the splines to curve by giving (slightly) more variation to their interpolated control points:


I think these are looking pretty decent. Now it's a matter of filling it in with a simple flood fill and then assigning depths to each cell. I do this by drawing a series of large circles, the centres following the line of the main river that flows along the lake. The closer to the centre of the circle, the deeper the lake at that point, to a maximum of the depth that's stored in the global map for that tile. I use the lake shape that we've been drawing as a mask.

Finally, it would be nice to have the occasional island in there. These aren't common in rift lakes and when they do appear they're close to the shore. Adding them is a simple matter: find the shore, move just past it, put some bits of land down.

All of that gives us these:





Not perfect, but a lot better than what I had before, I think.

No comments:

Post a Comment