OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Rendering transparent/opaque objects separately in deferred renderer using osg::RenderBin - how?


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
hich
Newbie


Joined: 26 Apr 2009
Posts: 2

PostPosted: Sun Apr 26, 2009 9:39 am    Post subject:
Rendering transparent/opaque objects separately in deferred renderer using osg::RenderBin - how?
Reply with quote

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.
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12353

PostPosted: Mon Apr 27, 2009 7:54 am    Post subject:
Rendering transparent/opaque objects separately in deferred renderer using osg::RenderBin - how?
Reply with quote

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 <> wrote:
Quote:
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:ShockedN | osg::StateAttribute::OVERRIDE );

                                           // mask color buffer
                                           binStateSet->setAttributeAndModes( new osg::ColorMask(false, false, false, false), osg::StateAttribute:ShockedN | 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









------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
hich
Newbie


Joined: 26 Apr 2009
Posts: 2

PostPosted: Mon Apr 27, 2009 8:51 am    Post subject:
Reply with quote

Thank you, Robert, for your advice, I appreciate it.

I'll probably take the cull traversal mask approach, since I don't have much spare time and it seems easier to implement. I'll post my results as soon as I have them if someone else deals with the same problem.

Regards, Jirka.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Crash on some machines while renderin... rposg General 3 Fri Oct 04, 2019 6:08 pm View latest post
No new posts two pass rendering without enhancing ... Trajce Nikolov NICK General 2 Tue Jul 02, 2019 9:58 am View latest post
No new posts Rendering a Depthmap lucasamparo General 2 Tue Jun 04, 2019 6:27 pm View latest post
No new posts Layered rendering with a geometry shader AnyOldName3 General 8 Tue May 14, 2019 11:25 pm View latest post
No new posts off screen rendering with OSG Sorin General 0 Mon May 13, 2019 8:14 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP