Hello, I think you might have bumped into a problem that shouldn't have been there, but still the simple solution is to set a uniform per object you want to light or not. The same as if without shader you have per object you draw to glEnable/glDisable the light.
Back to the problem, do you mean that if you have one pointer to uniform with light on and one pointer to uniform with light off, and you have several objects using the same pointer for the ON state, and other several objects using the same pointer for the OFF state, then if the objects won't be rendered as a groups of lit and unlit, the result won't be true? If so it does seems like a bug. Can you post the code so we can check it? I can't see how this is possible, the apply method of Uniform has no optimization of checking if it was called at the current frame... I thought of other possibility just now? Do you have ONE uniform you share among both lit and unlit object?? If you do so, then don't. Make two uniforms, one for the lit and one for the unlit objects and share each of them among the relevant group of objects. Hope it helps, tell us how you progress, Guy. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Yefei He Sent: Wednesday, April 09, 2008 5:46 PM To: OSG Users Subject: [osg-users] Sharing uniforms among statesets?; was: Shader question concerning GL_LIGHTING Hi, Mike, Robert, folks, Thanks for the help from this list, I've decided to use a uniform to solve the problem of switching lighting mode between fragments. My idea is to add the program and a LightingOn uniform to the stateset of the root node of the scenegraph, and set its value to 0 wherever the stateset of a node has GL_LIGHTING off, and to 1 wherever GL_LIGHTING is on. However, on a closer thought, here comes a problem. For the GL_LIGHTING mode in the stateset of a node, I can set it to whatever value and it won't affect that in the stateset of a different node, and individual glEnable(GL_LIGHTING) and glDisable(GL_LIGHTING) will be called during the draw stage. But if I'm sharing a uniform, is it that during the draw stage only one call to glUniform() for that uniform will take place, and its value will be that of the last call to Uniform::Set() before the draw stage? How do I make multiple glUniform() calls to the same uniform take place during the draw stage alongside glEnable/glDisable(GL_LIGHTING)? I don't think it's correct to create a separate osg::Uniform for each node, which in the minimum will induce multiple glGetUniformLocation() calls? Can I use a callback? A draw callback? A second approach is to create two sets of shaders and two programs, one for non lit fragments, and another for lit fragments. Then I just set the appropriate program to the stateset of each node in the scenegraph. Will this work? I imagine there may be thousands of glUseProgram() calls during each draw. I don't know how big an impact it will be on the performance. Thanks! Yefei _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or g _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org