PDA

View Full Version : 3 detail maps and a colormap with only 2 tex units



soconne
06-11-2005, 07:42 PM
I've recently come across the following article
http://www.cs.auckland.ac.nz/~jvan006/multitex/multitex.html

It states that its possible to mix 4 detail textures and a colormap all with only 2 texture units using Dot3. I've attempted to do it but I've run into some problems.

Here's how I do my setup.
Texture0 = alpha map
Texture1 = detail textures
Texture2 = color map

The alpha map is an RGB image, where R is the blending for the first detail texture and so forth. I have 3 detail textures mixed into the RGB channels of the detail texture itself, and then the color map is simply a regular texture.

Here are the textures below

color map http://cs.selu.edu/~soconnell/texture0.jpg

detail map
http://cs.selu.edu/~soconnell/texture1.jpg

alpha map
http://cs.selu.edu/~soconnell/texture2.jpg



// setup multitexturing stuff
glActiveTextureARB(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, alphaTex);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

glActiveTextureARB(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, detailTex);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DOT3_RGB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE0);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE1);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);

glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE0);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_TEXTURE1);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);


glActiveTextureARB(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, textureTex);
glEnable(GL_TEXTURE_2D);
float mixcol[4] = {1.0, 1, 1, 1};
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, mixcol);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_ONE_MINUS_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE2);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB, GL_CONSTANT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_COLOR);

glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_CONSTANT);And here is what I get as a result
http://cs.selu.edu/~soconnell/result.jpg

Also, here is what it looks like WITHOUT the final texture being blended. This is only the detail and alpha maps.
http://cs.selu.edu/~soconnell/result2.jpg

As you can see the colors are NOT what they're suppose to be. The detail textures itself are being blended where they're suppose to be, its just not blending correctly with the final texture. How do I comebine the detail textures with the alpha map, then have a resulting "GRAY" detail texture to combine with the final color map texture?

The author of the article seemed to have done it but I cannot figure it out.

zeckensack
06-11-2005, 10:55 PM
glActiveTextureARB(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, detailTex);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_COMBINE); !
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB,GL_DOT3_RG B); +