How to introduce Specular and Diffuse lighting into Bumped lighting

Hi there. I’m new here, as well as with OpenGL, so bear with me if my question is simple or my post is in the wrong section.

Basically I have a pretty good understanding of how to do simple diffuse lighting as well as specular, just using the standard GL light package. The problem is, when I introduced Bump-mapping, I found that the lighting system no longer seems to affect my textures… be it the decal, normal map, or even cubemap.

Of course I’m using DOT3, with 3 texture units combining everything together. The bump mapping works fine, the problem is simply that I cannot figure out how to vary the intesity of the result (from the cube x normal map). I’m not using tangent space because my objects are always going to be facing the viewer (or at least very closely).

Is there a way to get lighting to work on the 3rd texture unit? Do I need to add a 4th unit?

Or do I just need to do 2 passes to enable lighting? Or change blending states? I just don’t want to have to move the imaginary software bump-light position just to adjust intensity, which is what I’m doing now, which definitely feels like a hack. :slight_smile:

Thanks for pointing me the right way! I’ll provide some code if it’s really needed, but this is pretty basic.

I’ll go ahead and post the texture environment setup just before the drawing code, which I’ll leave out. The blending mode is (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA), with no changes throughout the program. Various lights and styles are enabled but have no effect?

Another thing, if I take the result from the 2nd unit and GL_ADD it with the decal, it seems to sort of provide a “fake” specular effect to the final bumped image… is this something people use often to immitate real specular highlights? Because it does look fairly nice if the angle to the light position is set up just right, I assume this is because the decal colors are being “washed out” with higher color values combined with clamping to get shades of white. Is there another combiner I should be using besides GL_MODULATE, for any reason?

///////////////////////////////////////
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_CUBE_MAP);
glDisable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_CUBE_MAP, normalCubeMap);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE) ;
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE) ;
Map).

glActiveTexture(GL_TEXTURE1);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, bgBump[0].texID);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_DOT3_RGB) ;
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS) ;
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE) ;

glActiveTexture(GL_TEXTURE2);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, bgTex[0].texID);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); // OR GL_ADD ???

Is there a way to get lighting to work on the 3rd texture unit? Do I need to add a 4th unit?
You don’t really seem to understand what it is you’re doing when you use some form of bump mapping.

Bump mapping is a method for adjusting the normals of a surface per-pixel such that the surface appears rough under lighting conditions. Because the bumps are a per-pixel thing (taken from some form of texture), your lighting must therefore be computed per-pixel.

OpenGL’s fixed-function lighting is a per-vertex effect, not a per-pixel one. As such, it doesn’t make sense to combine the two. If you have a light, and you’re computing bump mapped illumination on that light, you don’t need to put vertex lighting on top of that.

“Bumped Lighting” (as you called it) replaces the OpenGL lighting. Now, you still need to compute your lighting in both diffuse and specular, but they should both take into account the surface bump map.

Of course, I am having trouble understanding how this works, which is why I posted the question. :slight_smile: Again, I am new to OpenGL (just started a few weeks ago).

I already understand your answer, and was thinking along those lines. I just have no idea how to introduce the diffuse part without just blending/adding in another polygon to brighten things up (which I realize is another hack). So, for example, what could I adjust/add into the code above to account for a diffuse component of a single light? All I would really like is a method to account for the intensity of the light itself, not just the difference in angles between the normals and the light. This way, I think I could multiply the bump-intensity by the light intensity per-pixel, I just don’t understand what combining function I would use, whether that means using another texture unit, making a 2nd pass, or changing something within the units I’m already using to get the effect. But have faith that I completely understand that this has nothing to do with GL’s lighting system (it has been disabled for a while now in this app while coding). I just mentioned it to see if there is a way to use a vertex light as a quick-fix. If there is, there’s a good chance I’d be satisfied with it.

Given that I could understand how to implement diffuse lighting into this, I think I could inherently understand how to implement the specular part if I wanted it. I really just don’t understand how the combiners and operators work, I guess, and how to use the results of one of the first 3 units to compute diffuse/specular.

You don’t perhaps have an example or even a link showing me the right way to do it? I have searched and the only good examples of DOT3 bump-mapping I’ve found do not have any other components in the lighting model, so I’m going off nothing here. :frowning: