[osg-users] Texture coordinates in shaders GLSL

271 views
Skip to first unread message

Daniel Lobo

unread,
Oct 10, 2014, 2:05:10 PM10/10/14
to osg-...@lists.openscenegraph.org
Hi all,

I am trying to draw an osg scene (lz.osg) with shaders. For that, I had to use the Visitor Pattern and so on. The problem that I am having is that I don't know how the texture coordinates are beeing uploaded to shaders. I was expecting that I could use osg_MultiTexCoord0 in a similar way than osg_Vertex, but it seems that doesn't work.


Here is my shader code.

Vertex shader:


Code:

#version 400

uniform mat4 osg_ModelViewProjectionMatrix;
in vec4 osg_Vertex;
in vec4 osg_MultiTexCoord0;

out vec2 texCoord;

void main()
{
texCoord = osg_MultiTexCoord0.st;
gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex;
}





Fragment shader:


Code:

#version 400

out vec4 outColor;
uniform sampler2D baseMap;
in vec2 texCoord;

void main()
{
outColor = texture(baseMap, texCoord);
}




Thank you!
Best wishes

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





_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Robert Osfield

unread,
Oct 13, 2014, 3:49:16 AM10/13/14
to OpenSceneGraph Users
HI Daniel,

The aliasing of gl_* uniforms to osg_* equivialants is not done by default.  You can switch it one yourself if required though via osg::State, from the osgsimplegl3 example:

    // for non GL3/GL4 and non GLES2 platforms we need enable the osg_ uniforms that the shaders will use,
    // you don't need thse two lines on GL3/GL4 and GLES2 specific builds as these will be enable by default.
    gc->getState()->setUseModelViewAndProjectionUniforms(true);
    gc->getState()->setUseVertexAttributeAliasing(true);

In your own shaders if you are building against GL1/2 (default build of OSG) then you can simply use the gl_* parameters.

Also have a look at the shaders in OpenSceneGraph-Data and the osgshaders example.

Robert.




Daniel Lobo

unread,
Oct 13, 2014, 10:44:34 AM10/13/14
to osg-...@lists.openscenegraph.org
Hi,

You are right, I forgot use "setUseVertexAttributeAliasing(true)"

Thank you very much for the tip!

Best wishes

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=61288#61288
Reply all
Reply to author
Forward
0 new messages