I work on a deferred renderer for my master thesis. Everything is fine and now 
I want to correctly render transparent objects. I want to use forward rendering 
for that taks - just render the transparent objects in one pass, blend them 
together and add it to buffer of rendered opaque objects (by deferred 

The problem is that I don't now how to correctly access opaque/transparent 
objects in my scene graph to render them separately and combine them in the 
final stage of deferred renderer. I have found a disscussion 
 where access to render bin #10 (which should always contain transparent 
geometry ?) is described. So I got and idea that I could create my custom scene 
graph node (derived from osg::Geode) and redefine its traversal method, where I 
would "discard" the render bin for transparent/opaque objects after the cull 
I modified the code from the discussion a little bit and I mask depth and color 
buffer for writing when rendering transparent objects (don't know how to 
acctually remove transparent drawables from particular render bin):


void RenderBinMaskNode::traverse(osg::NodeVisitor& nv) {

    this->osg::Group::traverse( nv );
    // Clone render-bin 10 if this is a cull visitor
    if ( nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR ) {

        osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>( &nv );

        if ( cv ) {
            // Act if we have a RenderStage pointer
            if ( osgUtil::RenderStage* renderStage = cv->getRenderStage() ) {   
                // Get the render-bin list
                osgUtil::RenderBin::RenderBinList& binList = 

                                    osg::notify(osg::ALWAYS) << "RENDER BIN 
LIST SIZE: " << binList.size() << std::endl;

                                    // go to renderbin which stores transparent 
drawables (always number 10 ?)
                                    if( binList.find(10) != binList.end() ) {
                                            // for this render bin, do not 
render its content 
                                            osg::StateSet* binStateSet = 

                                            // mask depth buffer
new osg::Depth(osg::Depth::LESS, 0.0, 1.0, false), osg::StateAttribute::ON | 
osg::StateAttribute::OVERRIDE );

                                            // mask color buffer
new osg::ColorMask(false, false, false, false), osg::StateAttribute::ON | 
osg::StateAttribute::OVERRIDE );

                                            // TO DO: stencil and accum mask

If I add this custom node as a child of my camera node and the scene itself as 
a child of my custom node, then no transparent objects are rendered - which is 
exactly what I want. 

But the trouble is when I want to render only the transparent objects. When I 
dump the size of render bin list (see the code), it is 0 if no transparent 
object should be rendered on the screen (it is outside the view frustum) and 1 
if a transparent object should be rendered (but it is not visible since I mask 
the depth and color buffers). So I have only one render bin containing 
transparent geometry and no render bin with opaque geometry (and even though 
the opaque geometry is rendered correctly). I don't underestand why since as 
far as I know, the cull visitor should fill at least two render bins, one for 
transparent and one for opaque geometry. 

Finally, my questions: Is it correct that I have only one render bin containing 
transparent geometry and no render bin with opaque geometry? How can I render 
only the transparent geometry of my scene (possibly using the approach from the 

Thank you in advance for _any_ help. I really need to solve this out. PS.: I 
apologize for my poor English.

Regards, Jirka.

Read this topic online here:

osg-users mailing list

Reply via email to