Detail Mapping

How to do it??

GL_ADD_SIGNED, instead of GL_REPLACE or GL_MODULATE, and the detail map should go through an emboss filter in some paint program before you use it.

What???

What part did you not understand?

I didn’t understand anything

Uhm, think I was typing a little bit faster than I could think. Setting up the states to use GL_ADD_SIGNED is a little bit more work than just replacing GL_REPLACE/GL_MODULATE, which I first thought.

I don’t know how much you know about texturing, but to deal with detail mapping, you have to know how multitexturing and texture combine functions works. This is a base requirement, and if you don’t know about it, you should wait with detail mapping until you know it.

Anyways, the basic idea is like this. The first base texture is applied as usual, using the first texture unit. The detail map is then added ontop of the base texture, using the second texture unit. Detail mapping usually uses the extension ARB_texture_env_combine and the GL_ADD_SIGNED combine function. Have a look in the specification for the ARB_texture_env_combine extension for more information. A typical detail function setup may look something likt this, and it’s also the way I do it, more or less

// First texture unit, modulate base texture with primary color
glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, base_texture);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_PRiMARY);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR);
// Second texture unit, add detail map ontop of base texture
glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D, detail_texture);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_SIGNED_ADD);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR);