[osg-users] Can't write to ALPHA component with custom fragment shader in RTT pass

Daniel Holz osgforum at tevs.eu
Wed Mar 11 07:34:14 PDT 2009


Thanks for all your help. It directed me to the solution!

For other users who face the same problem:

The setting to obtain a RGBA texture with 32Bit floats per component which one can write unclamped values to is as follows:


Code:

    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->setInternalFormat(GL_RGBA32F_ARB);
    texture2D->setSourceFormat(GL_RGBA); // we need to set the source format to GL_RGBA. otherwise the values will be clamped to [0,1].
    // Note: use gl_FragData[0..n] to write to texture in fragment shader. otherwise data is clamped.

osg::Camera* camera = ...    camera->pCamPass->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
    camera->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER0), texture2D);
    



Just watch out that you write to the texture using gl_FragData[0] (in this example) instead of gl_FragColor if you want the values to be passed in the texture in an unclamped fashion.

Have fun!

Daniel

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=8263#8263








More information about the osg-users mailing list