Bumpmap issues

97720fee4881ed071e520a1aba181324
0
Rassilon 101 Apr 05, 2005 at 10:52

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://celestialvisions.net/pics/bbm1.jpg

And disabled:

http://celestialvisions.net/pics/bbm2.jpg

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

6 Replies

Please log in or register to post a reply.

97720fee4881ed071e520a1aba181324
0
Rassilon 101 Apr 05, 2005 at 18:04

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!

5e1d89e267ccbd40fed3dff8a3de9085
0
TheColonial 101 Apr 06, 2005 at 07:17

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!

97720fee4881ed071e520a1aba181324
0
Rassilon 101 Apr 06, 2005 at 18:49

@TheColonial

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!

[snapback]17063[/snapback]

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!

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Apr 06, 2005 at 19:19

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.edu/\~nrr02004/opengl.html (the program is called ‘combiners’).

Hope this assists you.

97720fee4881ed071e520a1aba181324
0
Rassilon 101 Apr 06, 2005 at 23:36

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….

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Apr 07, 2005 at 06:58

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).