Hi,
I have a problem when using multiple color buffer render targets. If I use one
color buffer everything works fine, but when I use two; the render result
always ends up in the last buffer and the first one remains blank.
I have used the osgmultiplerendertargets example as a guide.
My main camera renders to a texture and a following post processing camera
renders to a screen quad.
I assign the color buffers as follows:
[code]
for (unsigned int i = 0; i < 2; ++i) {
osg::Texture2D* texture = new osg::Texture2D();
texture->setInternalFormat(GL_RGBA);
texture->setTextureSize(size.x(), size.y());
texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);
texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);
texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
mainCamera->attach(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER0+i),
texture);
}
[/code]
And then bind the target textures as uniforms to the post process camera:
(I have also tried a simplified method of hard coding the bind instead of using
this function)
[code]
osg::StateSet* stateSet = this->getOrCreateStateSet();
for (int i = 0; i < aNumbSourceTextures; ++i) {
auto bufferIt =
aConnectToCameraOrPPU->getBufferAttachmentMap().find(osg::Camera::BufferComponent(osg::Camera::COLOR_BUFFER0+i));
if (bufferIt != aConnectToCameraOrPPU->getBufferAttachmentMap().end()
&& dynamic_cast<osg::Texture2D*>(bufferIt->second._texture.get())) {
stateSet->setTextureAttribute(i,
dynamic_cast<osg::Texture2D*>(bufferIt->second._texture.get()));
std::ostringstream stm;
stm << "mTexture" << i;
stateSet->addUniform(new osg::Uniform(stm.str().c_str(), i));
}
}
[/code]
I write to the buffer in the shader:
[code]
gl_FragData[0].r = intTemp / 25.0f;
gl_FragData[0].g = fracTemp;
gl_FragData[0].b = materialIndex;
gl_FragData[0].a = mainTexture.a;
gl_FragData[1] = texture(mTexture0, gl_TexCoord[0].st);
[/code]
I read the bound texture in the post process shader as normal:
[code]
gl_FragColor = texture(mTexture0, gl_TexCoord[0].st);
[/code]
As far as I can tell this code should bind COLOR_BUFFER0 to uniform sampler2D
mTexture0 and COLOR_BUFFER1 to mTexture1. But instead the result of
COLOR_BUFFER0 ends up in mTexture1 and mTexture0 is full black.
We use OSG 3.2.0, osgEarth 2.5 and QT 4.8.5.
The graphics card is an Intel HD2500. (could the card be the problem?)
I have been struggling with this problem on and off for a couple of days now, I
hope someone can help.
Thank you!
Cheers,
Sander[/list][/code]
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=61813#61813
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org