Jump to content
  • Advertisement
Sign in to follow this  
systemis

texture / multitexture / alpha masking questions

This topic is 4857 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 all, this is my first posting to the forums, so let me say a huge thanks for all that I've learned on this forum. I have a question for the texture gurus out there. Basically, I have an image, and the situation that I need to draw selective sections of it in the foreground, on top of everything else in the scene. I need the edged to be transparent (like a mask), so a stencil buffer won't work for me. ie :
      -  ----			<-- top
	other stuff 	
------ --    ----		<-- bottom
What I've done is to draw the image twice, first as the background, and then, using an alpha teture and color mask calls:

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1,1,1,1.0f);
cameraImg.drawNoUpload(0,0,1024,768);			// RGB texture

// draw stuff here using various blend modes, etc
/*
....
*/

glDisable(GL_BLEND);
glColorMask(0, 0, 0, 1);
glEnable(GL_TEXTURE_2D);
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
glColor4f(1,1,1,1.0f);
maskTex->renderTexture(0,0,1024,768);			// ALPHA texture

glColorMask(1,1,1,0);
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
glEnable(GL_BLEND);
glBlendFunc( GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA );
cameraImg.drawNoUpload(0,0,1024,768);			// RGB texture


my question is simple, is there a faster way to do this (as this requires 3 texture passes), either through multitexturing or other approaches? many thanks, zach

Share this post


Link to post
Share on other sites
Advertisement

Could you explain in a bit more detail what you're trying to do? Perhaps a screen shot would help?

It looks as if there are faster ways to do it, and I would note that a lot of older cards don't support the alpha channel in the framebuffer and so the drivers will kick you into software mode (very slow).

~SPH

Share this post


Link to post
Share on other sites
hi -

thanks, I'm sorry for the delay, I've been traveling alot since my last email.

Here's some screenshots:

http://thesystemis.com/drawn/drawnTechnology/liveShot.jpg
http://thesystemis.com/drawn/drawnTechnology/technology.jpg

the techniques I am using are for a performance (http://www.thesystemis.com/drawn) in which I paint ink live and manipulate the paintings.

It's a kind of magic show.

one technique I use is to composite my "hand" pixels on top of the scene, as you can see in the technology.jpg. I have an alpha mask which I use, but it's important that it be 8bit, and not 1bit (ie. stencil) since I need to blur it a bit for the technique to be believable.

I do the following:

+ + + + + + + + + + + + + +


(a) draw the incoming video (BRG texture)

(b) draw the ink in the scene (various BGR textures, luminance textures, etc)

(c) draw the alpha mask for the hand pixels (luminance) via (glColorMask(0, 0, 0, 1))

(d) draw the incoming video again (BGR texture) via (glColorMask(1,1,1,0))

+ + + + + + + + + + + + + +

I'd love to know if there is a way to optimize it since it seems to run very slow (as you mention) on my laptop and I'd be happier with less texture passes in general.

thanks for any advice you might have....

again, kudos to this forum, it's a great source of information and inspiration.

ciao,
zach

Share this post


Link to post
Share on other sites
Wow, that's really cool.

Quote:
Original post by systemis
I do the following:

+ + + + + + + + + + + + + +

(a) draw the incoming video (BRG texture)

(b) draw the ink in the scene (various BGR textures, luminance textures, etc)

(c) draw the alpha mask for the hand pixels (luminance) via (glColorMask(0, 0, 0, 1))

(d) draw the incoming video again (BGR texture) via (glColorMask(1,1,1,0))

+ + + + + + + + + + + + + +
You should be able to combine (c) and (d) using multitexturing and texture env combiners (GL_ARB_texture_env_combine spec, it's part of core OpenGL now but on Windows you will still need to access it like any other extension - read this if you've never used extensions before, then do yourself a favor and use GLee or GLEW to access them). It would be something like this...

//Enable blending just like you posted in your opening post
//except now since the alpha and rgb texture will be combined
//we use source alpha instead of destination alpha.
//Also enable alpha test to ignore any alpha value of 0.
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.0f);

//Set rgb texture to texunit 0 and set texenv to replace (or modulate
//if you want to use lighting or add a hue with glColor*)
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, alphaTex);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

//Set alpha texture to texunit 1 and set up texenv with
//correct combine settings
glActiveTexture(GL_TEXTURE1);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, rgbTex);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS); //get color from previous environment
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); //(texunit0, possibly modulated)
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE); //get alpha from texunit 1
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);

//
// Render here
//

//Disable textures and blending
glDisable(GL_TEXTURE_2D); //disables texunit1 since that's still the active texture
glActiveTexture(GL_TEXTURE0);
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);



There might be a problem or two in that since I haven't tested it, but the logic is valid.

You may be able to combine the different textures used in (b) using texture combiners as well, check the spec (link above), or the OpenGL spec since it is in the core now, for the different combine modes.

If you can, I highly recommend ignoring all that and using shaders though. Depending on your hardware and how many textures you use in (b) you may be able to squeeze all of it into a single pass.

You might also be able to gain some speed by rendering (b) into a texture (FBO or pbuffer) and then in a shader combine that texture with (c) and (d) in some way so that you don't need to render the background in (a) first.

The shaders and FBO stuff might not apply though, what video card do you have in your laptop? Just getting a new video card may speed up what you're currently doing enough for your purposes. Switching video cards for a laptop can be a pain however.

Anyway, I hope that helps and good luck.

PS: I sent you a PM.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!