Archived

This topic is now archived and is closed to further replies.

Supernova

Tutorial #20 and alpha blending question

Recommended Posts

Supernova    122
I think I understand how the masking works, but the way it''s done you can''t have semi-transparency of the texture you''re drawing this way. Since you first draw the black mask (white parts aren''t drawn) and then just copy the pixels from the texture to the corresponding black parts of the mask. Getting to the point, is there a way to not draw certain parts of a texture completely (like is done with masking), and other parts semi-transparently (using alpha values)? Doesn''t have to be using this method. I just haven''t seen or have been able to understand yet any others. Technically, I know that you can blend the mask (destination) and texture (source) together but I want to blend what''s UNDER the mask with the texture. I hope that makes sense.

Share this post


Link to post
Share on other sites
Obelix    122
Using an alpha test is the usual way to do masking and I think the tutorial text is mentioned it. I guess that if the alpha test pass can then normal blending be done. You have to sacrifice a alpha value for the test but it should not make any difference in most cases.

Share this post


Link to post
Share on other sites
Supernova    122
Could you explain this in more detail or give an example with code? I was thinking about this, and basically what I came up with is test the image alpha, if it's 1.0 then use an alpha provided in the code, otherwise (it would be 0.0) use the image alpha (makes it 100% transparent). But how would you do that?

Edited by - Supernova on June 29, 2001 12:11:04 PM

Share this post


Link to post
Share on other sites
Obelix    122
Alpha testing is something you get with glEnable. You set it up so it will test the image alpha and accept/reject the fragment. In other words do you get masking.

Blendings is also something you will have to enable. I think it is described in tutorial 8.

I have never tested it but I do not see any reasons why you can not have both enabled. Some parts will be cut off by the alpha test and others will be blended.

If you are not sure can you first try alpha testing and blending in separate programs before you combine them. Many sources is available like the red book.

Share this post


Link to post
Share on other sites
Supernova    122
Never mind, it seems to work without alpha testing. Apparently when you use an image with an alpha channel, OpenGL multiplies the alpha you want to use by the image alpha. Since all the transparent pixels of the image have alpha 0.0, mutliplying any number by that gives 0.0 also. The non-transparent pixels have alpha 1.0, so multiplying them by a given alpha makes them partially transparent. I think this is how it works.

Share this post


Link to post
Share on other sites
Obelix    122
You probably have to use alpha testing anyway to avoid writing to the Z-buffer. Take a look at this little demonstration from ATI http://www.ati.com/na/pages/resource_centre/dev_rel/sdk/rage128sdk/OpenGL/Samples/Rage128AlphaTest.html

It is also a more general solution if you want to blend in some other way.

Oh, I just realised that you will not update the Z-buffer anyway in this example because of the semi transparent stuff. I post it anyway so I get the last word.

Share this post


Link to post
Share on other sites