Multitexturing

Started by
11 comments, last by MV 20 years, 5 months ago
Hi, I would like to know if it is possible, using ARB extension, to blend 2 textures "following" a mask being a third texture. For example using texture C (greyscale), Opengl should blend texture A and B, using texture A for black values of C, texture B for white values and 50% of A and B for grey values. And if it is possible, how to do it ?
Advertisement
Yes, you can do it using ARB_texture_env_combine and ARB_texture_env_crossbar or NV_texture_env_combine4 extension:

With ARB_texture_env_combine you have the following operation GL_INTERPOLATE_ARB available. You can use it the following way:

glActiveTextureARB(GL_TEXTURE0_ARB);glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, your_texture_A);glActiveTextureARB(GL_TEXTURE1_ARB);glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, your_texture_B);glActiveTextureARB(GL_TEXTURE1_ARB);glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, your_greyscale_texture);glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_TEXTURE_ENV_COMBINE);glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COMBINE, GL_INTERPOLATE_ARB);glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE0_ARB);glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE1_ARB);glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_TEXTURE2_ARB);


The Interpolation here is done with:
result_color = color_of_texture_A * greyscale + color_of_texture_B * (1 - greyscale)

For more information see
http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_env_combine.txt

Hope this will help!

--------------------------------------------------------

"If it looks good, it is good computer graphics"
"If it looks like computer graphics, it is bad computer graphics"

Corrail
corrail@gmx.at
ICQ#59184081
--------------------------------------------------------There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.There is another theory which states that this has already happened...
click!
Gheez, Corrail, you got me by the time I used the search feature. Gotta wait for the next forums which have much faster search functions
Great ! Thx you 2 !!!

I was thinking using this technique for terrain transitions.
What do you think about this ?
That is certainly a bad idea, because that''s exactly what we''re doing for our terrain engine

In fact, it''s very good as long as you have to blend between two textures (grass<->rock), but when it comes to blend three textures (grass<->rock<->sand<->grass) this isn''t enough.

jm2c
Heis ppl...

First of All: Corrail, you have a little bug in your code:
glActiveTextureARB(GL_TEXTURE0_ARB);glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, your_texture_A);glActiveTextureARB(GL_TEXTURE1_ARB);glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, your_texture_B);glActiveTextureARB(GL_TEXTURE1_ARB); => should be GL_TEXTURE2_ARBglEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, your_greyscale_texture); 

But thats ok....

Ok, this is using 3 textures and 3 slots! But I thinck that is possible using the same efect when the slot2 texture is 32 bits! How to do alpha blend between textures?
Techno Grooves
My last question, but I think Vincoof has answered : how many textures can be used for multitexturing ?

Should 3 textures be used with rgb chanels of a 4th texture indicating the percentage of the blending ?
r -> % of 1st texture
g -> % of 2nd texture
b -> % of 3rd texture

@vincoof :-P

@Filami
*damn* My codes never will be perfect... :-)

I think you can realize this with only 2 textures using GL_OPERAND_RGB_ARB:

texture_A: 32 Bit RGBA texture where the RGB values represent the 24 Bit texture and the 8 Bit Alpha represents your grayscale texture
texture_B: normal 24 Bit RGB texture

// Texture Stage 0
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture_A);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_TEXTURE_ENV_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COMBINE, GL_REPLACE_ARB);

// copying the alpha value in the first texture environment
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE0_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERANT0_RGB_ARB, GL_SRC_ALPHA);

// Texture Stage 1
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture_B);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_TEXTURE_ENV_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COMBINE, GL_INTERPOLATE_ARB);

// Using Alpha value from previous texture environment
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE0_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE1_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_PREVIOUS_ARB);


Hope this will work!

--------------------------------------------------------

"If it looks good, it is good computer graphics"
"If it looks like computer graphics, it is bad computer graphics"

Corrail
corrail@gmx.at
ICQ#59184081

[edited by - Corrail on October 23, 2003 10:39:29 AM]

[edited by - Corrail on October 23, 2003 10:40:38 AM]
--------------------------------------------------------There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.There is another theory which states that this has already happened...
Thanck you Corrail...It''s pretty damn complicated that expressions...but I thinck I can figure it out! At least I''m hightlighted!
Techno Grooves

This topic is closed to new replies.

Advertisement