Sign in to follow this  
inTranceX

Multitexturing with 3 Texture Units

Recommended Posts

inTranceX    122
Hello! Is it possible to blend 2 textures with an alpha-texture with a graphic card which has only 3 Texture Units? I would like to calculate: FinalColor = TexA*(AlphaTex) + TexB*(1-AlphaTex) Every solution I have ever seen used 4 Textures (2 normal textures and two alphas). Is there a way to do it with 3 textures? How do I have to configure the blending stages? Thanks for any advice!

Share this post


Link to post
Share on other sites
Vilem Otte    2938
Hi,

I really recommend to use shaders for solution to this. Although it can be done with several texture units ... look closer here:

Link

The best solution would probably be using GL_INTERPOLATE_EXT token for glTexEnvi (or glTexEnvf, ...) - it does this - Arg0 * (Arg2) + Arg1 * (1-Arg2), e.g. exactly what you want.
Dunno if this is correct, but it should be written like (not sure, please anybody correct me if this is wrong ... I hadn't time to test it):

// first setup first texture unit
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, TexA);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, TexB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT)
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_INTERPOLATE_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE1);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, GL_PRIMARY_COLOR_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_SRC_COLOR);

glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, AlphaTex);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_INTERPOLATE_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_PREVIOUS_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_TEXTURE2);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, GL_PRIMARY_COLOR_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_SRC_COLOR);

Share this post


Link to post
Share on other sites
inTranceX    122
Thanks for your answer - will try it later on!

Unfortunately, my graphic card has not only not more than 3 TU but also no support for Shaders :-) It's an old ATI Mobility Radeon.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this