help: turn 2-pass blend into 1-pass multitex+combine

Hiya!

I’m coding some terrain stuff and i use the typical 2-texture approach in which you use two layers (grass and rock) and use per-vertex alpha colors to blend these two.

Right now we are using 2 passes and alpha, and I wonder if it can be done in a single pass with a card with 2 TMUs and multitexturing…

I’ve seen a demo on multitex using INTERPOLATE as a parameter for the COMBINE_EXT to get A*C1 + (1-A)*C2 done in a pass, but A was embedded as the alpha channel of one of the two textures, so I need to know if the same is possible with 2 non-alpha textures and using glColor4f to specify the blend factor.

thanx,

That should be possible with the GL_EXT_texture_env_combine extension.

Yes, what i am asking is HOW to get that done using the GL_EXT_texture_env_combine…

Originally posted by Humus:
That should be possible with the GL_EXT_texture_env_combine extension.

Should be something like this:

glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, GL_PRIMARY_COLOR_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_SRC_ALPHA);

This bit replaces the code that sets the second texture’s alpha as one of the operands. Here, you take the alpha of the primary color instead.

  • Tom

[This message has been edited by Tom Nuydens (edited 02-05-2001).]

you are using 3 TMUs? (0,1,2)? still doesn’t work… using the following setup code:

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
tm.usetexture(tex1);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);

// layer 2: modulate incoming color+texture
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
tm.usetexture(tex2);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE_EXT);
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_EXT,GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB_EXT,GL_PREVIOUS_EXT);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB_EXT, GL_PRIMARY_COLOR_EXT);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_RGB_EXT,GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_ALPHA);

Originally posted by Tom Nuydens:
[b]Should be something like this:

[quote]

glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, GL_PRIMARY_COLOR_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_SRC_ALPHA);

This bit replaces the code that sets the second texture’s alpha as one of the operands. Here, you take the alpha of the primary color instead.

  • Tom

[This message has been edited by Tom Nuydens (edited 02-05-2001).][/b][/QUOTE]

I think you should replace
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_EXT,GL_MODULATE);
with
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_EXT,GL_INTERPOLATE);

Alpha should also be SOURCE2.

[This message has been edited by Humus (edited 02-05-2001).]

aphex, Source2 does not imply a 3rd texture unit. Source2 can be primary color, texture environment color, texture, one, zero, or previous.

[This message has been edited by DFrey (edited 02-05-2001).]