Hi,
sorry, I didn't read through all your code, but have a look at the
osgmultiplerendertargets example. I don't think data is written
specifically to alpha there, but you can modify it to check. Run it with
--image and --hdr. I think the --image prints out some values of the
texture it reads back.
jp
Daniel Holz wrote:
Hi everyone,
I have trouble with a render to texture pass, where I try to write to
the RGB and ALPHA components of an attached RGBA texture in a custom
fragment shader.
Writing to the RGB components works, but gl_FragColor.a = ... does not
have any effect at all. The ALPHA component will always result in the
clear color's alpha component.
Also trying to do gl_FragColor = vec4(...,...,...,...) sets the RGB
values correctly but the ALPHA stays the same.
I am setting up my texture to render to as follows:
osg::Texture2D texture2D = new osg::Texture2D;
texture2D->setTextureSize(screen_width, screen_height);
texture2D->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
texture2D->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
texture2D->setBorderColor(osg::Vec4(1.0,1.0,1.0,1.0));
texture2D->setWrap(osg::Texture2D::WRAP_S,
osg::Texture2D::CLAMP_TO_BORDER);
texture2D->setWrap(osg::Texture2D::WRAP_T,
osg::Texture2D::CLAMP_TO_BORDER);
texture2D->setInternalFormat(GL_RGBA32F_ARB);
I am rendering to a screen aligned quad (osg::Geode* quadGeode) where I
activate GL_BLEND (I thought this might be necessary to actually be able
to write to gl_FragColor.a in the fragment shader):
osg::Geode* quadGeode = ... create screen aligned quad here ...
osg::StateSet* stateset = quadGeode->getOrCreateStateSet();
// deactivate lighting for faster processing
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
// activate blending to be able to write to gl_FragColor.a
stateset->setMode(GL_BLEND, osg::StateAttribute::ON);
And the camera is set up as follows:
osg::Camera* pCamPass = new osg::Camera;
pCamPass->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
pCamPass->setColorMask(new osg::ColorMask(1,1,1,1));
pCamPass->setClearColor(osg::Vec4(1.0,1.0,1.0,1.0));
pCamPass->setViewport(0, 0, screen_width, screen_height);
pCamPass->setReferenceFrame(osg::Camera::ABSOLUTE_RF);
pCamPass->setProjectionMatrixAsOrtho2D(0,1,0,1);
pCamPass->setViewMatrix(osg::Matrix::identity());
// tell the camera to use OpenGL frame buffer object where supported.
pCamPass->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
// attach the texture to render to
pCamPass->attach(osg::Camera::COLOR_BUFFER, texture2D);
// add screen aligned quad for rendering
pCamPass->addChild(quadGeode);
Does anybody have any clue what could be going wrong here?
Any help is much appreciated.
Cheers
Daniel
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard.
The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.
This message has been scanned for viruses and dangerous content by MailScanner,
and is believed to be clean. MailScanner thanks Transtec Computers for their support.
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org