# Bumpmap issues

6 replies to this topic

### #1Rassilon

New Member

• Members
• 6 posts

Posted 05 April 2005 - 10:52 AM

Hello its my first time posting in these forums so excuse the newbie question...

I have an interesting dilemma....Tonight I finally figured out how to implement bumpmaps but for some reason just as soon as I add them in all my textures go black except for spectural light....I am using glMaterial to colorise and have blending disabled but unfortunately this also disables my ability to properly colorise the base texture....

Here is a simple rundown of what I do to enable my bumpmaps and draw...

glDisable(GL_BLEND);
glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D, id1);

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);

glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_PREVIOUS_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_ALPHA);

glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR);

glEnable(GL_TEXTURE_2D);

// The DOT3 Bumpmap Texture
if (g_useEXTdot3) {
glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, id2);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_DOT3_RGBA_EXT);

glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_PRIMARY_COLOR_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);

glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR);

glEnable(GL_TEXTURE_2D);
}
glMaterialfv(GL_FRONT, GL_AMBIENT, white);
glMaterialfv(GL_FRONT, GL_DIFFUSE, white);
glMaterialfv(GL_FRONT, GL_SPECULAR, white);
glMaterialf(GL_FRONT, GL_SHININESS, 100);

all the drawing stuff


It bumps just great and draws the texture underneath but it seems to me the regular material color commands arent going to cut it here...because I only get a small patch of light on my quad like a large specular reflection....Is it something to do with my combiners? Do I have to add in some extra combiners to get it to be properly lit? All I know is everything went to black when I added bumpmaps...I take them out and everything looks fine...

Heres a sample image of what it looks like when bumps are enabled...
http://celestialvisi...t/pics/bbm1.jpg

And disabled:
http://celestialvisi...t/pics/bbm2.jpg

Its still dark but its the random color that was chosen for that planet...

### #2Rassilon

New Member

• Members
• 6 posts

Posted 05 April 2005 - 06:04 PM

Out of 33 people that have viewed this no one has a clue whats happening?

I know I dont....I know one thing Ive boiled it down to the normal map...When combined with the base texture it darkens or burns the mesh....so how do I lighten my bumpmap? My god man there HAS to be a way to do this it cant be that difficult!

### #3TheColonial

New Member

• Members
• 9 posts

Posted 06 April 2005 - 07:17 AM

I'm not a guru on bump mapping, but perhaps I can suggest taking a look at Ultimate Game Programming. Click on the "tutorials" link at the top, then select "Open GL" in the "game/graphics" section, and select page "12" at the bottom. There are a few tutorials on dot3 bump mapping, and some more using glsl.

Grab the tutorials, and cross check against the working code to make sure you're doing what they're doing. Hope that helps!
In order to understand recursion, one must first understand recursion.

### #4Rassilon

New Member

• Members
• 6 posts

Posted 06 April 2005 - 06:49 PM

TheColonial said:

I'm not a guru on bump mapping, but perhaps I can suggest taking a look at Ultimate Game Programming. Click on the "tutorials" link at the top, then select "Open GL" in the "game/graphics" section, and select page "12" at the bottom. There are a few tutorials on dot3 bump mapping, and some more using glsl.

Grab the tutorials, and cross check against the working code to make sure you're doing what they're doing. Hope that helps!

I found a solution...One, this isnt true bumpmapping....Its just combiners making a dot3 embross...True bumpmapping involves a cube map and vertex tangents...Im already working on a solution and Ill definately take a look at those tuts...Right now I need all the help I can get in the math dept!

### #5Reedbeta

DevMaster Staff

• 5307 posts
• LocationBellevue, WA

Posted 06 April 2005 - 07:19 PM

I haven't really looked at your code, since ARB combiner setup code is really hard to read. But this is the code I use to setup the combiners for dot3 bump-mapping:

// Combiner 0: RGB = dot3(tex0, tex1), where tex0 = per-fragment normal, tex1 = per-fragment light vector
glActiveTextureARB(GL_TEXTURE0_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE0_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE1_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_DOT3_RGB_ARB);

// Combiner 0: Alpha = tex2 - primary, where tex2 = 1 - s^2 - t^2, primary = r^2
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE2_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_ARB, GL_SRC_ALPHA);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_ARB, GL_PRIMARY_COLOR_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_SUBTRACT_ARB);

// Combiner 1: RGB = previous.RGB * previous.alpha
glActiveTextureARB(GL_TEXTURE1_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_ALPHA);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);

// Combiner 2: RGB = previous * diffuse
glActiveTextureARB(GL_TEXTURE2_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE3_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);

// Combiner 3: RGB = previous * constant, where constant = light color
glActiveTextureARB(GL_TEXTURE3_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_CONSTANT_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);

Here I am doing per-pixel dot3 and attentuation, using two normalization cubemaps in tex0-tex1, an attentuation map in tex2, and the diffuse map in tex3. I also use the primary color (glColor3f color) to give the squared distance from the light source to the polygon plane (for attentuation), and the texture environment constant color (glTexEnvfv color) to store the light color.

A working demo can be downloaded from http://pages.pomona....004/opengl.html (the program is called 'combiners').

Hope this assists you.
reedbeta.com - developer blog, OpenGL demos, and other projects

### #6Rassilon

New Member

• Members
• 6 posts

Posted 06 April 2005 - 11:36 PM

Yes thats quite a bit more than I was looking for but it seems it might be my only option...using cubemaps because the plain old bumpmap although it looks nicer than none at all doesnt follow the light source like I want...It just basically gives the texture more depth which I can do in Photoshop so anything other than a cubemap to compute the light vector is a waste of time..and memory....as I found out the hard way....

### #7Reedbeta

DevMaster Staff

• 5307 posts
• LocationBellevue, WA

Posted 07 April 2005 - 06:58 AM

You can get away without a cubemap if your mesh is finely tesselated. To do proper bumpmapping you need a cubemap though, otherwise the light will look too dark near the centers of triangles. You don't have to do attentuation though - I threw that into mine as an extra bell and whistle.

BTW I was incorrect in my earlier post - it's actually the normal map in tex0 and a single normalization-cubemap in tex1 (d'oh).
reedbeta.com - developer blog, OpenGL demos, and other projects

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users