Advertisement

Another Bump Mapping Problem

Started by August 24, 2004 12:53 PM
1 comment, last by L0rdDiabl0 20 years, 6 months ago
Hi: First a question: when implementing DOT3 Bump Mapping which is better and why : 1- Using a Cubemap to Normalize Tangent-Space Light Vector then using the Cubemap texture unit(0) to dot with normal map texture unit(1) 2- Pass Tangent-Space light vector coordinates as Color and then using the normal map texture unit(0) to dot with the color and saving a texture unit This leads me to the problem: as i'vew successfuly implemented Bump Mapping Using the Second Technique, I'm having difficulty using the first one, as i keep getting a brown colored (but correct Bump Mapping Effect) without the decal Texture, so What am i doing wrong? Here's the Code


	//Normalisation Cubemap
	glActiveTextureARB(GL_TEXTURE0_ARB);
	glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, normalisationCubeMap);
	glDisable(GL_TEXTURE_2D);
	glEnable(GL_TEXTURE_CUBE_MAP_ARB);

	//The Normal Map
	glActiveTextureARB(GL_TEXTURE1_ARB);
	glBindTexture(GL_TEXTURE_2D, normalMap);
        glEnable(GL_TEXTURE_2D);
	
        //The Decal Texture
	glActiveTextureARB(GL_TEXTURE2_ARB);
	glBindTexture(GL_TEXTURE_2D, decalTexture);
	glEnable(GL_TEXTURE_2D);

	//Set vertex arrays for Cube
	glVertexPointer(3, GL_FLOAT, sizeof(Cube_Vertices), &cube.vertices[0].Position);
	glEnableClientState(GL_VERTEX_ARRAY);

	//Send texture coords for normal map to unit 1
	glClientActiveTextureARB(GL_TEXTURE1_ARB);
	glTexCoordPointer(2, GL_FLOAT, sizeof(Cube_Vertices), &cube.vertices[0].TexCoord);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	//Send tangent space light vectors for normalisation to unit 0
	glClientActiveTextureARB(GL_TEXTURE0_ARB);
	glTexCoordPointer(3, GL_FLOAT, sizeof(Cube_Vertices), &cube.vertices[0].TangentMatrixLight);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	
	
        glActiveTextureARB(GL_TEXTURE0_ARB);
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
	glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
	
	glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
	glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
	
	
	glActiveTextureARB(GL_TEXTURE1_ARB);
	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_PREVIOUS_ARB); 
        glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);

	
	glActiveTextureARB(GL_TEXTURE2_ARB);
	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);
   

	//Draw Cube
	glDrawArrays( GL_QUADS, 0, 24 );






First method is better (more matematicly correct). In second method you are breaking so many things. First you are passing normalized light vectors when thy should be unnormalized. And after that you don't normalize them per-pixel so lighting gets not-unifrom as light vector length changes across triangle. In general this method will work only if you have highly tesselated meshes, but that basicly breaks the point of PPL in the first place.

Now, to your code. TexEnvs look OK, but you are missing one texcoord pointer (for unit 2).
//Send texture coords for diffuse map to unit 2glClientActiveTextureARB(GL_TEXTURE2_ARB);glTexCoordPointer(2, GL_FLOAT, sizeof(Cube_Vertices), &cube.vertices[0].TexCoord);glEnableClientState(GL_TEXTURE_COORD_ARRAY);


You should never let your fears become the boundaries of your dreams.
Advertisement
Thank you _DarkWIng_ again for the Clarification and Correction, I got it fixed (How silly i am not noticing that it was missing)

This topic is closed to new replies.

Advertisement