PDA

View Full Version : bump mapped bullet hole



Kaycee
01-31-2002, 07:21 PM
What I am trying to do is bump map bullet holes that can be applied on any object. The bullet hole is just a decal. It has a alpha texture, which when inverted is the bump map.
It should look like a dent when it works and it does but you can see the quad of the decal so it looks bad. It looks like a white square with a bump in the middle. How can I get it to blend with the object that it is applied to and still look bump mapped?

Here is what I am using to bump it,



glActiveTextureARB( GL_TEXTURE0_ARB );

glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT );

//RGB
glTexEnvf( GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE );
glTexEnvf( GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE );
glTexEnvf( GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR );
glTexEnvf( GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT );
glTexEnvf( GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR );
//alpha
glTexEnvf( GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE );
glTexEnvf( GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE );
glTexEnvf( GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_EXT, GL_SRC_ALPHA );

glActiveTextureARB( GL_TEXTURE1_ARB );

glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT );

//RGB
glTexEnvf( GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_REPLACE );
glTexEnvf( GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_PREVIOUS_EXT );
glTexEnvf( GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR );
//alpha
glTexEnvf( GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_ADD_SIGNED_EXT );
glTexEnvf( GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE );
glTexEnvf( GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_EXT, GL_ONE_MINUS_SRC_ALPHA );
glTexEnvf( GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_EXT, GL_PREVIOUS_EXT );
glTexEnvf( GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_EXT, GL_SRC_ALPHA );

glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ZERO );

glColor4f( 1.0f, 1.0f, 1.0f, 0.0f );
//draw decals


I have tried a couple other blend modes but it always loses the bump.

Any help would be greatly appreciated.
Thanks

[This message has been edited by Kaycee (edited 01-31-2002).]

knackered
02-02-2002, 03:40 AM
How would the alpha channel of your decal texture be the bump map? For bump maps you need to compress xyz vectors into rgb texels, how can you get a vector from a single alpha value?

Nervus
02-02-2002, 02:27 PM
Originally posted by knackered:
How would the alpha channel of your decal texture be the bump map? For bump maps you need to compress xyz vectors into rgb texels, how can you get a vector from a single alpha value?


Actually... it can, the resulted effect is not per-pixel bump mapping, but emboss bump mapping.
So, you load the texture w/ alpha encoded bumpmap (bumpmap will be some sort of heightmap), in both texture units, then you set the combiners as I shown you below, and then compute the texture coordinates for the 2nd texture unit according to the bump equation L*N, and draw the multitextured quad..., and that's it.
Below you will se the code for shader setup.

good luck!
PS: You need GL_EXT_texture_env_combine, and it works on TNT2 or greater just fine.
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,tex0);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_REPLACE);
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 1.00);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE0_ARB);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);

glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE);
glTexEnvf(GL_TEXTURE_ENV, GL_ALPHA_SCALE, 1.00);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE0_ARB);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_EXT, GL_SRC_ALPHA);

//combiner1 setup

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,tex1);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_REPLACE);
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 1.00);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_PREVIOUS_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);

glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_ADD_SIGNED_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_ALPHA_SCALE, 2.00);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_PREVIOUS_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_EXT, GL_ONE_MINUS_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_EXT, GL_TEXTURE1_ARB);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_EXT, GL_SRC_ALPHA);

Nervus
02-02-2002, 02:32 PM
BTW, if you want I have a very good tool for GL_ext_texture_env_combine I also use.
It's on my site at http://nervus.go.ro under the resource tab.

Nervus
02-02-2002, 02:36 PM
I almost forgot the main subject : the bumpiness.

You shoul try using GL_ADD_SIGNED_EXT if want to keep the bumpy effect of your decals.

Over and out. http://www.opengl.org/discussion_boards/ubb/smile.gif