PDA

View Full Version : Drawing roads and rivers onto a 3D terrain



lehmanne
10-09-2003, 07:17 AM
Hello,

i have drawn a 3D terrain with GL_QUADS. I have mountains and valleys in it. This part works well.

Now i want to draw roads and rivers to the terrain. A road/river is like a list of 2D (means x,y) coordinate pairs without elevation information. If i draw a road with GL_LINES into my scene, they all will be drawn on elevation coordinate Z = 0 as horizontal lines.

What i want is to draw lines onto the terrain surface, up to the mountains and down into the valleys. I want not roads tunneling through the mountains and i want not see a road shining through a mountain.

Please give some hints how to manage that.
Thanks

Cyranose
10-09-2003, 08:35 AM
Originally posted by lehmanne:
Hello,

i have drawn a 3D terrain with GL_QUADS. I have mountains and valleys in it. This part works well.

Now i want to draw roads and rivers to the terrain. A road/river is like a list of 2D (means x,y) coordinate pairs without elevation information. If i draw a road with GL_LINES into my scene, they all will be drawn on elevation coordinate Z = 0 as horizontal lines.

What i want is to draw lines onto the terrain surface, up to the mountains and down into the valleys. I want not roads tunneling through the mountains and i want not see a road shining through a mountain.

Please give some hints how to manage that.
Thanks

One way is to render your roads and rivers into an alpha texture map and blend this onto your terrain with multitexture (or blend into the base texture if resolutions match).

The downside is that if the resolution is too low, your roads may seem blurry. Roads may also seem to tilt strangely on steep slopes. But this would work nicely with LOD terrain, for example. If you render this on the fly and match your road texture extents and resolution to the current view, you can mitigate some of the blurring effects.

The second major way is to fit the roads and rivers to the terrain as vector data. This involves traversing each line segment in your roads and rivers and determining the elevation of that 3D point. That means finding the closest corresponding points on your terrain (in 2D) and interpolating the 3D height between them.

For correct results, it also involves splitting any line segments that cross terrain quad boundarties (split at the boundaries) and evaluating the height of those points too.

The advantage of this method is that the lines are crisper and of consistent width, but it's much harder to do this with dynamic LOD terrain. This same method works for drawing roads and rivers as wider quadstrips, where you want the quadstrip to have its width axis seem "flat." It's posssible, but non-trivial, to make everything match up correctly.

There are other misc methods, including rendering the roads as vertical quadstrip ribbons (after rendering your terrain) with the z-test set to z-equals. This will leave pixels colored only where the terrain intersects your ribbon.

I'd recommend the first method for starters and see if that's good enough for you.

Avi