Rendered boolean mask

Skip to first unread message

Matthew Murrian

May 24, 2021, 1:22:48 PMMay 24
to OpenSceneGraph Users

I have the need to render a boolean mask of a scene; an image with 0s for background/transparent pixels and 1s for "foreground pixels" (and no anti-aliasing, 1s or 0s). Of course, I could create a boolean mask myself from a normally-rendered scene... set the background color to black and replace rendered non-black pixels w/ 1s. However, it seems to me that the entire cull/render operation could be streamlined quite a bit with the end goal taken into account.

Can anyone recommend an efficient way to render a "boolean mask" directly? Forgive me if this is a common feature and I just don't know the lingo to find it.


Matthew Murrian

May 24, 2021, 3:44:53 PMMay 24
to OpenSceneGraph Users
Update: I've found the Stencil functionality and have determined how to use it to generate the boolean mask I require (and then copy it into my own buffer through glReadPixels). That resolves half of my question.

The other half is to whether there is a more efficient way to use OSG/OpenGL when I only need to render into the stencil buffer (i.e., I don't need the color or depth buffers). As it is, I am rendering into the color buffer but ignore the results. It would be great to reduce computational effort to the minimum required to populate the stencil buffer alone.

Thanks again,

May 25, 2021, 2:53:57 AMMay 25

Hi Mathew,

what about creating a texture with black for false white for true. Map this texture to a quad and set it to "nearest" mode.


Reply all
Reply to author
0 new messages