Hi all,
I'm trying to implement a deferred shading model based on some papers around
the web but I'm running into issues when using both
setUseVertexAttributeAliasing and rendering to a texture using FBO. I can
render to an FBO fine with attribute aliasing off, and attribute aliasing
appears to work fine with my shaders when not rendering to any FBOs, but using
both at the same time causes my FBO textures to be either black or just an RGB
gradient. Basically I'm doing this:
Code:
ref_ptr<osgViewer::Viewer> pOsgViewer = new osgViewer::Viewer();
pOsgViewer->setUpViewOnSingleScreen(1);
pOsgViewer->setCameraManipulator(new osgGA::OrbitManipulator());
pOsgViewer->setThreadingModel(osgViewer::ViewerBase::AutomaticSelection);
pOsgViewer->realize();
pOsgViewer->getCamera()->getGraphicsContext()->getState()->setUseModelViewAndProjectionUniforms(true);
pOsgViewer->getCamera()->getGraphicsContext()->getState()-->setUseVertexAttributeAliasing(true);
std::string filename = "blah.3DS";
ref_ptr<Node> pModel = osgDB::readNodeFile(filename);
unsigned int textureWidth = 1024;
unsigned int textureHeight = 1024;
// Initialize the GBuffer
// Create osg::Texture2D objects to store the image data and map them to
GBuffer types
ref_ptr<Texture2D> pNormalTex = new Texture2D();
pNormalTex->setTextureSize(textureWidth, textureHeight);
pNormalTex->setInternalFormat(GL_RGBA);
pNormalTex->setFilter(Texture2D::MIN_FILTER, Texture2D::LINEAR);
pNormalTex->setFilter(Texture2D::MAG_FILTER, Texture2D::LINEAR);
ref_ptr<Camera> pNormalCam = new Camera();
pNormalCam->setClearColor(Vec4(1.0, 1.0, 1.0, 1.0));
pNormalCam->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
pNormalCam->setGraphicsContext(pOsgViewer->getCamera()->getGraphicsContext());
pNormalCam->setRenderTargetImplementation(Camera::FRAME_BUFFER_OBJECT);
pNormalCam->setRenderOrder(Camera::PRE_RENDER);
pNormalCam->setViewport(0, 0, pNormalTex->getTextureWidth(),
pNormalTex->getTextureHeight());
pNormalCam->attach(Camera::COLOR_BUFFER, pNormalTex.get(), 0, 0, false);
attachShader(pNormalCam, GBUFFER_NORMAL);
pNormalCam->addChild(pModel.get());
ref_ptr<osg::Group> pGroup = new Group();
pGroup->addChild(pNormalCam.get());
pGroup->addChild(pModel.get());
pOsgViewer->setSceneData(pGroup.get());
pOsgViewer->run();
attachShader() just looks like this:
Code:
bool ShadedScene::attachShader(Camera* pCam, GBufferTypes programType)
{
if (pCam == NULL)
{
return false;
}
ref_ptr<Shader> pVertShader = new Shader(Shader::VERTEX);
ref_ptr<Shader> pFragShader = new Shader(Shader::FRAGMENT);
ref_ptr<Program> pShaderProgram = new Program();
pShaderProgram->addShader(pVertShader.get());
pShaderProgram->addShader(pFragShader.get());
StateSet* pCamSs = pCam->getOrCreateStateSet();
if (pCamSs == NULL)
{
return false;
}
pCamSs->setAttributeAndModes(pShaderProgram.get(), StateAttribute::ON);
switch (programType)
{
case GBUFFER_NORMAL:
pVertShader->setShaderSource(normalVertShader);
pFragShader->setShaderSource(normalFragShader);
break;
default:
break;
}
return true;
}
My shaders:
Code:
static std::string normalVertShader = "uniform mat4
osg_ModelViewProjectionMatrix;\n"
"uniform mat3 osg_NormalMatrix;\n"
"varying vec3 vVaryingNormal;\n"
"void main(void)\n"
"{\n"
" vVaryingNormal = osg_NormalMatrix * gl_Normal;\n"
" gl_Position = osg_ModelViewProjectionMatrix * gl_Vertex;\n"
"}\n";
static std::string normalFragShader =
"#version 120\n"
"varying vec3 vVaryingNormal;\n"
"void main(void)\n"
"{\n"
" gl_FragColor.rgb = vVaryingNormal;\n"
"}\n";
I'm using OSG trunk rev13134 for what I'm working on but I also had similar
issues back when using 3.0.1. I'm not sure if I'm missing something or what.
Some of this stuff is doable without attribute aliasing but it's more
complicated - i.e. accessing the texture coordinates for a model doesn't seem
particularly straightforward and I've not seen a simple way to do it when
loading in a 3D model. Just curious if I'm missing something glaringly obvious.
What I posted is a stripped-down version of what I'm working on but it covers
everything I'm actually doing in relation to OSG.
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=50649#50649
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org