Dot3 bump mapping lightning problem

I’m trying to do dot3 bump mapping, mainly based on Paul's project tutorial .

The big difference is that I’m trying to do it in a single pass, so I use 3 texture units. The effect seems to work as the result I get is the color of my color map and it is bumped with the normal map. However, I can’t get lightning to have any influence on my bumb mapped quad. Every other object in my scene reacts to lights, but my bump mapped quad is just as if there wasn’t any light. Below is the drawing part.

//enable lightning
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHTING);

//here I draw the rest of the scene

//and now the bump mapped quad

//texture unit 0 - normal map
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, normalTexture);
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);

//texture unit 1 - cube map
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_CUBE_MAP_ARB);
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, cubeMapTexture);
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_SOURCE1_RGB_ARB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_DOT3_RGB_ARB);

//texture unit 3 - color map
glActiveTextureARB(GL_TEXTURE2_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, colorMapTexture);
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_SOURCE1_RGB_ARB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_COMBINE_ARB);

//and here I draw my quad

Try changing the last line of the third stage to:

glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);

Dude

I tryed but it still doesn’t work, anyone else have an idea?

Hi, I’m not sure
if I understand, you do:
n.l+color
so not lighting.
Maybe you should try to modulate somewhere at the end with PRIMARY_COLOR_ARB in order to get:
(n.l+color)*PRIMARY_COLOR_ARB
I guess you have to give a white color to your object.

EDIT:wrong

Oops,
I correct myself:

n.l+color
n.l*texturecolor
So dude is right, and I don’t know why it doesn’t work.

The dot product is supposed to take the 3 component vector based normal map and perform the dot product with a suitably calculated & interpolated per vertex value. You are not supposed to have OpenGL fixed function lighting on for this.

That cubemap is there to normalize vectors generated per vertex in a vertex program or sent by the application. The result of the normalized vector represent the light direction vector in tangent space. Paul calculates these in C++ code and sends them as texcoords to the cubemap texture. You need to do the same. But understand that this dot product gives you a complete diffuse lighting result. Any additional modulation with, say, a vertex color should be some other interesting per vertex diffuse coloration (optional) and NOT the fixed function OpenGL lighting result (Paul has that as a comparrison and only when bumpmapping is off), that would just stuff things up & you’ll get a pretty dark result, not to mention something completely wrong and non physical (the modulation of one per vertex illumination term by another per vertex illumination term). You do a replace in your first unit and don’t use primary_color so lighting is redundant & unused anyway, however it makes me wonder if you implement the software per vertex calculations you need to.

You might want to add this line for each source as well

glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);

but I think that is the default.

So you need to send the regular tex coordinates to TEXTURE0 and TEXTURE2
For TEXTURE1, you need to supply the light vector in tangent space.
If you aren’t using a vertex program, then you do it on the CPU.

Thanks for answering, I must admit I didn’t understand everything. I have a good mathematics knowledge and I think I understood the theory behind it. What confuses me is that he’s doing it on a torus.

As for the per vertex light computation, I have to do it myself software right? Nothing in OpenGL or hardware?

You could write a vertex program for hardware acceleration, but for now keep it simple.

Look at Paul’s code for tangentSpaceLight, this is what you need to calculate and send as a texcoord.

Also understand that to compute this you need the normal, tangent and binormal vectors.

He’s doing this on a torus because it is a good test of a varying tangent space basis, it covers all possibilities with a reasonably well behaved surface (nice ortho coordinate frame (TSB)).

Paul seems to use a vector class of some sort for his dot products.