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:
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.
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_COMBINE_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_ADD);
//plain addition obviously needs two sources
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB_ARB,GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB_ARB,GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_ALPHA_ARB,GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_ALPHA_ARB,GL_TEXTURE);
//operand allows you to invert components or to expand alpha components to rgb
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_RGB_ARB,GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_RGB_ARB,GL_SRC_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
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.
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
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.