Hi Bram, The water camera is not clearing the depth buffer, which means it will be performing depth tests against the depth values from the world camera. Try setting the clear mask for the water camera to the following:
waterCamera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); Cheers, Farshid On Thu, Nov 14, 2013 at 2:09 PM, Bram Vaessen <bram.vaes...@gmail.com>wrote: > Hi, > > I'm trying to reuse a depth buffer for rendering two different passes. The > first one does terrain, the second one some water surface (to another > output buffer, but that's not the issue here) > > Based on posts from the forum I though I had it figured out but it doesn't > work well. Depending on how I move the camera in my application, it either > looks like the depth buffer was not used at all (I see water everywhere), > or it works as expected, or sometimes something in between, some parts seem > to be non-rendered as they should but not everywhere. I wonder if I did > anything wrong, here is the code I used, any comments would be useful, > thanks! > > > > Code: > //set up a depth buffer to be reused in two cameras > osg::Texture2D* depthBuffer; > depthBuffer = new osg::Texture2D; > depthBuffer->setTextureSize(screenWidth, screenHeight); > depthBuffer->setInternalFormat(GL_DEPTH_COMPONENT32); > depthBuffer->setSourceFormat(GL_DEPTH_COMPONENT); > depthBuffer->setSourceType(GL_FLOAT); > > > .... > > > //set up the world (scene) camera > osg::ref_ptr<osg::Camera> worldCamera = new osg::Camera(); > worldCamera->setViewport(new > osg::Viewport(0,0,screenWidth,screenHeight)); > worldCamera->setProjectionMatrixAsPerspective(30.0, 16.f/9.f, 0.5, > 10000); > worldCamera->setClearMask(GL_COLOR_BUFFER_BIT | > GL_DEPTH_BUFFER_BIT); > //camera->setClearColor(fog->getFogColor()); > worldCamera->setClearColor(osg::Vec4(0,0,0,0)); > worldCamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); > worldCamera->setRenderOrder(osg::Camera::PRE_RENDER,0); > > worldCamera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); > worldCamera->addChild(worldNode); //add the world to the world > camera > > worldCamera->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER0), > colorsRect); > > worldCamera->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER1), > normalsRect); > > worldCamera->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER2), > positionsRect); > worldCamera->attach(osg::Camera::DEPTH_BUFFER, depthBuffer); > > > > //set up the water surface camera > osg::ref_ptr<osg::Camera> waterCamera = new osg::Camera(); > waterCamera->setViewport(new > osg::Viewport(0,0,screenWidth,screenHeight)); > waterCamera->setProjectionMatrixAsPerspective(30.0, 16.f/9.f, 0.5, > 10000); > waterCamera->setClearMask(GL_COLOR_BUFFER_BIT); > waterCamera->setClearColor(osg::Vec4(0,0,0,0)); > waterCamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); > waterCamera->setRenderOrder(osg::Camera::PRE_RENDER,1); > > waterCamera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); > waterCamera->addChild(waterNode); > > waterCamera->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER0), > waterRect); > waterCamera->attach(osg::Camera::DEPTH_BUFFER, depthBuffer); > > ... > > > rootNode->addChild(worldCamera); > rootNode->addChild(waterCamera); > > > > > > Thank you! > > Cheers, > Bram > > ------------------ > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=57218#57218 > > > > > > _______________________________________________ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org >
_______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org