PDA

View Full Version : Dot3 bump mapping lightning problem



Cheps
08-13-2004, 04:58 AM
I'm trying to do dot3 bump mapping, mainly based on Paul\'s project tutorial (http://www.paulsprojects.net/tutorials/simplebump/simplebump.html) .

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

Dude
08-13-2004, 07:43 AM
Try changing the last line of the third stage to:

glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);Dude

Cheps
08-15-2004, 07:28 AM
I tryed but it still doesn't work, anyone else have an idea?

edf
08-15-2004, 12:37 PM
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

edf
08-15-2004, 12:44 PM
Oops,
I correct myself:

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

dorbie
08-16-2004, 11:41 AM
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.

V-man
08-16-2004, 07:20 PM
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.

Cheps
08-16-2004, 09:57 PM
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?

dorbie
08-17-2004, 10:05 AM
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.