HI Jirka,

Post processing generated the RenderStage/RenderBin's after the cull
traversals has complete on a subgraph can be a useful way to manage
techniques like your are suggesting, it does require you to understand
the details of the rendering backend though so it's not something I
would recommend for most users - it's very much an advanced topic.  If
it's appropriate in your case it may well make life much easier once
you've over come the initial learning curve on it, I'm afraid there is
no shot cut - learning from the source code in this instance will be
your best bet.

One thing you can do with the rendering back end is to create new
bins/stages and also move bins around.  In your case if you want to
handle the whole transparent bin separately then creating a separate
RenderStage for it, then moving the bin from it's original RenderStage
to it's new one could be done with a couple of lines of code.   This
would be better than trying to play games of switch on/off rendering
via state.

The other appropriate you could take is to use traversal masks for
opaque and transparent objects and use two camera that do rendering to
texture, and use different cull traversal masks for each camera to
pick out the different parts of the scene graph.  You'd need to apply
the different masks to the geodes that contains opaque and transparent
geometry.  This approach won't be quite as fast as the RenderBin
management done via a cull callback due to the extra traversals
required, but it would probably be easier in terms of using the OSG
front end, rather than the back end as the front end of the OSG is
better documented and cleaner (it's the public API that is meant to be
used, the back end is just the implementation so this is a natural
balance.)


Robert.

On Sun, Apr 26, 2009 at 10:39 AM, Jirka <h-i...@seznam.cz> wrote:
> Hi,
>
> 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 rendering).
>
> 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 
> http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/2008-July/014769.html
>  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 traversal.
> 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):
>
>
> Code:
>
> 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 = 
> renderStage->getRenderBinList();
>
>                                    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 = 
> binList[10]->getStateSet();
>
>                                            // mask depth buffer
>                                            binStateSet->setAttributeAndModes( 
> new osg::Depth(osg::Depth::LESS, 0.0, 1.0, false), osg::StateAttribute::ON | 
> osg::StateAttribute::OVERRIDE );
>
>                                            // mask color buffer
>                                            binStateSet->setAttributeAndModes( 
> 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 code)?
>
> 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:
> http://forum.openscenegraph.org/viewtopic.php?p=10874#10874
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to