Hi again! For this entry I'm going to talk about the Midpoint Displacement stage and post more pictures, everybody loves pictures! (Yes, I'm a sellout, shush!) Skipping whatever is left of the ridge generation phase and the river generation phase since I'm having difficulties with the last stage right now and the river phase is incomplete.
In the beggining...
I remind you the paper where all of this comes from: Ridges and Rivers, Bottom Up Approach There is another version somewhere that was meant for other presentation I think, same authors, same date, just described differently.
Stages of the terrain generation algorithm:
- Ridge particle generation. Traces ridge lines on the map, blurs the height values.
- River particle generation. Creates velocity field and traces river lines on the map. Discard everything except river lines and the original ridge lines after that.
- Inverse midpoint displacement pass. Fill up the ridges and rivers network with some relevant data.
- Midpoint displacement pass. Fill up the rest of the missing data.
We covered up ridge generation stage in the previous entries. River generation stage is more or less an erosion algorithm applied to few particles. You spawn a particle at the top of a random ridge, and simulate its trajectory around the terrain, "carving" a river on the landscape.
Craving for rivers
All of this is made with a single purpose, feeding specific data to a midpoint displacement algorithm. That specific data represents the features of a believable terrain, ie, ridges and rivers that follow a logical path (at least for the rivers).
Once that stage is done you'd end up with something like this:
Image is lightened up a little because it was too dark for viewing.
Rivers are light blue and ridges are the yellow lines. The blurred gray heights are there just for reference, they're actually dropped once the river generation stage is complete (ie, you're only left with the ridge lines and the river lines).
There are a few problems with the river generation, such as, they live in a magical land without friction, thus they carve their way around like balls in a pinball, and they have no notion of water mass, so their size is constant.
This particular stage could go on forever as it is (perpetual motioners dream)... But I placed a timer on it, it stops after a second or so. Hack, totally, I know. I'll get it fixed eventually. It deserves its own entry though.
Midpoint Displacement's Inverse
Now here is where it gets more interesting. Remember that I said that the point of the algorithm is to feed a midpoint displacement pass some useful data? Well, its not that simple.
The midpoint displacement algorithm is nice in the sense that for a given square, its internal values depend on the external values (this link might have more information about it). The center and the sides of the square depend on the heights of the corners. For any subsquare inside, it follows the same rule.
It is an algorithm that can be feed some data, say, reference points like, oh surprise, ridges and rivers. In theory the algorithm could follow the points already precomputed as reference to compute the points that are missing. Thus obtaining a terrain that makes sense in the context of the rivers and ridges already present in it.
In reality, it isn't that simple. If you grab the heightmap as it is. The information available would be just too low to get a decent "contextualized noise" out of it. That's why the paper presents another stage to fill up the heightmap with some "guide points" for the midpoint displacement algorithm.
The authors use something they call... (dramatic drum roll in the background) Midpoint Displacement's Inverse. (MDI from now on) And the point of all of this is that I can't understand what it is.
MDI and my problems with it
It sort of describes it as a way of guess the corner values of every square and subsquare of the heightmap by interpolating its "child values", which I guess it means the midpoints that you obtain from a regular midpoint displacement pass.
So far I can't understand their (lack of) explanation about the process.
See, say that I have the 5 midpoints of a square, and I want to figure out the corner values. You can get a rough estimate (as in "almost wrong estimate" ) of what the corner values were by interpolating the values that it contributed to.
Example from the Wikipedia.
As you can see there, the top left corner contributes to the values of the left midpoint, upper midpoint and the middle midpoint. If you do (1+2+3.5)/3 you get 2.16'. Which isnt 0 at all but I guess is better that having no point at all.
These (very) rough estimates should help the regular midpoint displacement pass so the values it produces follows the general landscape that the ridges and rivers defined. That's all I could get from the paper.
Doing the MDI pass as I imagined doesn't yields good results:
There you have the bright higher ridge lines and the wider darker river lines going down from the top of the ridges.
As you might or might not see, the map isn't filled with corner points like the example of the paper shows. I'm producing barely any new point, but I can't see how could I be more lax with the algorithm so I can interpolate more points.
The interpolation as I see it needs at least one thing. The point I'm trying to find contributes to three other points, and I need those 3 points to exist to get an average out of them and get the corner value's estimate.
This happens very little on the map given the information it has. There just isn't that many points to get corners from. Moreover, the image you saw its not even checking for the middle value of the square, it tries to find the midpoints of the sides of the square and averages them, and it stills doesn't happens a lot.
So I end up without enough data to feed the regular Midpoint Displacement pass. Here is an example:
The result shows almost the same discontinuities the paper talks about before trying with the MDI pass. That means that my MDI pass isn't working as it should.
Though I understand now why the paper insist on storing everything on a few lists for processing later. If you want to do all of this on some for loops, you're going to need a lot of if checks, since you have to check if there is a need of calculating the height value, and if it isn't, to use the height value that already exists for the later computations. Which usually means to check for all of the 9 values of every sub-square (corners and midpoints) to see if you have to calculate them or not. It was a bit of an index madness for me there
Here is a colored version just for giggles:
That's it until I figure out the MDI proccess. If someone want's to help, it would be appreciated. Bye!