Discussion:
Matrix uniform is no longer getting set in osg 3.2+
Kevin Clancy
2014-05-22 16:44:13 UTC
Permalink
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
Sebastian Messerschmidt
2014-05-23 08:38:25 UTC
Permalink
Hi Kevin,

Can you see what is the offending OpenGL call is, which causes the
error? (Should be piece of cake with GDebugger).
Also, I always specify the uniforms in terms of their data type (e.g.
float vs. double). If there is a mismatch between double and float, some
drivers will not link the shader nor execute it correctly.

Cheers
Sebastian
Post by Kevin Clancy
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.
//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());
if(nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR)
{
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv);
if(cv)
{
_eyeToWorldUni->set(*cv->getModelViewMatrix());
}
}
varying vec4 vertCoords = eyeToWorld * (gl_ModelViewMatrix * gl_Vertex);
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
------------------
http://forum.openscenegraph.org/viewtopic.php?p=59534#59534
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Kevin Clancy
2014-05-23 12:23:57 UTC
Permalink
Hi Sebastian,

Thanks for the speedy response.
Post by Sebastian Messerschmidt
Also, I always specify the uniforms in terms of their data type (e.g.
float vs. double). If there is a mismatch between double and float, some
drivers will not link the shader nor execute it correctly.
I took your suggestion and am now explicitly specifying the types for all my uniforms and it is now working. What a silly mistake, although, curious as to how it ever worked.

Thanks again,
Kevin

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

Loading...