Sign in to follow this  
scwizzo

Understanding lighting, bump mapping, texturing

Recommended Posts

scwizzo    100
I managed to implement DOT3 bump mapping thanks to NeHe's tutorial (http://nehe.gamedev.net/data/articles/article.asp?article=20) on it. It works pretty well, but now I have come across a couple issues I can't track down with a search or by messing with parameter values. 1) The lighting works fine, but always seems to rotate with the users view point, and creates a problem with the angle of the lighting compared to where the texture thinks the light is coming from, resulting in a dark/black/non-textured model when rotated. I have tried applying GL_LIGHT_MODEL_TWO_SIDE and the only effect is had was the same thing, but on the back side of my model instead with the front being dark. 2) I cannot seem to un-bump map my textures so I can switch between normal (non-lighting) textures and bump mapped textures. The NeHe tutorial does not take care of the "clean up" needed after drawing a model that I'm looking for. Here is the code I use for bump mapping, which is basically a direct copy paste from the nehe tut, and also what I tried after drawing the model so I can draw other non-bump mapped models.
//----------------------------------
// to create the bump mapping effect

        if (mdl.TexID != NO_TEXTURE)
        {
            glActiveTextureARB(GL_TEXTURE0);
            glEnable(GL_TEXTURE_CUBE_MAP);
            glBindTexture(GL_TEXTURE_CUBE_MAP, normCubeMap);
            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) ;

            glActiveTextureARB(GL_TEXTURE1);
            glEnable(GL_TEXTURE_2D);
            glBindTexture(GL_TEXTURE_2D, mdl.normalMapID);
            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) ;

            glActiveTextureARB(GL_TEXTURE2);
            glEnable(GL_TEXTURE_2D);
            glBindTexture(GL_TEXTURE_2D, mdl.TexID);
            glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
        }

		glPolygonMode(GL_FRONT_AND_BACK, effectsList.polyFill);
        glBegin(GL_TRIANGLES);

//-----------------------------
// and the "clean up" part

        glDisable(GL_TEXTURE_CUBE_MAP);
        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
        
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);




I can/will attach pictures to show what I am talking about with the lighting. If any more code is needed let me know. EDIT: Here is an example of the lighting. The ball is the position of the light, and the line is the direction in which it is pointing. light from the front... http://sites.google.com/site/scwizzo/home/files/bump_front.jpg light from the back... http://sites.google.com/site/scwizzo/home/files/bump_back.jpg

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this