Making the Flat Not So Much
A
message from Larry N. on FlightSim.com's Wish List forum pinged a thought about how we handle rivers in FS. Here's what he said:
"While on the subject of flattening, it's wonderful that we have improved resolution mesh (38m and better -- even 9m in a few areas), but that's still coarse enough to leave parts of some rivers with height variations. Perhaps on rivers with "splashable" water there could be a flattening mechanism similar to that for roads. Obviously this isn't needed for the "blue line" rivers, but could be an aid on the ones suitable for landing floatplanes."
Now, you would think this would be a simple issue but in reality we have spent many, many developer months trying to grapple with the non-flatness of rivers. In fact, many of the problems are similar to creating non-flat airports
that I wrote about last week. To understand the issue you need to know we have two types of "water" in FS: line-based (streams) and polygon-based (rivers, lakes and ocean shorelines). Streams are simple and we treat them just like roads. As Larry points out in his post in FS2004 we "chiseled" roads and streams into the terrain so they were spanwise flat. (Now they still cimb and descend hills at alarming gradients but that's another issue for another day.)
The big problem with polygonal water--mainly rivers--is the elevation. Lakes are simple because we can use a single elevation for all the polygons that comprise them. Ocean shorelines are also simple because we can assume sea level for everything. Rivers are difficult because the elevation changes as the river flows downstream. Now, if we had accurate elevation data for the polygons this would be a bit easier but we don't. That's because the data was originally authored for a two dimensional view--a topographical map. If you've ever used a topo map you know that elevation is given by a series of lines that follow the slope, measured at regular intervals. Rivers are viewed top-down and you need to project the third dimension using your imagination.
So how do we tackle the issue? Well, in FS2002 we didn't, really. We simply used one elevation value for each polygon obtained by sampling the DEM at a single reference point. The result was very visible "waterfalls" where the elevation changed dramatically between two adjacent polygons. The effect became more noticable the larger the source polygon was. The only redeeming feature was you take the Caravan floatplane and 'jump' over the edge--very fun!
In FS2004 we attempted to provide a more realistic slope to large rivers. The technique we use to pre-process the polygonal data to create center lines for each polygon along the length of the river. We then sample the DEM at the end points to create two elevation values. At runtime the terrain engine uses this data to create a slope for each polygon along the centerline while retaining a level spanwise orientation. Now all of this is pretty simply so far but you quickly run into major obstacles when processing the entire world. First is the problem of handling varying geography such as inlets, coves, islands, and branches.
To see this for yourself, get out a map that depects rivers in two dimenions and start drawing a line from the head to the mouth. What happens when you reach an island in the middle of the river? Do you split your line or just go on one side? If you split your line where do you do it and where you you rejoin it? Now let's say you come to a point where a smaller river feeds into the larger one. Do you start drawing a new line up the tributary? What do you do at the junction? How small does the tributary need to be before you can just use the main river's elevation? Oh, and did you notice that you intuatively knew where to start drawing your line? How do tell a computer problem where the "head of a river" is?
The next problem, as with creating non-flat airports, is discrepencies between data sources (hydrology and DEM). If you are processing rivers that twist and turn through particularly steep canyons (try the Rhine, for example) poorly align data will through off your elevation sampling. You may end up with rivers that heave and fall like roller coasters. Your algorithm, therefore, has to assume some tolerance for bad data. Still the end result are portions of rivers that appear unusually sloped.
Hopefully you start to get a sense of the challenges of doing this for every river on the entire planet. The point of this post is not make excuses for not getting it right. It's to give some insight into the challenge and to let you know we're still working on getting better.