Skip to main content
gamedev.net
🔒 Locked

color coded picking

Started by ehmdjii 6 replies 1.4k views
Original Post
ehmdjii
ehmdjii
hello, in order to perform picking not only on geometrical objects but also depending on their texture's alpha value, i am thinking of using color coded picking which is described here: http://www.lighthouse3d.com/opengl/picking/index.php3?color1 but i am not sure how to do this correctly with textures. how can i tint a texture completely in one color, except for the alpha channel? also, how does the renderpass look like? i try this every frame: drawPickableObjectsWithUniqueColor(); getPickedObjectAccordingToColorUnderMouseCursor(); drawAllObjectsWithNormalColor(); unfortunately i still see the objects modulated with their unique color. the final rendering does not seem to overwrite the picking rendering. thanks!
ehmdjii
ehmdjii
anyone?

i think i will have to ignore the R, G and B channel and only render the Alpha channel of the texture.
Nepherim
Nepherim
You should be clearing the colour and depth buffers between rendering the picking pass and the final render.

If you have Z-buffering enabled and are using less-than z testing then none of the second pass will be rendered as every pixel will fail the z test. This would certainly cause the problem you are having.
ehmdjii
ehmdjii
ok, thanks! that works now.

what about the other problem? rendering objects in a unique color?
i think i have to only use the alpha channel of the texture. how would i do that?
Nepherim
Nepherim
With colour picking you would normally just disable texturing when you render the unique colours.

Are you trying to use the object's texture to mask areas so that they cannot be picked? So when an objects texture has an alpha of say 255 it can be picked but where it has an alpha value of another value it can't be.
ehmdjii
ehmdjii
thanks a lot!

Quote:
Original post by Nepherim
With colour picking you would normally just disable texturing when you render the unique colours.


picking according to the texture's alpha is the original reason why i chose color picking! picking with texture disabled would give me the same results as with the selection buffer, or ray-intersections.

Quote:

Are you trying to use the object's texture to mask areas so that they cannot be picked? So when an objects texture has an alpha of say 255 it can be picked but where it has an alpha value of another value it can't be.


YES! that's exactly what i want!

the graphics in my game are heavily using alphaed-textures, so i really need picking according to a texture's alpha value.

thanks!
Nepherim
Nepherim
I thought perhaps you were trying to use the alpha channel of an objects texture to identify it (this would only give you 256 unique identifiers).

To get the effect you want you will have to set the blending settings when rendering your selection buffer so that the alhpa value from the texture is used for the pixel's alpha and the unique colour value assigned is used for the pixel's RGB value. Then you have to set alpha testing to reject any pixels that have a different value from the one you want.

This should work; I don't know the exact code for it because I'm using shaders at the moment and haven't touched blending options in a while.

Also if you want non-pickable areas and objects to occlude pickable ones you will probably have to do a separate pass to fill the z-buffer with depth values and set depth testing to only pass on equal values when rendering the selection buffer.
ehmdjii
ehmdjii
thank you!

Quote:
Original post by Nepherim
To get the effect you want you will have to set the blending settings when rendering your selection buffer so that the alhpa value from the texture is used for the pixel's alpha and the unique colour value assigned is used for the pixel's RGB value. Then you have to set alpha testing to reject any pixels that have a different value from the one you want.


yes, that's the idea!

the point where i am stuck at the moment is to use a unique color instead of the RGB color from the texture.
does anyone know how to do that? (preferably not with shaders, since i am targeting older graphic cards)

Topic Locked

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

Sign in to reply to this topic.