Archived

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

Crispy

blending

Recommended Posts

Hi, again, blending is confusing me and I can''t figure out a simple factor combination. I have the mask for each bitmap stored in the alpha layer, 0 being where I want to see through the bitmap and 255 where the actual image is. How should I set the blending func to create a solid mesh that I can (completely) see through where the alpha mask is zero? I''m figuring glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);, but it produces a totally different effect... Note that I don''t want to use a separate monochrome image for masking - instead I''d like to store everything in one bitmap. Thanks in advance, Crispy

Share this post


Link to post
Share on other sites
GL_SRC_ALPHA for the source blend factor.
GL_ONE_MINUS_SRC_ALPHA for the destination blend factor.

Use GL_REPLACE. (don''t use GL_BLEND). You might want to use GL_MODULATE.

Use RGBA for your map.

Set your material color to 4 components, where the alpha is 1.0.

I believe you want to enable GL_BLEND, but don''t confuse this with the texture operation, which should not be GL_BLEND.

It gets rather confusing.



Share this post


Link to post
Share on other sites
I resorted to blending and set glAlphaFunc() to > 0 (and enabled GL_ALPHA_TEST) and the result is pretty much as expected. Looks nice except for one thing. I''ll post a pic describing the problem:



The red lines denote four quads (topside view) and the green triangle is the fov. This is a tricky one - if I use any other mode than GL_LINEAR to create the textures, the edges of the quads are "blended", or "interpolated". This poses a problem - the order in which the quads have to be drawn becomes relevant. The normal order is back-first for blending as, I''m sure, everyone here knows. In this case, however, how do I set the order for the quads?

Here''s a result when they''re drawn in constant succession, regardless of the orientation/position of the eye:



Even though this screenshot doesn''t examplify the actual problem (I could draw the trees and other such objects as the last things in the scene), there still remains a similar effect when it comes to viewing through the holes in the leaves of the tree. The backmost quads of the same tree can be seen through just as the water surface can be seen through in this screenshot - all due to incorrect z-order. Just in case it''s unclear: have a closer look at the red rectange and the terrain that can be seen clearly through the water surface along the edge of the tree leaves. What would be a solution to this?

Thanks,
Crispy

Share this post


Link to post
Share on other sites
The simple solution is to use alpha masking by itself, and not bother with blending for this.

Blending eats up more fillrate, and what youre after is achieved via alpha masking alone anyway

-----------------------
"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else''s drivers, I assume it is their fault" - John Carmack

Share this post


Link to post
Share on other sites