[osg-users] Attaching children to the prerender camera

Mary-Ann Zorra rebebaba2 at gmail.com
Mon Sep 19 08:14:02 PDT 2016


Hi,

I am pretty new in OSG, so sorry if I am asking a bit noob question. But I am stuck on this problem, and have no idea how I could solve it.

So I would like to prerender my scene into a framebuffer to have a depth map. I tested everything, my shader seems to work if I am using it in my main rendering pass, and it is being called in my prerender pass too. But for some reason it can not see the objects of the scene, so the depthmap gets black (I do linearize the depth values in the fragment shader too).  I think the problem is, that I do not attach the subgraph to the framebuffer camera properly, but I can not figure it out, what I am missing. So please help, I  do not have any new ideas  anymore :(

Here is the code:


Code:
camera = new osg::Camera;;
camera->setViewport(0, 0, m_textureSizeX, m_textureSizeY);
camera->setClearColor( osg::Vec4() );
camera->setClearMask( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
camera->setRenderTargetImplementation( osg::Camera::FRAME_BUFFER_OBJECT, osg::Camera::PIXEL_BUFFER_RTT );
camera->setRenderOrder( osg::Camera::PRE_RENDER );
camera->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
camera->setProjectionMatrix( osg::Matrix::ortho2D(0.0, 1.0, 0.0, 1.0) );
camera->setViewMatrix( osg::Matrix::identity() );

m_depthTexture = new osg::Texture2D;
m_depthTexture->setTextureSize(m_textureSizeX, m_textureSizeY);
m_depthTexture->setInternalFormat(GL_RGBA);
m_depthTexture->setDataVariance(osg::Object::DYNAMIC);
m_depthTexture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR);
m_depthTexture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
m_depthTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
m_depthTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
m_depthTexture->setResizeNonPowerOfTwoHint(false);

m_texImage = new osg::Image;
m_texImage->allocateImage(m_textureSizeX, m_textureSizeY, 1, GL_RGBA, GL_UNSIGNED_BYTE);

camera->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER), m_texImage);
m_depthTexture->setImage(0, m_texImage);

//m_DBRoot is filled by init(), I checked and the subgraph is there
camera->addChild(m_DBRoot.get());
//the root of the scene graph
root->addChild(camera.get()); 




Thank you!

Cheers,
Mary-Ann

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








More information about the osg-users mailing list