PDA

View Full Version : picking and transparency



tomster
05-24-2009, 02:13 AM
Hello,

I am thinking about using opengl picking vs. ray picking.

My program is a pretty simple 2D program so picking will probably be sufficient and i won't have to get into reverse projecting and intersection detections.

There is one thing i couldn't find the answer to and i'd like to know before i choose.

When i have a polygon that has a texture on it, and part of the polygon is transparent (due to 0 value in the texture alpha channel), when i click on the transparent part will it get picked or not (obviously i'd like it to not get picked).
Also, in this same case how would ray trace picking help?

Thanks for your help

ZbuffeR
05-24-2009, 06:31 AM
1) alpha blending is quite tricky, as it writes a combination of "before" color and "new" color. But only 1 color value is stored, as well as only 1 depth value.

2) However I am pretty sure alpha *testing* works as expected, even with "selection" mode, when it is needed to discard the 99% transparent parts.

3) if alpha test is not working in selection mode, you will have to go to the "color selection" mode. Be sure to enable alpha test and disable blending !

Drawbacks : slightly more complex, can not return a list of selected objects.
Advantages : hardware accelerated !!! and somewhat easier to debug, as it is possible to "see" the color buffer.

Have a read on the GL twiki :
http://www.opengl.org/wiki/Selection_mechanism
http://www.opengl.org/wiki/Common_Mistakes#Selection_and_Picking_and_Feedback _Mode
http://www.opengl.org/wiki/Unique_Color_For_Every_Primitive
http://www.opengl.org/wiki/Specify_An_Exact_Color

tomster
05-24-2009, 06:39 AM
thanks for answering.

What exactly is alpha testing? Does it mean that each pixel's alpha is tested and if it's above a certain threshold it gets rendered (non blended with whatever's below it) and if its below it doesnt (the pixel below is rendered)?

in that case, assuming all i want is to "not pick" the parts where the alpha is zero, i could still use the ALPHA_BLENDING mode for the desired effect right?

ZbuffeR
05-24-2009, 09:59 AM
fixed :
each pixel's alpha is tested and if it's above a certain threshold it gets rendered (and blended if blending is active, with whatever's below it) and if its below it doesnt (the pixel below stay as it was)?

Alpha test and blending are independant.

Just read the docs :
http://www.opengl.org/sdk/docs/man/xhtml/glAlphaFunc.xml

tomster
05-24-2009, 11:49 PM
Hey again,

I read the docs (got it all now) and I did as you said. Doesn't work though. The transparent areas still get picked when i click on them.

Do i have to enable alpha testing while in selection mode? Its enabled in the opengl init method (i enabled it and disabled blending - just in case).

Could it be the texture image?
It a png file and it gets rendered fine (transparency wise) so i figure it's alpha channel is fine.

I am thinking about color coding instead of picking but how would i render all the texture in one color while still not rendering the transparent parts?

thanks