Hi Bram, Sorry, I misunderstood your question.
The values in the depth buffer are normalized based on the near/far clip planes. If you are automatically computing the near/far planes, then they can end up being different for each camera, which causes the depth test for the water scene to be computed incorrectly. Disabling computing of near/far and forcing the same clip plane values should ensure proper depth testing between the two cameras. Does that make sense? Cheers, Farshid On Thu, Nov 14, 2013 at 2:50 PM, Bram Vaessen <bram.vaes...@gmail.com>wrote: > Farshid, I should have been more clear about it, but that was actually my > intention. The terrain and water are in the same world so i wanted to use > the depth information from the terrain render to draw only visible portions > of the water to the other buffer. > > Sebastian, I always get this error: "Warning: detected OpenGL error > 'invalid framebuffer operation' at After Renderer::compile" but I got this > from the very beginning of when I started on the project, when I didn't > have any framebuffers or anything else for that matter, it was just always > there from the first time I used OSG. I tried looking it up but nobody on > the forum could help me with it, and it doesn't seem to do any harm... > > for the buffers and resulations, let me just paste the code here, this is > how I set them up: > > > Code: > //set up fragment color raster > osg::TextureRectangle* colorsRect; > colorsRect = new osg::TextureRectangle; > colorsRect->setTextureSize(screenWidth, screenHeight); > colorsRect->setInternalFormat(GL_RGBA32F_ARB); > colorsRect->setSourceFormat(GL_RGBA); > colorsRect->setSourceType(GL_FLOAT); > > colorsRect->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::NEAREST); > > colorsRect->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::NEAREST); > > //set up fragement normal raster > osg::TextureRectangle* normalsRect; > normalsRect = new osg::TextureRectangle; > normalsRect->setTextureSize(screenWidth, screenHeight); > normalsRect->setInternalFormat(GL_RGBA32F_ARB); > normalsRect->setSourceFormat(GL_RGBA); > normalsRect->setSourceType(GL_FLOAT); > > normalsRect->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::NEAREST); > > normalsRect->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::NEAREST); > > //set up fragment coordinate raster > osg::TextureRectangle* positionsRect; > positionsRect = new osg::TextureRectangle; > positionsRect->setTextureSize(screenWidth, screenHeight); > positionsRect->setInternalFormat(GL_RGBA32F_ARB); > positionsRect->setSourceFormat(GL_RGBA); > positionsRect->setSourceType(GL_FLOAT); > > positionsRect->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::NEAREST); > > positionsRect->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::NEAREST); > > //set up fragment color raster 2 for water > osg::TextureRectangle* waterRect; > waterRect = new osg::TextureRectangle; > waterRect->setTextureSize(screenWidth, screenHeight); > waterRect->setInternalFormat(GL_RGBA32F_ARB); > waterRect->setSourceFormat(GL_RGBA); > waterRect->setSourceType(GL_FLOAT); > > waterRect->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::NEAREST); > > waterRect->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::NEAREST); > > //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); > > > > > > add the depth texture as input > > sampler to the consecutive passes if they use it for writing. > > > do you mean as a texture? I tried > > waterCamera->getOrCreateStateSet()->setTextureAttributeAndModes(0, > depthBuffer, osg::StateAttribute::ON); > > but that didn't help. > > I was looking at it again and it looked like it was clipping when I moved > the camera around, so I tried this (also for the other camera): > > > worldCamera->setComputeNearFarMode(osg::CullSettings::ComputeNearFarMode::DO_NOT_COMPUTE_NEAR_FAR); > worldCamera->setProjectionMatrixAsPerspective(30.0, 16.f/9.f, 0.1, > 100000); > > that seems to solve it! I suppose the clipping was causing it, but not > sure how exactly. Would be helpful if I understood what was happening > exactly, any idea? > > Thanks :) > > ------------------ > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=57221#57221 > > > > > > _______________________________________________ > 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