Jump to content
  • Advertisement
Sign in to follow this  
Subotron

Using a grayscale texture as alpha map for another

This topic is 4525 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

What I'd like to do is combine 3 textures on a quad, such that the first texture is projected on to the quad normally (no blending of any kind), and the second is put over the first one, but blended, such that the underlying texture shows through at certain places. Those certain places are defined in the grayscale texture. This means, I want to use the grayscale texture as an 'alpha channel' for the second texture. I tried several things with multitexturing, but it seems I just don't get the blend mode right or something (multitexturing gives me the 2 images blended together, but instead of black being transparent, black is just being black) I hope this makes sense, else, I can try to post some screenshots (and not-working code). Thanks a lot for the help.

Share this post


Link to post
Share on other sites
Advertisement
You can use the interpolation operator in the basic texture environment combiners.

Texture unit 0: Bind the greyscale image. What this combiner outputs is not important.
Texture unit 1: Bind one of the two texture you want to blend. Output the texture color unaltered.
Texture unit 2: Bind the other texture you want to blend. Interpolate between the texture and the output of the previous combiner, using texture unit 0 as interpolation factor.

Something like this.

glActiveTexture(GL_TEXTURE0);
glBind(greyscale texture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);

glActiveTexture(GL_TEXTURE1);
glBind(one texture to blend);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);


glActiveTexture(GL_TEXTURE2);
glBind(other texture to blend);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB, GL_TEXTURE0);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_COLOR or GL_ONE_MINUS_SRC_COLOR);

Pick one of the two constants in the last line depending on what white means; full color from texture unit 1 or 2.

I hope I got that correct. Late here and I'm about to fall asleep now...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!