Hi Paul, On 2/24/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
I'm not sure I understand why the compiler would treat my uniform as a constant when I told it I wanted it to be a uniform. I thought uniforms are meant, by definition, to be changed. Bad decision by the compiler if it is the case.
They are meant to be changed, but infrequently. Drivers developers are free to make the optimizations they feel are appropriate, sometimes they will screw up, when they do you need to tell them. If you want to change values frequently then the best thing to do is use vertex attributes rather than uniforms. The OSG is geared up to manage vertex attributes at the osg::Geometry level rather than as StateAttributes. One could create a custom StateAttribute to set a vertex attribute though. The interaction with osg::Geometry would have to be managed carefully but it is probably doable.
Also, its my guess that you are not seeing this problem with your examples because the example shaders are too small and take minimal amount of time to recompile "on-the-fly". My shaders are on the larger side and the recompile time is more noticable. The particular uniform I'm having trouble with changes values as the camera position changes. I have several other uniforms that are being changed on a per-frame basis but it appears only this particular one is causing problems (but its declared/handled no different than the others).
The OSG itself just does culling, state sorting and then throws the OpenGL data at the fifo and lets it get on with it. The types of stalls you are seeing just down to a state change of uniform from 0.5 to 0.4999 won't result in any change to the way the OSG passes its data to OpenGL, to me this is all a clear indicator that its the driver that is the problem. As a general note, there are a couple of stages in setting up GLSL programs - first you compile the shaders, then you link them. Changing a uniform will may or may not force a re-link of the shaders into a program - its all down to the OpenGL driver. Linking of the shaders might invoke a recompilation too, or perhaps just an optimization pass. Again this is all driver specific behavior, as far as I'm aware there isn't anything in the OpenGL spec that constrains the drivers to do things in a particular way w.r.t handling of unfiroms and relinking/compiling. Different approaches will have different trade off w.r.t performance and flexibility. I'd strongly recommend chatting with NVidia about this uniform issue. The only other thing I could recommend is to try using an attribute rather than uniform. Robert. _______________________________________________ osg-users mailing list [email protected] http://openscenegraph.net/mailman/listinfo/osg-users http://www.openscenegraph.org/
