More debugging of terrain blending

So I was working to debug terrain blending, and thought that it might be easier to see what was going on if I could see the distances more easily, and so modified the terrain to draw with a simple grid on it…  I’m going to have to include something like this in the final game, aren’t I?

Anyhow, I found a bug in the terrain blending code, and was all excited to have fixed it, only to discover that fixing it has made the problem worse.  Or at least, it has made problems appear at all district boundaries, instead of only at some of them, and make the bad behaviour even more pronounced.

However, making a bug’s bad behaviour occur more consistently is often a good first step toward solving the bug, so I’m hopeful that I’m moving in a good direction.

What I’ve done in this shot is to set up all districts to be almost completely flat, just at different heights from each other;  the blending function should make smooth ramps up and down between the different flat sections.. but as you can see here, the ramps seem to only be about half as steep as they need to be, and you end up with a sheer vertical cliff in the middle of them.  (for reference, the blend between districts occurs over forty meters on each side of the border, and each square in the grid is eight meters on a side — so that means that you should see about ten grid squares of blending in total, between each pair of districts.