Skip to main content
gamedev.net
🔒 Locked

Masking

Started by Boder Mar 29, 2006 at 5:21 PM 8 replies 1.8k views
Original Post
Boder
Boder
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?
lc_overlord
lc_overlord
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.
Boder
Boder
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?
lc_overlord
lc_overlord
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.
Axesor
Axesor
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
Boder
Boder
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).
Axesor
Axesor
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.