Jump to content
  • Advertisement
Sign in to follow this  
Sir Sapo

Masking and Blending

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

Is it possible to mask a texture but still be able to change it's opacity without ruining the masking effect? What I'm trying to do is have a masked smoke texture that is faded as it rises into the air. Thanks in Advance

Share this post


Link to post
Share on other sites
Advertisement
If I get what you're asking, then yes. You can mask a texture, ie with an alpha channel or a separate alpha component texture, and still use vertex alpha to fade the whole primitive. The vertex alpha will be interpolated, then multiplied by the alpha channel alpha (with default texture combine settings, that is; these can be tweaked if desired).

Share this post


Link to post
Share on other sites
So would this work (sorry, I'm away from my compiler right now):


glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);

glBlendFunc(GL_DST_COLOR,GL_ZERO);

glBindTexture(GL_TEXTURE_2D , mask);
glColor4f(1.0 , 1.0 , 1.0 , 0.5); //for the transparency



glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.51f, -0.51f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.51f, -0.51f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.51f, 0.51f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.51f, 0.51f, 0.0f);
glEnd();

glBlendFunc(GL_ONE, GL_ONE);
glBindTexture(GL_TEXTURE_2D , img);

glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.51f, -0.51f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.51f, -0.51f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.51f, 0.51f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.51f, 0.51f, 0.0f);
glEnd();

glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);



Share this post


Link to post
Share on other sites
Too tired right now to puzzle through exactly what you're trying to accomplish here with this multi-pass tomfoolery...

The way I always did it was to have textures that either have an alpha channel built in for transparency (RGBA), or use multi-texturing and some tweaked texture combine settings, and put the RGB colormap in the first stage (using GL_MODULATE) and the mask as an 8-bit alpha texture in the second stage (using GL_REPLACE; check out the extension spec for ARB_texture_env_combine for details on how to do it using this extension; you could probably accomplish the same using shaders). Then I would use glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) to do the blending in one pass.

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!