Any texture combiner experts out there?

Started by
3 comments, last by Yann L 18 years, 8 months ago
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?
Exitus Acta Probat
Advertisement
Perhaps you should be looking for "lightmapping", as what you've described is exactly that ;).
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.
Exitus Acta Probat
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.
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);

This topic is closed to new replies.

Advertisement