Kevin Clancy
2014-05-22 16:44:13 UTC
Hi all,
I've recently upgraded an osgEarth application's underlying osg framework from osg 3.0.1 to 3.2.1 and began to receive a bunch of OpenGL "invalid operation" errors with one of my shaders.
Running through gDEBugger, it turns out that one of my uniforms is no longer getting set, and is always zeroed out.
In summary of what I'm doing, I create the uniform in a custom ShadowedScene class like so:
Code:
//Eye to world matrix for determining distance from object in shader
osg::ref_ptr<osg::Uniform> _eyeToWorldUni = new osg::Uniform("eyeToWorld", osg::Matrix::identity());
_stateset->addUniform(_eyeToWorldUni.get());
Then in this custom class' traverse function, I set the uniform:
Code:
if(nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR)
{
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv);
if(cv)
{
_eyeToWorldUni->set(*cv->getModelViewMatrix());
}
}
In my shader, I then use this uniform to calculate the distance from an object to the vertex. In summary I do the following:
Vertex:
Code:
varying vec4 vertCoords = eyeToWorld * (gl_ModelViewMatrix * gl_Vertex);
Fragment:
Code:
vec3 distV = objectPosition - vertCoords.xyz;
float dist = length(distV);
All my other uniforms (like objectPosition) are unaffected. There is only a problem with the eyeToWorld uniform.
Also note, that I did not have to change any of my code to get it to compile in 3.2.1. I just had to rebuild my application with the new binaries. (Trying to rule out some silly mistake I made in the upgrade process.)
Any suggestions or osg changes that could have caused this?
Thanks,
Kevin
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=59534#59534
I've recently upgraded an osgEarth application's underlying osg framework from osg 3.0.1 to 3.2.1 and began to receive a bunch of OpenGL "invalid operation" errors with one of my shaders.
Running through gDEBugger, it turns out that one of my uniforms is no longer getting set, and is always zeroed out.
In summary of what I'm doing, I create the uniform in a custom ShadowedScene class like so:
Code:
//Eye to world matrix for determining distance from object in shader
osg::ref_ptr<osg::Uniform> _eyeToWorldUni = new osg::Uniform("eyeToWorld", osg::Matrix::identity());
_stateset->addUniform(_eyeToWorldUni.get());
Then in this custom class' traverse function, I set the uniform:
Code:
if(nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR)
{
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv);
if(cv)
{
_eyeToWorldUni->set(*cv->getModelViewMatrix());
}
}
In my shader, I then use this uniform to calculate the distance from an object to the vertex. In summary I do the following:
Vertex:
Code:
varying vec4 vertCoords = eyeToWorld * (gl_ModelViewMatrix * gl_Vertex);
Fragment:
Code:
vec3 distV = objectPosition - vertCoords.xyz;
float dist = length(distV);
All my other uniforms (like objectPosition) are unaffected. There is only a problem with the eyeToWorld uniform.
Also note, that I did not have to change any of my code to get it to compile in 3.2.1. I just had to rebuild my application with the new binaries. (Trying to rule out some silly mistake I made in the upgrade process.)
Any suggestions or osg changes that could have caused this?
Thanks,
Kevin
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=59534#59534