I'm re-implementing some shader code and I've run into a problem I've not had before. That is, I'm switching on osg uniforms and vertex attributes for shaders (testing GLSL 140), as it's laid out in the osgVertexAttributes example, but it seems to only partly work.
Here's the shader code:
Vertex:
Code:
#version 140
uniform mat3 osg_NormalMatrix;
uniform mat4 osg_ModelViewProjectionMatrix;
in vec3 osg_Normal;
in vec4 osg_Vertex;
out vec3 normal;
void main()
{
normal = normalize(osg_NormalMatrix * osg_Normal);
gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex; //ftransform();
}
Fragment:
Code:
#version 140
vec4 color1;
vec4 color2;
vec4 color3;
vec4 color4;
in vec3 normal;
out vec4 glFragColor;
void main()
{
color1 = vec4( 1.0, 0.5, 0.5, 1.0 );
color2 = vec4( 0.5, 0.2, 0.2, 1.0 );
color3 = vec4( 0.2, 0.1, 0.1, 1.0 );
color4 = vec4( 0.1, 0.05, 0.05, 1.0 );
vec4 light0 = vec4(0.0, 0.0, 0.0, 1.0);
float intensity = dot(vec3(light0), normal);
if (intensity > 0.95) glFragColor = color1;
else if (intensity > 0.5) glFragColor = color2;
else if (intensity > 0.25) glFragColor = color3;
else glFragColor = color4;
}
Error log:
Code:
glLinkProgram "" FAILED
Program "" infoLog:
Vertex info
------------
0(3) : warning C7555: 'attribute' is deprecated, use 'in/out' insetead
0(6) : error C1038: declaration of "osg_ModelViewProjectionMatrix" conflicts with previous declaration at 0(2)
0(8) : error C1038: declaration of osg_Vertex conflicts with previous declaration at 0(3)
I've used GLSL 140+ successfully in the past (OSG 2.8.x / 2.9.x), though I don't have that code any longer. The error log makes no sense, suggesting I'm declaring osg_ModelViewProjectionMatrix and osg_Vertex twice, with meaningless line references. Interestingly, the osg_NormalMatrix and osg_Normal declarations generate no errors.
Just to ensure it wasn't something I was doing, I modded osgVertexAttributes to automatically load a model and apply the same GLSL 140 code - shader gen was disabled. I didn't change any of the NodeVisitor code. Strangely enough, I received a very similar error log for the vertex shader.
The GLSL 140 code was modded from the original 120 in the beginner's guide. Prior to enabling the osg uniforms and vertex attributes, I tested the version 120 code and it worked just fine.
Maybe I missed a CMake option when I built my 3.0.1 binaries?
Thanks,
Joel
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=46690#46690
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
I wonder if it's osg::State that has been configured to covert
gl_ModelViewMatrix to osg_ModelViewMatrix in the shader, with
inserting of the required declaration of the osg_ModelViewMartrix. If
osg::State is inserting this declaration you can either disable the
setUseModelViewAndProjectionUniforms(false), or just remove the
declaration in your own shader.
Robert.
It didn't really matter if I called setUseModelViewAndProjectionUniforms() with either true or false. In either case, the same errors were generated. The only thing that fixed the error was removing the osg_ModelViewProjectionMatrix declaration from the code. Regardless of the setUse...() state flag, no error was generated w.r.t. osg_ModelViewProjectionMatrix if I removed the declaration from the GLSL code, even if I still used the uniform in the shader.
The same is true with the osg_Vertex error - only by removing the declaration could I eliminate the error. In fact, the shader compiled without *any* errors after removing both declarations. But, of course, nothing appeared onscreen.
The only problem that I couldn't deal with separately was the "attribute" warning, especially since I did not use the "attribute" keyword in my code.
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=46700#46700
First, I rebuilt my binaries and retested. Strangely, I had different results, though it may be that I didn't do something the first time that I did the second. I can't imagine rebuilding OSG would help, but it appears as though it did.
Second, I retested the 120 shader version, and transitioned from gl_ to osg_ builtins one at a time. Here the secret divulged itself: osg_ModelViewProjectionMatrix and osg_Vertex must *not* be declared, but everything else must. That is, declaring the first two generated "duplicate declaration" errors, but omitting any other built-ins generated "undeclared idnetifier" errors. Note that I only tested osg_Normal, osg_ModelViewMatrix, and osg_NormalMatrix in addition to the first two.
I still enabled the built-ins using:
Code:
(*itr)->getState()->setUseModelViewAndProjectionUniforms(true);
(*itr)->getState()->setUseVertexAttributeAliasing(true);
For posterity's sake, I've included the source I used to test.
------------------
Read this topic online here: