See what's going on with flipcode!


Detail Textures
Question submitted by (17 October 1999)

Return to The Archives
  Hi I was wondering if you could give a detailed step by step explanation of how to implement detail textures using and openGL rendering architecture. And if you have time could you please show how to implement the detail textures on a pipline that uses lightmaps and one that doesnot.  

  There is no single way to perform detail texturing and I don't think a full tutorial is within the scope of this venue so an overview is going to have to suffice.

First a description. A detail texture is a small, high-frequency texture that is blended with a large, low frequency texture to produce a result that would have otherwise required a single very large texture to duplicate. Using Treadmarks as an example, a single large 1024x1024 texture is placed on top of a 1024x1024 height field. At full tessellation this means there is one source texel for each vertex in the terrain. Needless to say this produces a very bland looking landscape so Seumas uses a 128x128 detail texture and repeats it over the entire terrain so a single iteration of the detail texture covers 8 square vertices. It would require a 16384x16384 texture to produce the same amount of detail (granted, you would have more control over that detail). It is worth noting that the same detail texture is used over everything (grass, sand, etc) and while it might seem that a texture repeated so many times would be obvious, the modulation with the base texture prevents this from happening and produces good results at a relatively low cost.

The detail texture itself is currently an RGB texture where each component is of equal value (monochromatic). It should be possible to use a Luminance texture instead, but it is unclear how well drivers and hardware support Luminance textures right now. If a card has native support for Luminance textures it should produce better performance than using an RGB due to lower bandwidth requirements from texture memory to the TMU.

When it comes to setting up the blend modes there are many different possibilities. Treadmarks currently uses modulation with multi-texture by default and glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) with an RGBA detail texture for cards that don't support the above. Another option is src*dst*2 with glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR) and multiple passes, which allows for brightening as well as darkening of the base texture. There is probably a way to produce this with the tex_env_combine extension to perform it in a single pass with multi-texture.

Traditional light mapping works in the opposite direction to detail texturing. You use a small low frequency texture (the lightmap) and modulate it with a large detail texture (the detail texture) without repeating. If you wanted to combine the techniques you would use multiple passes. First I would combine the detail texture and the base texture in the frame buffer, then use an additional pass to modulate the frame buffer with the light map. There are of course several different ways of combining these things together and how you do it depends on the effect you are trying to achieve.

Special thanks go out to Seumas McNally at Longbow Digital Arts for helping me make sure I had my facts straight and allowing me to use his Treadmarks game engine as an example. You can download the second demo of Treadmarks and turn detail textures on and off with the F7 key to see their effects in action.

Response provided by Tom Hubina

This article was originally an entry in flipCode's Fountain of Knowledge, an open Question and Answer column that no longer exists.


Copyright 1999-2008 (C) FLIPCODE.COM and/or the original content author(s). All rights reserved.
Please read our Terms, Conditions, and Privacy information.