PDA

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



aphex
02-04-2001, 01:55 PM
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,

Humus
02-04-2001, 03:50 PM
That should be possible with the GL_EXT_texture_env_combine extension.

aphex
02-04-2001, 04:24 PM
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.

Tom Nuydens
02-05-2001, 03:34 AM
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).]

aphex
02-05-2001, 01:32 PM
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_MO DULATE);

// 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_CO MBINE_EXT);
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_EXT,GL_MOD ULATE);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB_EXT,GL_PRE VIOUS_EXT);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB_EXT, GL_PRIMARY_COLOR_EXT);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_RGB_EXT,GL_SR C_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_ALPHA);



Originally posted by Tom Nuydens:
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).]

Humus
02-05-2001, 01:40 PM
I think you should replace
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_EXT,GL_MOD ULATE);
with
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_EXT,GL_INT ERPOLATE);

Alpha should also be SOURCE2.


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

DFrey
02-05-2001, 01:44 PM
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).]