Skip to main content
gamedev.net
🔒 Locked

problems with bump mapping

Started by Marlitan Dec 21, 2004 at 7:42 AM 2 replies 650+ views
Original Post
Marlitan
Marlitan
Hi all, I've got problem with bump mapping. I do it according to NEHE tutorial. I've created function ( below ) to display simple wall mesh ( 4 vertices ) with bumpmap. Problem is that this texture is blended against all other surfaces, ie. ground, I don't know why. Of course in the begining is blending enabled, but I guess it is due to glTexEnvf ? And recomendation or advices? Another think I'd like to know how to do it in 1 pass. I tried do it via .. glMultiTexCoord2fARB(GL_TEXTURE2_ARB .. etc. in another texture unit. But there was problem with light, which should be enabled only on ordinary texture. ( if you've got also some links please send them ) Thanks PS.: Don't recoment me advanced techniques, like fragment shaders etc.. because I have GeForce2 with no fragment shaders.

void DrawWallBump2 (Vertex *verts,Vector2d *coords,Vertex *light,int stex)
{
	glPushAttrib (GL_LIGHTING | GL_BLEND);

	glDisable(GL_LIGHTING);
	glEnable(GL_BLEND);

	glActiveTextureARB(GL_TEXTURE0_ARB);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, tx.m_pTextures[stex].m_nBumpmapID );
	glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
	glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_EXT, GL_REPLACE);

	glActiveTextureARB(GL_TEXTURE1_ARB);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, tx.m_pTextures[stex].m_nLightmapID  ); // inverse bumpmap
	glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
	glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_ADD);

	// nakresli to oboje

    Vertex n,s,t,pt;
	s = verts[1] - verts[0];
	t = verts[2] - verts[1];
	n = CMath::CrossProduct (s,t);
	CMath::Normalize (&s);
	CMath::Normalize (&t);
	CMath::Normalize (&n);
  
	glBegin(GL_QUADS);

	  for (int i=0;i<4;i++)
		{
		pt = verts;
	    SetUpBumps(&n,&pt,light,&s,&t);  
		glMultiTexCoord2fARB(GL_TEXTURE0_ARB,coords.x,coords.y);
	    glMultiTexCoord2fARB(GL_TEXTURE1_ARB,coords.x+pt.x,coords.y + pt.y);
	    verts.Draw ();
		}
	 
	  glEnd();	
	  
	glActiveTextureARB(GL_TEXTURE1_ARB);
	glDisable(GL_TEXTURE_2D);
	glActiveTextureARB(GL_TEXTURE0_ARB);

	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	glBindTexture(GL_TEXTURE_2D,tx.m_pTextures[stex].m_nTextureID);
	glBlendFunc(GL_DST_COLOR,GL_SRC_COLOR);

	 glBegin(GL_QUADS);
	  n.Normal ();
	  for (i=0;i<4;i++)
		   {
		   glTexCoord2f(coords.x,coords.y);
		   verts.Draw ();
		   }

	 glEnd();

	glPopAttrib();
}
  
zedzeek
zedzeek
had a very quick look, with bumpmapping u need
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_EXT, GL_DOT3);
not
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_EXT, GL_REPLACE);
u need to dot this with some vector (normally normalized saying wehere the light is coming from in relation to the bumpmap)
Marlitan
Marlitan
Thanks for answer. I've heard about Dot3, Do I need some extension for it?
What and how set that vector, it is plane normal?
zedzeek
zedzeek
>>What and how set that vector, it is plane normal?<<

its the normalized vector from the vertices position to the light (this vector must be in the same space as the bumpmap)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.