HI Nico, The OSG only attaches osg::Shader to osg::Program so one wouldn't ordinarily be compiling shaders separately. It's hard to know what you are doing and why let alone why it's going wrong.
Robert. On 6 November 2014 07:50, Nico Schertler <[email protected]> wrote: > Hi, > > I face the problem that the pure compilation of a shader breaks other > shaders. The relevant part of my scene graph looks as follows: > > > Code: > > * root (osg::Group) > * SkyGeode (osg::Geode) > *Sky (subclass of osg::Geometry) > * OtherGroup (subclass of osg::Group) > > > > The Sky geometry object compiles its own shader and sets its uniforms once > on creation. This alone works very well. > As soon as I compile a vertex shader in the constructor of OtherGroup, the > sky rendering fails (i.e. the calculated color is not reasonable anymore). > I have found out that this is caused by some uniforms not being set > correctly. However, I haven't changed anything about them. They should > still have their values from the beginning. > Here is the second vertex shader (compiled from OtherGroup): > > Code: > > #version 150 > #extension GL_ARB_texture_rectangle : enable > uniform sampler2DRect instanceData; > > uniform mat4 osg_ModelViewProjectionMatrix; > > in vec4 vertex; > in vec3 normal; > > out vec4 vertexColor; > > const vec3 directionToLight = normalize(vec3(1, -2, 3)); > > void main(void) > { > vec2 instanceCoord = vec2(gl_InstanceID % 256, gl_InstanceID / 256); > > vec4 pos = texture2DRect(instanceData, instanceCoord); > pos.w = 0; > gl_Position = osg_ModelViewProjectionMatrix * (vec4(vertex, 1) + pos); > > float diffuse = max(0, dot(normal, directionToLight)); > float ambient = 0.2; > float color = diffuse + ambient; > > vertexColor = vec4(color, color, color, 1); > } > > > > This problem occurs even though OtherGroup does not have any drawable > children. The vertex shader is not even added to a program. It is just > compiled. I compile it as follows (in the constructor of OtherGroup): > > Code: > > osg::ref_ptr<osg::Shader> vs = osgDB::readShaderFile(osg::Shader::VERTEX, > "glsl/shader.vert"); > > > > For debugging purposes, I have output some uniforms as the color in the > sky fragment shader. As long as the compilation of the second vertex shader > is not present, this gives me a reddish color. Once I insert this single > line, the sky turns yellow. That's how I confirmed that the uniforms must > be wrong. > I have enabled useModelViewAndProjectionUniforms for the camera, but not > useVertexAttributeAliasing. > I really can't understand why the sole compilation of a shader causes > other parts of the application to fail. Am I missing something here? It > appears that if the shader contains syntax errors (of which I am not > notified btw), the sky renders just fine. > I have also found out that this problem only occurs if the shader is > loaded through osgDB::readShaderFile(). If I load it directly as follows, > everything is working again. However, the GLSL plugin basically does the > same (plus some osgDB caching): > > Code: > > osgDB::ifstream fin(osgDB::findDataFile("glsl/shader.vert").c_str(), > std::ios::in | std::ios::binary); > std::stringstream ss; > ss << fin.rdbuf(); > osg::ref_ptr<osg::Shader> vs = new osg::Shader(osg::Shader::VERTEX, > ss.str()); > > > > > Nico > > ------------------ > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=61525#61525 > > > > > > _______________________________________________ > osg-users mailing list > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org >
_______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

