[osg-users] Attaching children to the prerender camera

Trajce Nikolov NICK trajce.nikolov.nick at gmail.com
Mon Sep 19 08:34:05 PDT 2016


Hi Mary-Ann,

I have recently worked on similar issue and the way how I debug the depth
RTT was by rendering the Depth image on a quad (the shader for displaying
the Depth image is here: http://markmail.org/message/
ccscbkzyxsgmb5vl#query:+page:1+mid:c542rbpj3jdw3v5d+state:results )
or simply attach a color texture to the depth RTT as well - might help you
to see if your View/Projection matrices are ok too. The link works with
Depth textures in general so maybe the code there will give you some
inspiration

Hope this helps
Nick

On Mon, Sep 19, 2016 at 5:14 PM, Mary-Ann Zorra <rebebaba2 at gmail.com> wrote:

> 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
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>



-- 
trajce nikolov nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20160919/ff8d9e0d/attachment-0003.htm>


More information about the osg-users mailing list