[osg-users] using modern shaders with osg - setting vertex attribute layout

Sebastian Messerschmidt sebastian.messerschmidt at gmx.de
Fri Sep 1 06:27:09 PDT 2017


Hi Antiro,

I don't have an idea why it is not working.
For which camera's state set did you enable it?
Have you tried to check this with a simplistic non-MRT/FBO setup?
Which OSG-Version do you use (its working with 3.4.x definitively)

I've been using this for years, so there must be some error somewhere else.

Cheers
Sebastian
> Hi Sebastian,
> 
> I was under the impression that the "layout(...) in ..." command was essentially a variable declaration and that hence only the location and type needed to match. I now also changed the name, this does not seem to have any effect though..
> 
> new vertex shader code:
> 
> Code:
> #version 330 core
> layout(location = 0) in vec4 osg_Vertex;
> layout(location = 1) in vec3 osg_Normal;
> layout(location = 2) in vec4 osg_Color;
> layout(location = 3)in vec4 osg_MultiTexCoord0;
> layout(location = 4)in vec4 osg_MultiTexCoord1;
> layout(location = 5)in vec4 osg_MultiTexCoord2;
> layout(location = 6)in vec4 osg_MultiTexCoord3;
> layout(location = 7)in vec4 osg_MultiTexCoord4;
> layout(location = 8)in vec4 osg_MultiTexCoord5;
> layout(location = 9)in vec4 osg_MultiTexCoord6;
> layout(location = 10)in vec4 osg_MultiTexCoord7;
> 
> out vec3 Normal;
> out vec2 TexCoords;
> out vec3 WorldPos;
> 
> uniform mat4 osg_ModelViewMatrix;
> uniform mat3 osg_NormalMatrix;
> uniform mat4 osg_ProjectionMatrix;
> 
> 
> void main()
> {
>      gl_Position = osg_ProjectionMatrix * osg_ModelViewMatrix * osg_Vertex;
>      WorldPos = (osg_ModelViewMatrix * osg_Vertex).xyz;
>      Normal = osg_NormalMatrix * osg_Normal;
>      TexCoords = osg_MultiTexCoord0.xy;
> 
> }
> 
> 
> 
> If I use the shader without the UseVertexAttributeAliasing enabled I see red silhouettes for the different models, when looking at the normals texture output (as if all normals are <1,0,0> ), which I expect is caused by the shader reading wrong  on unitialized attributes.
> 
> with UseVertexAttributeAliasing enabled I get no output.
> 
> 
> 
> Thank you!
> 
> Cheers,
> antiro
> 
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=71588#71588
> 
> 
> 
> 
> 
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> 


More information about the osg-users mailing list