DOT3 Bump Mapping Problem

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

Recommended Posts

Hi, EDIT: "The problem is i don't see anything, just black, and when i disable the combiner and use just glColor i see just a grey box." I can't get my hands on the error in my code, after days of research i gave up and decided to seek your help guys so PLEASE don't disappoint me : this is the main code:
	glTranslatef(0.0f, 0.0f, z);
glRotatef(xrot, 1.0f, 0.0f, 0.0f);
glRotatef(yrot, 0.0f, 1.0f, 0.0f);

// The Normal Map
glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, normalMap);
glEnable(GL_TEXTURE_2D);

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_DOT3_RGB_ARB);

glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);

glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);

// The Base Texture
glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D, decalTexture);
glEnable(GL_TEXTURE_2D);

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);

glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);

glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);

Vector LightPosition = Vector(3.0f, 3.0f, 3.0f);

Matrix InverseModelMatrix;

glPushMatrix();
glRotatef(-xrot, 1.0f, 0.0f, 0.0f);
glRotatef(-yrot, 0.0f, 1.0f, 0.0f);
glGetFloatv(GL_MODELVIEW_MATRIX, InverseModelMatrix.matrix);
glPopMatrix();

GLfloat position[24][3] = {cube vertex coordinates}

GLfloat texcoords[24][2] = {cube texture coordinates}

GLfloat normals[6][3] = {normals for each face}

for(unsigned int i=0; i<6; i++)
{
int j = i * 4;

glNormal3f(normals[0], normals[1], normals[2]);

LightVector = LightPosition - Vector(position[j+0]);
LightVector.Normal();
VecXMat4x4(LightVector, InverseModelMatrix, ObjectLightVector);
ObjectLightVector.Normal();

CalculateTangentMatrix(Vector(position[j+0]), Vector(position[j+1]), Vector(position[j+2]), TexCoord(texcoords[j+0]),
TexCoord(texcoords[j+1]), TexCoord(texcoords[j+2]), TangentMatrix);
VecXMat3x3(ObjectLightVector, TangentMatrix, TangentLightVector);

lp[0] = TangentLightVector.x * 0.5f + 0.5f;
lp[1] = TangentLightVector.y * 0.5f + 0.5f;
lp[2] = TangentLightVector.z * 0.5f + 0.5f;

glColor3fv(lp);

glMultiTexCoord2fARB(GL_TEXTURE0_ARB, texcoords[j+0][0], texcoords[j+0][1]);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, texcoords[j+0][0], texcoords[j+0][1]);
glVertex3f(position[j+0][0], position[j+0][1], position[j+0][2]);

}

glEnd();


There's also three copies of the previous code (with j=j+1) to draw a cube and this is the relevant parts:
void CalculateTangentMatrix(Vector PointA, Vector PointB, Vector PointC,
TexCoord ATex, TexCoord BTex, TexCoord CTex, Matrix TangentMatrix)
{
// Get the vector between point A and point B.
Vector VectorAB = PointB - PointA;

// Get the vector between point A and point C.
Vector VectorAC = PointC - PointA;

Vector Normal;
Normal.CrossProduct(VectorAB, VectorAC);
Normal.Normal();

// Compute the components of the vectors to the vertex normal of the first point.
Vector ProjAB = VectorAB - (Normal * Normal.DotProduct(VectorAB));
Vector ProjAC = VectorAC - (Normal * Normal.DotProduct(VectorAC));

3 and 1.
float TexCoord_S_AB = BTex.s - ATex.s;
float TexCoord_S_AC = CTex.s - ATex.s;

point 3 and 1.
float TexCoord_T_AB = BTex.t - ATex.t;
float TexCoord_T_AC = CTex.t - ATex.t;

if((TexCoord_S_AC * TexCoord_T_AB) > (TexCoord_S_AB * TexCoord_T_AC))
{
TexCoord_S_AC = -TexCoord_S_AC;
TexCoord_S_AB = -TexCoord_S_AB;
}

Vector Tangent = (ProjAB * TexCoord_S_AC) - (ProjAC * TexCoord_S_AB);
Tangent.Normal();

Vector Binormal;
Binormal.CrossProduct(Tangent, Normal);
Binormal.Normal();

TangentMatrix.matrix[0] = Tangent.x;
TangentMatrix.matrix[1] = Tangent.y;
TangentMatrix.matrix[2] = Tangent.z;

TangentMatrix.matrix[4] = Binormal.x;
TangentMatrix.matrix[5] = Binormal.y;
TangentMatrix.matrix[6] = Binormal.z;

TangentMatrix.matrix[8] = Normal.x;
TangentMatrix.matrix[9] = Normal.y;
TangentMatrix.matrix[10]= Normal.z;
}

void VecXMat4x4(Vector sourceV, Matrix m, Vector resultV)
{
resultV.x = ((sourceV.x)*(m.matrix[0])) + ((sourceV.y)*(m.matrix[4])) + ((sourceV.z)*(m.matrix[8])) + m.matrix[12];
resultV.y = ((sourceV.x)*(m.matrix[1])) + ((sourceV.y)*(m.matrix[5])) + ((sourceV.z)*(m.matrix[9])) + m.matrix[13];
resultV.z = ((sourceV.x)*(m.matrix[2])) + ((sourceV.y)*(m.matrix[6])) + ((sourceV.z)*(m.matrix[10])) + m.matrix[14];
}

void VecXMat3x3(Vector sourceV, Matrix m, Vector resultV)
{
resultV.x = ((sourceV.x)*(m.matrix[0])) + ((sourceV.y)*(m.matrix[4])) + ((sourceV.z)*(m.matrix[8]));
resultV.y = ((sourceV.x)*(m.matrix[1])) + ((sourceV.y)*(m.matrix[5])) + ((sourceV.z)*(m.matrix[9]));
resultV.z = ((sourceV.x)*(m.matrix[2])) + ((sourceV.y)*(m.matrix[6])) + ((sourceV.z)*(m.matrix[10]));
}


[Edited by - L0rdDiabl0 on August 19, 2004 1:58:53 AM]

Share on other sites
Whats the problem? Hard to read though a bunch of code when you dont even know what your looking for.

Share on other sites
Sorry for not stating the problem, it is that i don't see anything, just black, and when i disable the combiner and use just glColor i see just a grey box.

Share on other sites
If your getting a grey box, then your TangentLightVector must be (0,0,0)... in which case the dot product will return zero.

Share on other sites
Quote:
 Original post by RipTornIf your getting a grey box, then your TangentLightVector must be (0,0,0)... in which case the dot product will return zero.

Yeah i figured that out, but how can it be? i read through the code dozens of time and everything seem how it should be

Share on other sites
First of all, use the code-tags, because this is unreadable.
Second, what's this, and why are you doing it?
Quote:
 Original post by L0rdDiabl0 lp[0] = TangentLightVector.x * 0.5f + 0.5f; lp[1] = TangentLightVector.y * 0.5f + 0.5f; lp[2] = TangentLightVector.z * 0.5f + 0.5f;

Have you gotten it to work with a simple screen-aligned quad and a directional lightsource? For that, there's no need to make the transform to texturespace. If that works, your problem should be in the transform.

Share on other sites
FIXED with code tags
I'll try it with a single quad without tranformations, but please can somebody take a look at my Tangent Space Calculation?

Share on other sites
Quote:
 Yeah i figured that out, but how can it be? i read through the code dozens of time and everything seem how it should be

have you stepped through the code with a debugger?
set a break point on the glColor3fv call, and look through the values of the variables... The tanget matrix, etc. If something is amiss, then work backwards until you find where the bug is.

Share on other sites
Quote:
Original post by RipTorn
Quote:
 Yeah i figured that out, but how can it be? i read through the code dozens of time and everything seem how it should be

have you stepped through the code with a debugger?
set a break point on the glColor3fv call, and look through the values of the variables... The tanget matrix, etc. If something is amiss, then work backwards until you find where the bug is.

Thanks for the Advice, i'll try it

Share on other sites
You might wanna try setting cell 44 (4,4) of the tangentspace transformation matrix to 1.
Just guessing, but might be worth a try.

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• Forum Statistics

• Total Topics
634092
• Total Posts
3015439
×