Sign in to follow this  

DOT3 bump mapping help !!!

This topic is 4863 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I am new to this forum and seek help on DOT3 bump mapping. I am not sure whether the movement of light source would change the color of the object; I could see the bumps fade and get bright by light source movement but am not sure about change in color. What parameter should be given in glBlendFunc (.....) to render the texture after the bumpmap is rendered ? Thanks for your suggestions, Kavitha

Share this post


Link to post
Share on other sites
If you just use a normal map and light vector, you'll get a result in greyscale. If you want to add color as a second pass, you could use glBlendFunc(GL_ZERO,GL_SRC_COLOR) to modulate the color with the result from the lighting calculation.

Share this post


Link to post
Share on other sites
Hi all,

Thanks for your reply. I indeed did a second pass and found the displayed color (little dark too !!) is different to the texture map I used. Although the pattern is correct, there is a change in color.

And when I move the light source, the color changes?

I don't understand the behaviour

thanks,

kavitha

[Edited by - kavitha on August 17, 2004 4:25:52 PM]

Share this post


Link to post
Share on other sites
Have you specified GL_REPLACE as texture mode for the color texture? 'Cause if you use vertex colors to store light vectors, you might get such a behaviour with GL_MODULATE..
I can't be sure without knowing exactly how you do your bump mapping and rendering (and perhaps seeing some screenshots.)
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);

Share this post


Link to post
Share on other sites
Hi Tomas,

Thanks for your reply!!, I indeed changed to GL_REPLACE and now I have the right texture but with a less dull intensity. I have used two variables bump - to display bump texture; onlyTexture - to display just the texture and both are set to TRUE initially.

Initially, when it renders, the bump texture appears to be dull but brightens up when I press a key that makes bump = true & onlyTexture = false;

I have attached my rendering code (DOT3 bump mapping a square) and please go through to find my fault in GL parameters. I donno how to attach an image; looking forward to your reply



void
display () {

glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity ();
gluLookAt (0.0f, 0.0f, 10.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

//Get the inverse model matrix
MATRIX4X4 inverseModelMatrix;
glPushMatrix();
glLoadIdentity();
glGetFloatv(GL_MODELVIEW_MATRIX, inverseModelMatrix);
glPopMatrix();

VECTOR3D objectLightPosition = inverseModelMatrix * worldLightPosition;

if (bump) {
glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture (GL_TEXTURE_2D, normalMap);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_DOT3_RGB_EXT);

glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PRIMARY_COLOR_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR);

glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture (GL_TEXTURE_2D, normalisationCubeMap);
glEnable(GL_TEXTURE_2D);

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);

glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_PREVIOUS_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR);

glBegin (GL_TRIANGLE_STRIP);

VECTOR3D lightVector = objectLightPosition - square_vertices[0].position;
lightVector.Normalize ();

vecMat3x3Mult (lightVector, tangentMatrix, square_vertices[0].tangentSpaceLight);

glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0, 0.0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0, 0.0);
glColor3fv(square_vertices[0].tangentSpaceLight);
glNormal3f(0.0, 0.0, 1.0);
glVertex3f(-2.0, -2.0, 0.0);

lightVector = objectLightPosition - square_vertices[1].position;
lightVector.Normalize ();

vecMat3x3Mult (lightVector, tangentMatrix, square_vertices[1].tangentSpaceLight);

glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0, 0.0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0, 0.0);
glColor3fv(square_vertices[1].tangentSpaceLight);
glNormal3f(0.0, 0.0, 1.0);
glVertex3f(2.0, -2.0, 0.0);

lightVector = objectLightPosition - square_vertices[2].position;
lightVector.Normalize ();

vecMat3x3Mult (lightVector, tangentMatrix, square_vertices[2].tangentSpaceLight);

glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0, 1.0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0, 1.0);
glColor3fv(square_vertices[2].tangentSpaceLight);
glNormal3f(0.0, 0.0, 1.0);
glVertex3f(-2.0, 2.0, 0.0);

lightVector = objectLightPosition - square_vertices[3].position;
lightVector.Normalize ();

vecMat3x3Mult (lightVector, tangentMatrix, square_vertices[3].tangentSpaceLight);

glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0, 1.0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0, 1.0);
glColor3fv(square_vertices[3].tangentSpaceLight);
glNormal3f(0.0, 0.0, 1.0);
glVertex3f(2.0, 2.0, 0.0);

glEnd ();

// reset texture unit state
glActiveTextureARB(GL_TEXTURE0_ARB);
glMatrixMode(GL_TEXTURE);
glLoadIdentity ();
glMatrixMode(GL_MODELVIEW);
glDisable(GL_TEXTURE_3D_EXT);
glDisable(GL_TEXTURE_CUBE_MAP_ARB);
glDisable(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_GEN_R);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glActiveTextureARB(GL_TEXTURE1_ARB);
glMatrixMode(GL_TEXTURE);
glLoadIdentity ();
glMatrixMode(GL_MODELVIEW);
glDisable(GL_TEXTURE_3D_EXT);
glDisable(GL_TEXTURE_CUBE_MAP_ARB);
glDisable(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_GEN_R);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
}

if(bump && onlyTexture)
{
//Enable multiplicative blending
glBlendFunc(GL_ZERO,GL_SRC_COLOR);
glEnable(GL_BLEND);
}

if (onlyTexture) {

if (!bump) {

glLightfv(GL_LIGHT1, GL_POSITION, VECTOR4D
(objectLightPosition));
glLightfv(GL_LIGHT1, GL_DIFFUSE, white);
glLightfv(GL_LIGHT1, GL_AMBIENT, black);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, black);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHTING);
glMaterialfv(GL_FRONT, GL_DIFFUSE, white);
}
glBindTexture(GL_TEXTURE_2D, textureId);
glEnable(GL_TEXTURE_2D);

glBegin (GL_TRIANGLE_STRIP);

glTexCoord2f (0.0f, 0.0f); glVertex3f(-2.0, -2.0, 0.0);
glTexCoord2f (1.0f, 0.0f); glVertex3f(2.0, -2.0, 0.0);
glTexCoord2f (0.0f, 1.0f); glVertex3f(-2.0, 2.0, 0.0);
glTexCoord2f (1.0f, 1.0f); glVertex3f(2.0, 2.0, 0.0);

glEnd ();

if (!bump)
glDisable(GL_LIGHTING);
//Disable texture
glDisable(GL_TEXTURE_2D);
}

if(onlyTexture && bump)
glDisable(GL_BLEND);

glFinish();
glutSwapBuffers();
glutPostRedisplay();
}



thanks,

kavitha

Share this post


Link to post
Share on other sites
Ok, a few things:
You store the tangent space light vector in the vertex color, but you still use a normalization cube map? Usually it's either-or, not both. If you want to use a normalization cube map, you should supply the light vector as texture coordinates to it.
With a cube map:
TU0: Cube map. Mode GL_REPLACE
TU1: Normal map. Mode GL_COMBINE/GL_DOT_3
Second pass:
TU0: Color texture. Mode GL_REPLACE. Blend with background
TU1: Disabled
Without cube map:
TU0: Normal map. Mode GL_COMBINE/GL_DOT_3
TU1: Color texture. Mode GL_MODULATE.

So without the cube map, you won't have to do two passes, but the normals will not always be properly normalized (since they are interpolated.)
That's how I understand it. I haven't implemented dot3 with a normalization cube map, so I might be wrong (I'm sure someone will correct me in that case.)

Share this post


Link to post
Share on other sites
Hi Tomas,

Thanks for your reply !!!....how do i supply the light vector as texture coordinates since I've used normalization cube map. I am little confused of how to implement that.

Also I am looking to rotate the square; since an inverse matrix had to be done, where in with this piece of code, glRotatef must be called

MATRIX4X4 inverseModelMatrix;
glPushMatrix();
glLoadIdentity();
glGetFloatv(GL_MODELVIEW_MATRIX, inverseModelMatrix);
glPopMatrix();

thanks,

kavitha

Share this post


Link to post
Share on other sites
Just try using glMultiTexCoord3fvARB instead of glColor3fv. I can't help you much more now - as I said I haven't tried normalization cube maps, and it's getting late here. If you still need help tomorrow, and I have the time, I'll do my best to help out more [disturbed]

Share this post


Link to post
Share on other sites
Maybe you've already figured it out, but anyway:
Quote:
Also I am looking to rotate the square; since an inverse matrix had to be done, where in with this piece of code, glRotatef must be called

MATRIX4X4 inverseModelMatrix;
glPushMatrix();
glLoadIdentity();
glGetFloatv(GL_MODELVIEW_MATRIX, inverseModelMatrix);
glPopMatrix();

Ok, you use the inverse matrix to get the light position from world to object coordinates. So you'll need the inverse transformation of the one you use to get the object to world coordinates. So if you add the rotation glRotatef(a,x,y,z) before rendering (i.e. before the glBegin:s) you would add glRotatef(-a,x,y,z) just before the glGetFloatv above. Right?

Also, when using a normalization cube map, you shouldn't need to normalize the light vector (though it won't hurt anything except performance.)

Share this post


Link to post
Share on other sites
Hi tomas,

Yeah, I figured it out when I experimented various positions and found the reason for it too!!

BTW, I've got one more doubt. Although, you didn't perform DOT3 using normalization cube, I hope you could explain the steps in rendering the texture and the polygon. I am confused in following two tutorials, I am not able to understand what they do in total sense as GL commands are being juggled up and down without any coherence in steps.

thanks for your input.

~ kavitha

Share this post


Link to post
Share on other sites
Quote:
Original post by kavitha
BTW, I've got one more doubt. Although, you didn't perform DOT3 using normalization cube, I hope you could explain the steps in rendering the texture and the polygon. I am confused in following two tutorials, I am not able to understand what they do in total sense as GL commands are being juggled up and down without any coherence in steps.

I'd be happy to help. Could you post the part of the code that you need further explanation on?

Share this post


Link to post
Share on other sites

This topic is 4863 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this