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->setTextureSize( winW, winH ); tex->dirtyTextureObject(); 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 ); rootCamera->setRenderTargetImplementation( osg::Camera::FRAME_BUFFER_OBJECT, osg::Camera::FRAME_BUFFER ); #if( OSGWORKS_OSG_VERSION >= 20906 ) rootCamera->setImplicitBufferAttachmentMask( osg::Camera::IMPLICIT_COLOR_BUFFER_ATTACHMENT|osg::Camera::IMPLICIT_DEPTH_BUFFER_ATTACHMENT, osg::Camera::IMPLICIT_COLOR_BUFFER_ATTACHMENT ); #endif // 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( osgwTools::makePlane( 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()->setAttribute( myCreateEffectProgram( "none" ) ); geode->getOrCreateStateSet()->addUniform( new osg::Uniform( "inputTextures[0]", 0 ) ); postRenderCamera->addChild( geode ); return( postRenderCamera.release() ); }
osg::Node* postRender( osgViewer::Viewer& viewer ) { osg::Camera* rootCamera( viewer.getCamera() ); // MRT: Attach two color buffers to the root camera, one for // the standard color image, and another for the glow color. osg::Texture2D* tex0 = new osg::Texture2D; tex0->setTextureWidth( winW ); tex0->setTextureHeight( winH ); tex0->setInternalFormat( GL_RGBA ); tex0->setBorderWidth( 0 ); tex0->setFilter( osg::Texture::MIN_FILTER, osg::Texture::NEAREST ); tex0->setFilter( osg::Texture::MAG_FILTER, osg::Texture::NEAREST ); // Full color: attachment 0 rootCamera->attach( osg::Camera::COLOR_BUFFER0, tex0, 0, 0, false, 8, 8 ); osg::Texture2D* tex1 = new osg::Texture2D; tex1->setTextureWidth( winW ); tex1->setTextureHeight( winH ); tex1->setInternalFormat( GL_RGBA ); tex1->setBorderWidth( 0 ); tex1->setFilter( osg::Texture::MIN_FILTER, osg::Texture::NEAREST ); tex1->setFilter( osg::Texture::MAG_FILTER, osg::Texture::NEAREST ); // Glow color: attachment 1 rootCamera->attach( osg::Camera::COLOR_BUFFER1, tex1, 0, 0, false, 8, 8 ); rootCamera->setRenderTargetImplementation( osg::Camera::FRAME_BUFFER_OBJECT, osg::Camera::FRAME_BUFFER ); #if( OSGWORKS_OSG_VERSION >= 20906 ) rootCamera->setImplicitBufferAttachmentMask( osg::Camera::IMPLICIT_COLOR_BUFFER_ATTACHMENT|osg::Camera::IMPLICIT_DEPTH_BUFFER_ATTACHMENT, osg::Camera::IMPLICIT_COLOR_BUFFER_ATTACHMENT ); #endif // Post-draw callback on root camera handles resolving // multisampling for the MRT case. MSMRTCallback* msmrt = new MSMRTCallback( rootCamera ); rootCamera->setPostDrawCallback( msmrt ); // Configure postRenderCamera to draw fullscreen textured tri pair. // This will combine the two (resolved) textures into a single image. 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->setCullingActive( false ); geode->addDrawable( osg::createTexturedQuadGeometry( osg::Vec3( -1,-1,0 ), osg::Vec3( 2,0,0 ), osg::Vec3( 0,2,0 ) ) ); mrtStateSetTriPair( geode->getOrCreateStateSet(), tex0, tex1 ); postRenderCamera->addChild( geode ); return( postRenderCamera.release() ); }