PDA

View Full Version : texEnv



goldwire32767
04-15-2004, 08:14 PM
Im trying to make a multi-light bump mapping application which uses texenv's dot3 operation. I can get the bumpmapping working the a white light by using the following setup:
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);

glActiveTextureARB(GL_TEXTURE1_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_DOT3_RGB_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);

This code will draw white and black bumps given a normal map. I was wondering how i can change this so that i can color the bumps to a specific color. Thanks.
Chris

dawn
04-16-2004, 05:04 AM
You need an aditional texture stage.
Just set on third stage a dummy texture (coords not needed) and set the following env op:

glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, your_bump_color);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_CONSTANT_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);

Also don't forget about:
glTexEnvi(GL_TEXTURE_ENV, GL_OPERANDx_RGB_ARB, GL_SRC_COLOR); // or 1-src_color

and about setting the proper operations also for alpha (i've got some times weird results with non-setting the alpha operation)

goldwire32767
04-16-2004, 05:36 AM
So now I have:

//Set up texture environment to do (tex0 dot tex1)*color
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);

glActiveTextureARB(GL_TEXTURE1_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_DOT3_RGB_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);

float f[]={1,1,1,0};
glClientActiveTextureARB(GL_TEXTURE3_ARB); //set a dummy texture (nothing in there)
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_CONSTANT_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, f);

But it still does not work.

dawn
04-16-2004, 05:48 AM
TEX3 is active ?

Constant color with alpha = 0 ?

goldwire32767
04-16-2004, 05:51 AM
Just set on third stage a dummy texture (coords not needed) and set the following env op:
I guess im not sure what you mean by this. I am new to the texEnv functions.

waramp
04-16-2004, 08:18 AM
if you have the crossbar extension, then this should work:

glActiveTextureARB(GL_TEXTURE0_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE1_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_DOT3_RGB_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE0_ARB);

glClientActiveTextureARB(GL_TEXTURE1_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB);

Where the primary color (glColorxx()) is the light color. Alternatively, you can use GL_CONSTANT_COLOR instead of GL_PRIMARY_COLOR and put the lights color int the TexEnv's constant color.

Does anyone know how often you can set the TexEnv constant color? can it be done for every vertex (ie: use it like a secondary color?)

goldwire32767
04-16-2004, 09:30 AM
sorry, still doesnt want to work.

waramp
04-16-2004, 09:42 AM
give us more information, what isn't working? Its not coloring the light? do you have any blend modes set? is it dot3 but not colored? is it colored but not dot3?

I notice that you have: glClientActiveTextureARB for Unit 0 but glActiveTextureARB for Unit 1. Mayhaps this is an issue?

goldwire32767
04-16-2004, 09:55 AM
This code will actually apply the bump mapping beautifully with a white light.

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE0_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_DOT3_RGB_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE1_ARB);

When I add the following code below the first, it appears that the glColor is applying to the actualy normal map, and the dot3 isnt even doing anything anymore:

glClientActiveTextureARB(GL_TEXTURE1_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB);
glColor4f(1,1,0,1);

does blending need to be enabled at this time?

waramp
04-16-2004, 10:30 AM
hmmm no blending needed.

According to: http://www.khronos.org/opengles/documentation/html/glActiveTexture.html

you should use glActiveTexture, NOT glClientActiveTexture.
read up on them

http://www.khronos.org/opengles/documentation/html/glActiveTexture.html

http://www.khronos.org/opengles/documentation/html/glClientActiveTexture.html

goldwire32767
04-16-2004, 01:31 PM
So ive tried every combination of commands i could think of and still i cant assign a constant color to the bumpmap. The exact code im trying to change is:

http://www.paulsprojects.net/tutorials/simplebump/simplebump.html

And once again, i just want a way to do (a dot b)*color
thanks in advance