PDA

View Full Version : Emboss bump, HELP please....!!

dabeav
06-03-2002, 09:39 AM
Ok here is my code, for the rendering section of the bump mapping code. As you can probly tell, i am using NeHe's tutorial 22 to do my emboss bump mapping, but here is where i get SERIOUSLY lost. I have made copies of there two following functions, they are used to extract the bump data, i believe. The last function is one i have created to bump map a stage. Here is my delema, in NeHes tutorial he uses the variables N, S, T. He was using a simple square, I am however using a series of vertex arrays. Is the N (normal) for a face, or for a vertex? Cause right now, i have only vertex normals, I could find face normals, if necesary. Also, i have No idea how to find S,T, or even what they are. Am I attempting to do something unduable with vertex arrays?? Im sorry, im really slow when it comes to stuff like this, thanks for any help you may give me.

void VMatMult(GLfloat *M, GLfloat *v)
{
GLfloat res[3];
res[0]=M[ 0]*v[0]+M[ 1]*v[1]+M[ 2]*v[2]+M[ 3]*v[3];
res[1]=M[ 4]*v[0]+M[ 5]*v[1]+M[ 6]*v[2]+M[ 7]*v[3];
res[2]=M[ 8]*v[0]+M[ 9]*v[1]+M[10]*v[2]+M[11]*v[3];;
v[0]=res[0];
v[1]=res[1];
v[2]=res[2];
v[3]=M[15];
}

void SetUpBumps(GLfloat *n, GLfloat *c, GLfloat *l, GLfloat *s, GLfloat *t)
{
GLfloat v[3];
GLfloat lenQ;

// Calculate v From Current Vector c To Lightposition And Normalize v
v[0]=l[0]-c[0];
v[1]=l[1]-c[1];
v[2]=l[2]-c[2];
lenQ=(GLfloat) sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);
v[0]/=lenQ;
v[1]/=lenQ;
v[2]/=lenQ;
// Project v Such That We Get Two Values Along Each Texture-Coordinat Axis.
c[0]=(s[0]*v[0]+s[1]*v[1]+s[2]*v[2])*MAX_EMBOSS;
c[1]=(t[0]*v[0]+t[1]*v[1]+t[2]*v[2])*MAX_EMBOSS;
}

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(CamPos[x], CamPos[y], CamPo[z]);
glRotatef(CamOri[z], 0, 0, 1);
glRotatef(CamOri[y], 0, 1, 0);
glRotatef(CamOri[x], 1, 0, 0);

glGetFloatv(GL_MODELVIEW_MATRIX,Minv);

//Reverted
glLoadIdentity();
glRotatef(-CamOri[x], 1, 0, 0);
glRotatef(-CamOri[y], 0, 1, 0);
glRotatef(-CamOri[z], 0, 0, 1);
glTranslatef(-CamPos[x], -CamPos[y], -CamPos[z]);

//Moved
glLoadIdentity();
glRotatef(-CamOri[x], 1, 0, 0);
glRotatef(-CamOri[y], 0, 1, 0);
glRotatef(-CamOri[z], 0, 0, 1);
glTranslatef(-CamPos[x], -CamPos[y], -CamPos[z]);

// Transform The Lightposition Into Object Coordinates:
l[0]=LightPos[0];
l[1]=LightPos[1];
l[2]=LightPos[2];
l[3]=1.0f;

VMatMult(Minv,l);

//Map Rendering
if(MultiTextureSupport == true && CompiledVertexArraySupport == true)
{
ilGenImages(1, &MapImage);
ilBindImage(MapImage);
ilutEnable(ILUT_OPENGL_CONV);
ilLoadImage((char *) &MapTextureName);
glGenTextures(1, MapBaseTex);
glBindTexture(GL_TEXTURE_2D, MapBaseTex[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR_MIPMAP_NEAREST);
ilutGLBuildMipmaps();
ilDeleteImages(1, &MapImage);

ilGenImages(1, &MapBumpImage);
ilBindImage(MapBumpImage);
ilLoadImage((char *) &MapBumpTextureName);
ilConvertImage(IL_BGR, IL_UNSIGNED_BYTE);
glPixelTransferf(GL_RED_SCALE, 0.5f);
glPixelTransferf(GL_GREEN_SCALE, 0.5f);
glPixelTransferf(GL_BLUE_SCALE, 0.5f);
glGenTextures(1, MapBumpTex);
glBindTexture(GL_TEXTURE_2D, MapBumpTex[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR_MIPMAP_NEAREST);
ilutGLBuildMipmaps();
ilDeleteImages(1, &MapBumpImage);

iluNegative();

ilGenImages(1, &MapInvBumpImage);
ilBindImage(MapInvBumpImage);
ilLoadImage((char *) &MapBumpTextureName);
glGenTextures(1, MapInvBumpTex);
glBindTexture(GL_TEXTURE_2D, MapInvBumpTex[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR_MIPMAP_NEAREST);
ilutGLBindMipmaps();
ilDeleteImages(1, &MapInvBumpImage);

glPixelTransferf(GL_RED_SCALE,1.0f);
glPixelTransferf(GL_GREEN_SCALE,1.0f);
glPixelTransferf(GL_BLUE_SCALE,1.0f);

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, MapBumpTex[0]);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_REPLACE);

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, MapInvBumpTex[0]);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_ADD);

glDisable(GL_BLEND);
glDisable(GL_LIGHTING);

/////////////////////////Lost starting here
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(3, GL_FLOAT, 0, &Map.Texture1PT);
////////////////////////Lost till here

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,MapBaseTex[0]);
glBlendFunc(GL_DST_COLOR,GL_SRC_COLOR);
glEnable(GL_BLEND);
glEnable(GL_LIGHTING);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(3, GL_FLOAT, 0, &Map.Texture1PT);

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, &Map.VertPT);
glNormalPointer(GL_FLOAT, 0, &Map.NormalPT);

//fix the count to the correct values (all floats, or just verts??)
glLockArraysEXT(0, Map.NumInterleavedVerts);
glDrawElements(GL_TRIANGLES, 0, GL_UNSIGNED_INT, &Map.VertIndexPT);
glUnlockArraysEXT();

dorbie
06-04-2002, 04:28 AM
I'm not sure I totally follow you.

I think what you require is the tangent and binormal vectors. You should look for online tutorials on this.
http://www.dorbie.com/bumplogo.html

has some stuff that might help about half way down, but something better may be available elsewhere.

I generate my model procedurally. What you need to do is look at the derivitive of s & t texture coordinate change across primitives and use that to calculate the tangent and binormal vectors. These can then be used to project the light vector into tangent space. Once there you can use the tangent and binormal components of the light vector as the texture translation values for s & t.

Good Luck.

gdelarosa
06-04-2002, 05:57 AM
You should use vertex normals, but the bumpmap technique you are using in the SetupBumps function doesn't use the normal so it's not important. S and T are the texture coordinates of each vertex. These are usually defined in the model file where you read the vertex array from. If the vertex data you use does not have any texture coordinates then you will have to define them yourself. You can use whatever you want for them.