Hello Robert et al.,
I am trying to get in a texture the minimum and maximum depths for each texels.
I render my scene to a FBO using
a float texture (GL_RGBA32F_ARB). The scene has different fragments in depths
that maps to one texel. I disable
the depth test to process all those fragments in my fragment shader, where I
output its depth (gl_FragCoord.z).
I enable the blending and use RGBA_MAX as my blend equation. Now when I read
back the texture I rendered to,
I would expect to have all the furthest fragments. If I use RGBA_MIN, I would
expect to have all the closest
fragments... Is my reasoning correct ? Now I always get the same values in the
texture regardless whether I
use RGBA_MIN or RGBA_MAX... Any idea ? Anyone used RGBA_MIN / RGBA_MAX with
success ?
Here is how I setup the camera to render to the texture:
osg::ref_ptr<osg::Camera> pCam = new osg::Camera;
pCam->setClearColor(osg::Vec4(-1, -1, 0, 0));
pCam->setClearMask(GL_COLOR_BUFFER_BIT);
pCam->getProjectionMatrix().makeIdentity();
pCam->setReferenceFrame(osg::Transform::RELATIVE_RF);
pCam->setViewport(0, 0, m_uiWidth, m_uiHeight);
pCam->setRenderOrder(osg::Camera::PRE_RENDER);
pCam->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
pCam->setComputeNearFarMode(osg::Camera::COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES);
pCam->getOrCreateStateSet()->setMode(GL_DEPTH_TEST,
osg::StateAttribute::OFF|osg::StateAttribute::PROTECTED|osg::StateAttribute::OVERRIDE);
pCam->getOrCreateStateSet()->setAttributeAndModes(new
osg::Depth(osg::Depth::ALWAYS),
osg::StateAttribute::ON|osg::StateAttribute::PROTECTED|
osg::StateAttribute::OVERRIDE);
pCam->getOrCreateStateSet()->setMode(GL_BLEND,
osg::StateAttribute::ON|osg::StateAttribute::PROTECTED|osg::StateAttribute::OVERRIDE);
osg::BlendEquation* blendMax = new
osg::BlendEquation(osg::BlendEquation::RGBA_MAX); // or RGBA_MIN
pCam->getOrCreateStateSet()->setAttributeAndModes(blendMax,
osg::StateAttribute::PROTECTED|osg::StateAttribute::OVERRIDE);
pCam->attach(osg::Camera::COLOR_BUFFER0, texture.get());
// attach additional image for readback (slow)
{
osg::Image* pImg = new osg::Image();
pImg->allocateImage(m_uiWidth, m_uiHeight, 1, GL_RGBA, GL_FLOAT);
pImg->setInternalTextureFormat(GL_RGBA32F_ARB);
pCam->attach(m_RenderTargets[TU_MINMAXDEPTH0], pImg);
pCam->setPostDrawCallback(new WriteCameraAttachments());
}
pCam->getOrCreateStateSet()->setAttributeAndModes(writeDepthProg.get(),
osg::StateAttribute::ON|osg::StateAttribute::PROTECTED); // writes
gl_FragCoord.z in frag
// add to scene graph
regards,
Bill
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org