PDA

View Full Version : Blending and multitexturing...



tobiaso
04-05-2002, 06:53 AM
How does blending and multitexturing work?

I have made a multipass engine that works nicely. You can have a number of passes blended togeter to create nice metal effects etc (using an alphablended rusty texture on top of an an envmapped chrome texture). Unfortunately I have run into problems when I now want to move my engine into using multitexturing...

As I have understood it blending does not work "inside" a multitexturing pass. So you can not do it like this:

SetUpStuffForPassOne
glBlend(GL_ONE, GL_SERO)
SetUpStuffForPassTwo
glBlend(GL_ONE, GL_ONE)
Render!

Or am i wrong?

Must I use further extensions to create the blending modes I need? And if so which ones?

Multitexturing seems nice but pretty hard to do... if you want to have the same possibilities as when you do multipass or am I completely off?

regards

/hObbE

zeckensack
04-05-2002, 07:03 AM
What you need are texture environments. These are additional blending stages inside the texture pipe, one for each texturing unit. Core GL 1.3 already allows a host of functions to be applied there, just look at table 3.24 in the spec and pick what you like.

zeckensack
04-05-2002, 07:12 AM
Originally posted by tobiaso:
SetUpStuffForPassOne
glBlend(GL_ONE, GL_SERO)
SetUpStuffForPassTwo
glBlend(GL_ONE, GL_ONE)
Render!
To translate this example to texture environments, you can leave the first one as is and select the 'add' function in the second one.


glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D,first_texture);
glEnable(GL_TEXTURE_2D);
glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D,second_texture);
//don't forget that texture units must be enabled individually!
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_CO MBINE_ARB);
//you can select different function for rgb and alpha
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_ARB,GL_ADD );
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_ALPHA_ARB,GL_A DD);
//plain addition obviously needs two sources
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB_ARB,GL_PRE VIOUS);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB_ARB,GL_TEX TURE);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_ALPHA_ARB,GL_P REVIOUS);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_ALPHA_ARB,GL_T EXTURE);
//operand allows you to invert components or to expand alpha components to rgb
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_RGB_ARB,GL_SR C_COLOR);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_RGB_ARB,GL_SR C_COLOR);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_ALPHA_ARB,GL_ SRC_ALPHA);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_ALPHA_ARB,GL_ SRC_ALPHA);

//now you can render

DFrey
04-05-2002, 07:33 AM
Zeckensack, if you want to simply add the textures, why not use ARB_texture_env_add rather than the GL_ADD combiner, that would require much less code for this example.

On the otherhand, tobiaso, if what you are asking is if it is possible to replicate all possible two pass algorithms as one pass with multitexture, then the answer is no. All opaque algorithms are available, but not all transparent algorithms.

zeckensack
04-05-2002, 07:44 AM
Originally posted by DFrey:
Zeckensack, if you want to simply add the textures, why not use ARB_texture_env_add rather than the GL_ADD combiner, that would require much less code for this example.
Partly because I haven't used the plain environment modes for a looong time and wasn't entirely sure what's available.
OTOH, it's nice to get a start on texture_env_combie, it offers lots of flexibility and a little bit of experience with it just might come in handy when the requirements increase.
But I agree, it's a bit overkill for this particular case http://www.opengl.org/discussion_boards/ubb/wink.gif

tobiaso
04-07-2002, 10:00 PM
Thanx for the replies guys!

I will probably not dwell furter into texture environments for this engine, instead I will use multitexturing when the blending between the passes are right.

Regards!

/hObbE