2

I have a flight simulator style opengl application. This application loads height data from file (imports DTED files). It generates a custom terrain mesh that is rendered as a perspective view based on the aircraft's position and orientation (i.e. a moving viewpoint) and the current field of view.

I am trying to apply ridgeline enhancements to the terrain rendering, such that within the field of view of the aircraft, the ridgelines of the terrain are highlighted. The following pictures should help clarify:

Example: Aircraft View across terrain contours

Example: Ridgeline enhancement

I have tried to find suitable algorithms, but the closest I could find were contour algorithms which simply match height points. I have tried rendering the terrain and then interrogating the depth buffer to find the ridgeline - which works for a basic skyline but not intermediate ridgelines. I have considered performing multiple renders of the terrain at different ranges to get a "set" of range based skylines, but this is computationally expensive and does not actually capture the ridges very well. I have considered performing multiple intervisibility calculations to determine the ridgelines but this is very computationally expensive.

Thus I am looking for suggestions, algorithms or code snippets that will help me to render the ridgelines.

  • Instead of "performing multiple renders of the terrain at different ranges" couldn't you just check the depth buffer for those ranges? Or maybe check the depth buffer for discontinuities greater than a certain value. Or maybe render the tile position into another buffer, then a ridge is wherever two adjacent screen pixels don't come from the same tile or adjacent tiles. – user253751 Sep 10 '21 at 11:40
  • You may have to define what a ridgeline is and isn't. If there's a 1x1 metre hole in the ground then does the front of it count as a ridge, or do they have to be above a certain size? – user253751 Sep 10 '21 at 11:41
  • @user253751 Part of the problem is that a ridgeline is generally not very well defined (unfortunately) and is somewhat subjective. Basically a ridgeline is the visible line of terrain that distinguishes it from either the sky or more distant terrain. One things I have tried is changing the clip planes such that I only look for ridgelines at a distance from the observer (which overcomes the "hole" problem) – Fergus Crawford Sep 10 '21 at 12:22
  • @user253751 I have tried to look for discontinuities in the depth buffer, but as I am rendering a significant distance the relative changes in depth buffer are quite small even when the near clip plane is set at a distance. Also could you expand on the tile position idea please. I am not sure I follow. – Fergus Crawford Sep 10 '21 at 12:26

1 Answers1

0

I would try looking for discontinuities in the depth buffer. If two pixels next to each other are more than a certain depth apart, that's a ridgeline. This can be done in a shader that reads the depth buffer.

Beware that the depth buffer is non-linear, so you have to convert the depth buffer value back to actual distance by using the inverse of the projection matrix. Depending on how your matrices are set up, you might have to also undo the view matrix in order to calculate the distance in the game world.

Perhaps you could choose to apply some non-linearity of your own, so that less significant ridgelines (less of a depth gap) don't appear until they are closer to the player.

user253751
  • 57,427
  • 7
  • 48
  • 90
  • Thanks. I have already got code that detects z-buffer discontinuities and reconstructs the ridgeline points but only in x,y. I'll look at reconstructing depth and see how much that helps – Fergus Crawford Sep 10 '21 at 12:35