[osg-users] Custom shader not working on Mac OS
Sebastian Messerschmidt
sebastian.messerschmidt at gmx.de
Fri Feb 19 00:57:33 PST 2016
Hi Pierre-Jean
> Hi,
>
> I try to port my app from Linux to Mac OS (El Capitan) using OSG 3.2.
> I wrote a simple system of shaders to apply a texture on a model:
>
> Vertex shader :
>
> Code:
>
> attribute vec4 osg_Vertex;
> uniform mat4 osg_ModelViewProjectionMatrix;
> varying vec4 texCoord0;
>
> void main(void)
> {
> gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex;
> texCoord0 = gl_MultiTexCoord0;
> }
>
>
>
> Fragment shader :
>
> Code:
>
> uniform sampler2D tex;
> varying vec4 texCoord0;
>
> void main(void)
> {
> gl_FragColor = texture2D(tex, texCoord0.st);
> }
>
>
>
>
> While it works as expected on Linux, on Mac my model is not displayed at all (I only see the default blue background). There is no error from the shader compilation.
> I use
> viewer->getCamera()->getGraphicsContext()->getState()->setUseModelViewAndProjectionUniforms(true);
> to get the osg_* variables, and also
> viewer->getCamera()->getGraphicsContext()->getState()->setUseVertexAttributeAliasing(false);
> to keep the fixed pipeline possibilities (for other models in my scene).
setUseVertexAttributeAliasing should be active, when you are using osg_Vertex etc.
It might be, that the driver on your first machine simply assigns the "in-slot" accidentally to the correct input.
Are there any outputs on the console?
If this is not working two hints:
1. #pragma version 150 compatibility
The version is epxected to be the first line in any shader.
2.Use gl_ instead on osg_ attributes and uniforms for testing fixed function.
>
> I saw a strange thing in the log : on Mac gl_MultiTexCoord0 is converted to osg_MultiTexCoord0 even if setUseVertexAttributeAliasing is set to false. On Linux
> gl_MultiTexCoord0 is not converted and is keeped.
> By the way if I set setUseVertexAttributeAliasing to true and replace gl_MultiTexCoord0 by osg_MultiTexCoord0, my model is properly visible (but I don't want that because I lose fixed pipeline functions).
Cannot say anything on the first issue, but you are not "loosing" any
functionality by using the aliasing. OSG will simply replace gl_ names
with its osg_ aliases when uploading the shader to the driver. All other
functions will still work as expected.
>
> Has anybody an idea of where this behavior comes from ?
As I said, drivers will do stuff behind your back. So a shader with
obvious errors might run one machine while failing on another.
Cheers
Sebastian
>
> Thank you!
>
> Cheers,
> Pierre-Jean
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=66344#66344
>
>
>
>
>
> _______________________________________________
> 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