Hi Ross --

Nesting cameras alone doesn't cause the output of the first Camera to be "sent" to the second Camera. The second Camera will need to bind the texture that the first Camera rendered into. Is it possible that you simply failed to do this?

For a really simple example of RTT, see the attached example. It uses the Viewer Camera to render the scene to an FBO with a texture attached, then uses a post render Camera to draw a full-window quad with the texture applied. Take a look at how it wires up the texture between the two Cameras -- as an attachment to the first Camera, and as a Texture in the StateSet of the second Camera.

For information on how Camera rendering is handled, take a look at CullVisitor::apply(Camera). During cull, a Camera node creates a RenderStage in the render graph. Each RenderStage has a list of pre children and post children. The Camera's render order determines whether the new RenderStage is added to the pre or post list of the current RenderStage. During draw, OSG traverses the graph of RenderStages by recursively processing first the pre list, then the RenderStage, then the post list.

Paul Martz
Skew Matrix Software LLC
_http://www.skew-matrix.com_ <http://www.skew-matrix.com/>
+1 303 859 9466



Ross Bohner wrote:
Hi,

I am having difficulty setting the order of multiple pre render cameras for 
RTT.  Specifically I wish to set
1. a camera for rendering a depth buffer to a texture which is sent as a 
uniform to
2. another camera which preforms some more calculations to a texture which is 
used on the general scene root.

I set the first camera as a subnode to the second camera and sent both 
renderOrders to PRE_RENDER.  However this structure does not correctly send 
output texture of the first camera to the second camera's shader.  I have 
verified the shaders and first camera's output.

How does the render sequence get handled?  I have read in other posts that the 
render order was based on the camera hierarchy.  Did I misinterpret this and 
not have added the first camera as a child to the second camera?

Also how does the RenderOrderNum of a camera effect the order to processing? If the cameras are siblings my first interpretation was that the order is PRE_RENDER 0, PRE_RENDER 1, ..., PRE_RENDER n, NESTED_RENDER 0, NESTED_RENDER 1, ... NESTED_RENDER n, POST_RENDER 0, POST_RENDER 1, ... POST_RENDER n. However I did try setting the render order for the sequence above but the first camera's output texture was not available for processing by the second camera.
Any help would be greatly appreciated

Thank you!

Cheers,
Ross

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=20043#20043





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


// Copyright (c) 2008 Skew Matrix Software LLC. All rights reserved.

#include <osg/Node>
#include <osg/Camera>
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/Texture2D>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>

#include <string>


const int winW( 800 ), winH( 600 );


osg::Node*
postRender( osgViewer::Viewer& viewer )
{
    osg::Camera* rootCamera( viewer.getCamera() );

    // Create the texture; we'll use this as our color buffer.
    // Note it has no image data; not required.
    osg::Texture2D* tex = new osg::Texture2D;
    tex->setTextureWidth( winW );
    tex->setTextureHeight( winH );
    tex->setInternalFormat( GL_RGBA );
    tex->setBorderWidth( 0 );
    tex->setFilter( osg::Texture::MIN_FILTER, osg::Texture::NEAREST );
    tex->setFilter( osg::Texture::MAG_FILTER, osg::Texture::NEAREST );

    // Attach the texture to the camera. Tell it to use multisampling.
    // Internally, OSG allocates a multisampled renderbuffer, renders to it,
    // and at the end of the frame performs a BlitFramebuffer into our texture.
    rootCamera->attach( osg::Camera::COLOR_BUFFER0, tex, 0, 0, false, 8, 8 );
    rootCamera->setRenderTargetImplementation( 
osg::Camera::FRAME_BUFFER_OBJECT, osg::Camera::FRAME_BUFFER );


    // Configure postRenderCamera to draw fullscreen textured quad
    osg::ref_ptr< osg::Camera > postRenderCamera( new osg::Camera );
    postRenderCamera->setClearColor( osg::Vec4( 0., 1., 0., 1. ) ); // should 
never see this.
    postRenderCamera->setRenderTargetImplementation( osg::Camera::FRAME_BUFFER, 
osg::Camera::FRAME_BUFFER );

    postRenderCamera->setReferenceFrame( osg::Camera::ABSOLUTE_RF );
    postRenderCamera->setRenderOrder( osg::Camera::POST_RENDER );
    postRenderCamera->setViewMatrix( osg::Matrixd::identity() );
    postRenderCamera->setProjectionMatrix( osg::Matrixd::identity() );

    osg::Geode* geode( new osg::Geode );
    geode->addDrawable( osg::createTexturedQuadGeometry(
        osg::Vec3( -1,-1,0 ), osg::Vec3( 2,0,0 ), osg::Vec3( 0,2,0 ) ) );
    geode->getOrCreateStateSet()->setTextureAttributeAndModes(
        0, tex, osg::StateAttribute::ON );
    geode->getOrCreateStateSet()->setMode( GL_LIGHTING, 
osg::StateAttribute::OFF );

    postRenderCamera->addChild( geode );

    return( postRenderCamera.release() );
}

int
main( int argc, char** argv )
{
    osg::ref_ptr< osg::Group > root( new osg::Group );
    root->addChild( osgDB::readNodeFile( "cow.osg" ) );
    if( root->getNumChildren() == 0 )
        return( 1 );

    osgViewer::Viewer viewer;
    viewer.setThreadingModel( osgViewer::ViewerBase::SingleThreaded );
    viewer.setUpViewInWindow( 10, 30, winW, winH );
    viewer.setSceneData( root.get() );
    viewer.realize();

    root->addChild( postRender( viewer ) );

    // Clear to white to make AA extremely obvious.
    viewer.getCamera()->setClearColor( osg::Vec4( 1., 1., 1., 1. ) );

    return( viewer.run() );
}
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to