Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

MV

Multitexturing

This topic is 5440 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 ?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Great ! Thx you 2 !!!

I was thinking using this technique for terrain transitions.
What do you think about this ?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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_ARB
glEnable(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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
@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]

Share this post


Link to post
Share on other sites
Thanck you Corrail...It''s pretty damn complicated that expressions...but I thinck I can figure it out! At least I''m hightlighted!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!