[osg-users] Attaching children to the prerender camera

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


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:

camera = new osg::Camera;;
camera->setViewport(0, 0, m_textureSizeX, m_textureSizeY);
camera->setClearColor( osg::Vec4() );
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->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_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
//the root of the scene graph

Thank you!


Read this topic online here:

More information about the osg-users mailing list