I've got a 3D terrain that consists of many heightmap-based tiles. I need to render multiple roads over the tile. By now I simply subdivide road into tile pieces then generate a decal per each tile. But decals are pretty expensive on memory. Is there any better solution than using decals or baking roads into the tile texture? (Target application should work on mobile device with OpenGL ES 2.0 support)


An alternative to incorporating the roads into your terrain texture is to model them as separate geometry, for example as triangle strips. The problem with that is you want the road geometry to be very close to the terrain geometry, which leads to depth ambiguity. Sometimes the terrain will appear in front of the road, and that may change (flicker) as the camera moves. In some OpenGL applications it is possible to force one “layer” to be in front by drawing in two sequential passes, and turning off depth testing for the second layer:

// Draw terrain.

// Draw roads.

However this may not work for you since you may have roads behind terrain that you do want to to be occluded. If so, baking your roads into the terrain textures may be the best approach. But then the road surface will always have slope parallel to the terrain. Or possibly, modeling the roads as separate geometry, and lifting them above the terrain by such a large amount that the depth ambiguity goes away.

  • \$\begingroup\$ You can also apply absolute and slope-based depth biasing, but yeah, it's fiddly to make it work perfectly at all distances & angles. \$\endgroup\$
    – DMGregory
    Dec 28 '17 at 22:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.