Masking

Started by
8 comments, last by lc_overlord 18 years ago
I understand the tutorial. I have looked over it numerous times. I don't get how this technique has any advantages over normal transparency. Are there other examples besides this use of the technique that achieve cool effects other than achieving a simple on/off alpha channel?
Advertisement
Until recently i thought this effect has no real use at all concidering that we now got alpha blending.

But i did find a use of it last week when i converted lesson14 for it to be antialised.
when you do use antialising (glEnable( GL_POLYGON_SMOOTH ); to be exact) you have to use a specific blending function, but this blending function(GL_SRC_ALPHA, GL_ONE) is additive, so you have to mask the text by first rendering the text in black using the (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) blendfunc and then rendering the correct text in whatever color you want.

Anyway for most situations masking is pretty useless, i think nehe wrote this tut just because he couldn't load 32bit images.
Quote:
Anyway for most situations masking is pretty useless


For transparent object you have to order them from back to front before drawing them or you get incoorect results. It is also slower to render, because it must read the current contents of the backbuffer before render (to blend with it).

For masking you can just render them normally like a solid mesh, but you can only have a hard edge in your textures. Plant rendering among a vast range of other things benifit from this since you do not waste your CPU ording each triangle, so I wouldnt call it useless, since it is used all the time in current high-end games.
Quote:Original post by Anonymous Poster
Quote:
Anyway for most situations masking is pretty useless


For transparent object you have to order them from back to front before drawing them or you get incoorect results. It is also slower to render, because it must read the current contents of the backbuffer before render (to blend with it).

For masking you can just render them normally like a solid mesh, but you can only have a hard edge in your textures. Plant rendering among a vast range of other things benifit from this since you do not waste your CPU ording each triangle, so I wouldnt call it useless, since it is used all the time in current high-end games.


This is what alpha-testing is for isn't it?
Quote:Original post by Anonymous Poster
Quote:
Anyway for most situations masking is pretty useless


For transparent object you have to order them from back to front before drawing them or you get incoorect results. It is also slower to render, because it must read the current contents of the backbuffer before render (to blend with it).

For masking you can just render them normally like a solid mesh, but you can only have a hard edge in your textures. Plant rendering among a vast range of other things benifit from this since you do not waste your CPU ording each triangle, so I wouldnt call it useless, since it is used all the time in current high-end games.


1. as Boder said, that's what alpha-testing is for.

2. masking still needs to read from the backbuffer, infact it has to do that two times per pixel, alpha blending only has to do that once per pixel and alphatesting does not have to do that at all.

3, it's allmost never used anywhere because of 1 and 2.
Is masking really bad to use? It works like a charm for me!
.::WARNING!::. Axesor is a total newb or n00b! Beware his lack ofintellegence of OpenGL. Feel sorry for him and keep him in your thoughts.~Leader of the phsychoward
I assumed you were talking about alpha testing, i wasnt aware that there was an in-between/alternate(?) version of alpha blending/testing in openGL. Granted Ive only done a little bit of openGL programming, but it sounds to me like it is totally pointless, due to the high overhead and same(?) results as transpent/tested blending.

The technique (Lesson 20) works like this.

Use glBlendFunc(GL_DST_COLOR,GL_ZERO) to draw the mask, which turns all black parts of the mask image to black in the frame buffer.

Then, with an image where black should be transparent, use glBlendFunc(GL_ONE, GL_ONE) to perform an additive blend. The transparent part (black) of course doesn't affect the frame buffer, and the color part is blended with black (because of the mask).
So does it take alot of processing to do so? On the tutorials they run pretty fast. I chopped mine down into a few lines of code simple but using some for satements :D
.::WARNING!::. Axesor is a total newb or n00b! Beware his lack ofintellegence of OpenGL. Feel sorry for him and keep him in your thoughts.~Leader of the phsychoward
The tutorials are more cpu limited than gpu limited and runs OMGWTFPWN fast so any speed diference won't be noticable unless you use losts and lots of polygons, like more than 10000.

This topic is closed to new replies.

Advertisement