Sign in to follow this  

DOT3 Bump Mapping Problem

This topic is 4867 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, 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();
	glLoadIdentity();
	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}

glBegin(GL_QUADS);

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

		
		glNormal3f(normals[i][0], normals[i][1], normals[i][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 this post


Link to post
Share on other sites
Quote:
Original post by RipTorn
If 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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

I fixed it, i was doing something really stupid, and finally caugth it with debugging

Share this post


Link to post
Share on other sites

This topic is 4867 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