texture blending layers

Started by
22 comments, last by pammatt 19 years, 5 months ago
Aw... right.
It wastes texture units for forwarding color, but anyway without fragment programs you're doomed to enable all units, so ...
Advertisement
I have everything working utilizing the crossbar functionality. I'm not sure how to set up the combiner state for this layout though. (Still new to the combiner thing so please bear with me).

SOURCE2 would be the alpha map, so GL_PREVIOUS...
SOURCE1 would be the current layer, so GL_TEXTURE

now one of those sources needs to be the previous texture layer.. but I'm not sure how to get that to work without the crossbar stuff.

Thanks for the help thus far, and hopefully i'm not sounding too stupid. :-)
Anyone can complete pammatt efforts?

what will be the right combination using combiners operations... none NV or ATI specific will be more interesting... just one pass witout blending... sounds like a challenge!!! hehe

THX
Just realized, what I mean in my latest post is how to I acheive the setup DaN1maL gave.

texunit 0 - layer 1 (doesn't need mask)
texunit 1 - layer 2's mask
texunit 2 - layer 2 (use interpolate to blend using prev alpha map)
texunit 3 - layer 3's mask
texunit 4 - layer 3 (use interpolate to blend using prev alpha map)

Thanks.
// texunit 0 - layer 1 (doesn't need mask)
glActiveTextureARB(GL_TEXTURE0_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

// texunit 1 - layer 2's mask
glActiveTextureARB(GL_TEXTURE1_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);

// texunit 2 - layer 2 (use interpolate to blend using prev alpha map)
glActiveTextureARB(GL_TEXTURE2_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_ALPHA);

// texunit 3 - layer 3's mask
// texunit 4 - layer 3 (use interpolate to blend using prev alpha map)
// For textutre units 3 and 4 (and other pairs if your card support more units), simply copy'n'paste the code for texture units 1 and 2, granted you replace the GL_TEXTUREi_ARB token of course [wink]
// [edit] : BTW, instead of copy/paste, you can use display lists. In this case it's more a toy though.
I was thinking about something along those lines but I wasn't sure if it would work for the following..

given a card with 4 texture units available I would have to do some multi-pass stuff. I didn't think that setup would work for the following:

texunit 0 - layer 1 (doesn't need mask)
texunit 1 - layer 2's mask
texunit 2 - layer 2 (use interpolate to blend using prev alpha map)
-->create new render pass here
texunit 3 - layer 3's mask
texunit 4 - layer 3 (use interpolate to blend using prev alpha map)

I thought I needed to have the mask and the texture grouped in the same multi-texturing pass, so that's why I broke it up the way I did. Given this, on the second pass, the mask would reside in texunit 0, however, rendering the mask uses GL_PREVIOUS for one of the sources. Is this something I need to write code to figure out.. I was thinking I could rearrange the masks and textures if the mask falls at texunit0, but wasn't sure.

Thanks again for all of the help.
Alright, so I've been trying to get this stuff to work without success. I hate to do it.. but does anyone by any chance have some sample application I can look at.. this is driving me crazy!
Nevermind, I finally got it. It is not quite how I want it though. I wanted to use a single channel texture for the alpha map. I set the texture format to be GL_ALPHA, however, that does not work. I need to use a 32-bit RGBA texture for the mask.. not sure why though. Shouldn't the texture of the form GL_ALPHA get the job done for me?
Alright, so the next problem i'm trying to tackle is this. I was under the impression that on each render pass, I could render more than one texture layer. I'm seeing now, that I can only render more than one layer on the first render pass. On subsequent passes, each texture layer overwrites the alpha channel, therefore, when I blend each pass, the alpha information is only in the last layer rendered which is no good. Are there any nice solutions to this problem? Or am I stuck using a full pass for each remaining texture layer after the first pass is complete?

Thanks, and I know I've been posting a lot, but I'm just trying to get this stuff working nice.
Quote:Original post by pammatt
texunit 0 - layer 1 (doesn't need mask)
texunit 1 - layer 2's mask
texunit 2 - layer 2 (use interpolate to blend using prev alpha map)
-->create new render pass here
texunit 3 - layer 3's mask
texunit 4 - layer 3 (use interpolate to blend using prev alpha map)

Right. For the new render passes, you can switch mask and color (though it's not needed, it's just a thought in case it fits better your memory scheme, class management or whatever).

Quote:Original post by pammatt
I set the texture format to be GL_ALPHA, however, that does not work. I need to use a 32-bit RGBA texture for the mask.. not sure why though. Shouldn't the texture of the form GL_ALPHA get the job done for me?

Yes it should. However, it is sometimes a bit dodgy to get it working. From memory alignment to buggy drivers, there are lots of issues with alpha masking. Anyway you SHOULD be able to make it working. May I ask which card/driver/OS combo you have, and which parameters you send to glTexImage2D (or whatever texture uploading function you use) ?

Quote:Original post by pammatt
Alright, so the next problem i'm trying to tackle is this. I was under the impression that on each render pass, I could render more than one texture layer. I'm seeing now, that I can only render more than one layer on the first render pass.

Right. AFAIR that's exactly what I mentioned in my first reply to this thread.

Quote:Original post by pammatt
Are there any nice solutions to this problem? Or am I stuck using a full pass for each remaining texture layer after the first pass is complete?

Even if you can/want/need to deal with multi-path rendering (don't mistake with "multipass"), I don't think you can benefit register combiners, fragment shaders, fragment programs or-the-like. It's a blending issue, and as far as blending programs do not exist, you're stuck to multipass the way you describe.
However, if some layers have 1-bit non-filtered alpha channel (cookie-cutter like) then you can play with them sometimes. It's a bit tricky and not flexible at all though.

This topic is closed to new replies.

Advertisement