Jump to content
  • Advertisement
Sign in to follow this  
Calexus

Any texture combiner experts out there?

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

I need some help using texture combiners. The thing is I’m trying to replicate a simple shader using texture combiners. Problem is I just don’t get texture combiners. This is what I have: One 8 bit texture (grey scale image) and one 24 bit texture (RGB) and I would like to use the first one as an alpha mask for the second. And no I can’t use a texture with an alpha. This is what I did after some googling: Load the second image as an ordinary texture, no problem. Load the first image as a GL_ALPHA texture, never used one of those before but it seems to be working. Next steep: do some fancy combiner magic… Problem,I simply don’t get combiners and everything turns out black when rendering. Then render some stuff. It’s possible to do this using combiners, right? Could someone give me a hint or two?

Share this post


Link to post
Share on other sites
Advertisement
Is it? That’s not the way my light maps work, but I don’t use texture combiners for those so maybe you’re right.

But a light map makes things lighter / darker depending of the value in the light map.
What I want to do is use the RGB from my texture and the Alpha from my alpha mask to make parts of the texture transparent. Like a normal RGBA texture.

I don’t have access to my code right now but I have found a post with the same problem
http://www.gamedev.net/community/forums/topic.asp?topic_id=327083
and I tried what Brother Bob suggested but wasn’t able to get it to work.

Share this post


Link to post
Share on other sites
Ohhh I see, I'm sorry, I read it as for sure that you were taking an ordinary texture and rendering alpha values over it for lighting (which, by definition, is a lightmap).

You are actually looking for texture combiners, like cookie cutters for images right? I would do that in my loading routines, but if you need to do it live for in a game that may not be an option, and that's an option I'm not equipped to handle (being relatively new to OpenGL).

I guess someone else will have to try to help you, because I know that's the approach I would take and I wouldn't even consider OpenGL for such work. Hope you get it to work.

Share this post


Link to post
Share on other sites
Quote:
Original post by Calexus
I don’t have access to my code right now but I have found a post with the same problem
http://www.gamedev.net/community/forums/topic.asp?topic_id=327083
and I tried what Brother Bob suggested but wasn’t able to get it to work.

Brother Bob's approach is perfectly correct. He forgot to include the commands specifying the operands, so his code might or might not work out of the box (I don't remember the default behaviour, when no operand source is specified).

Basically, you would bind your alpha texture on unit 0, and your colour texture on unit 1. Make sure that the image in unit 0 will actually expose valid alpha information, means you need to use GL_ALPHA8, GL_INTENSITY8 or similar as an internal format.

Now, the first unit will simply pass (GL_REPLACE) the texture alpha (arg0_alpha is GL_SRC_ALPHA from GL_TEXTURE) to the second unit, and ignore all colour information:

glActiveTexture(GL_TEXTURE0);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);



On the second unit, you would take the colour information from the texture bound to it (arg0_rgb is GL_SRC_COLOR from GL_TEXTURE), and get the alpha from the previous unit (arg0_alpha is GL_SRC_ALPHA from GL_PREVIOUS):

glActiveTexture(GL_TEXTURE1);
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);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);

glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);


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!