Andreas Jung

Tuesday, January 10, 2006

Building Cliffs

Fortunately, I have worked hard to get a little bit ahead of the University's stream of weekly tasks, so I still had some spare hours left for the FSNG substitute.



The problem in my previous post was the terrain-slope, which was not interpolated, thus resulting in blocky terrain overlay layer coverage. Now you probably want to say: hey, a little interpolation is not hard.
IT IS ... it is - at least if you want to do it efficiently.

Imagine you have an arbitrary floating point location, and you want to know the terrain's slope at that location. It can't be that hard: take the 4 neighbors's slope-values of the heightmap's grid-cell-rectangle-vertices where the location lies in, and do a bilinear interpolation.
So how do you get the slope value at such a neighbor-slope at a grid-cell-rectangle-vertex (<-- nice word, isn't it?). Well, take the 4 neighbor vertices of this vertex and do a little algebra.
Can you follow? For each of the 4 neighbors, look up the 4 neighbors and do algebra ... for each of the 4096*4096 texels of the terrain overlay texture!!! Look ups are said to be fast, but when reaching a certain number of look ups, it is obviously not.

I ended up creating a little terrain-slope cache, so I could reduce the amount of look ups by a factor 4. The amount of slope look ups is now bound to the heightmap resolution, and not the terrain overlay texture resolution, which is of course an improvement.

However, I admit that this factor 4 is not very much noticable when doing an 4096*4096 compile. (but I did not try yet the release-build).

Another problem that botherd me was the definition of slope in 2.5 dimensional space. I mean, we all know slope in 1.5 dimensional space when drawings graphs or deriving algebra. But honestly, I have no idea how to do it in 2.5 dimensional space, i.e. with the terrain.
I solved this provisionally by calculating the slope for each x/y-axis, and then let be slope=max(slope.x, slope.y) - it works more or less this way. I don't have the CPU cycles for more complicated stuff anyway.

Ok, more to come soon ... hopefully.