PDA

View Full Version : GL_ADD_SIGNED_EXT washing out colors?



malachii
11-11-2002, 05:29 AM
I'm trying to do some "fake bump mapping" by blending a greyscale image representing bump lighting (it is pre-lit) on top of a marble texture for this sample application.

To do this I'm using the following blending modes with 2 passes (to avoid multitexturing for the time being)

glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_CO MBINE_EXT);
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_EXT, GL_ADD_SIGNED_EXT );

It is working nicely, BUT is washing out the colors of the original texture EVEN when the greyscale from the "bump map" is 0.5 (128 in byte-speak).

Any ideas? Here are the images from my website for you to look at...

Just the marble: http://dev.wadesoft.com/bumps/marble.png

The fake bump map itself (with the top portion set to neutral gray).
http://dev.wadesoft.com/bumps/bump.png

The bad results: http://dev.wadesoft.com/bumps/results.png

Here is the full code including the texture setup code...

// prepare marble
glBindTexture(GL_TEXTURE_2D, 3);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, marbleMem);

// prepare bump map
glBindTexture(GL_TEXTURE_2D, 4);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_CO MBINE_EXT);
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_EXT, GL_ADD_SIGNED_EXT );
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, bumpMem);

// ***** DRAW bump mapped marble
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_white_diffuse);
glBindTexture(GL_TEXTURE_2D, texMarble);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
drawQuad( 4.0, 4.0, 3, 3, -10 );

**** NOTE: perhaps the problem is in the next line!!
glBlendFunc(GL_SRC_COLOR, GL_DST_COLOR);
glBindTexture(GL_TEXTURE_2D, texBump);
drawQuad( 4.0, 4.0, 3, 3, -10 );

// ****** DRAW just the marble
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_white_diffuse);
glBindTexture(GL_TEXTURE_2D, texMarble);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
drawQuad( 4.0, 4.0, 3, -3, -10 );

[This message has been edited by malachii (edited 11-11-2002).]

[This message has been edited by malachii (edited 11-11-2002).]