[osg-users] Shader Uniform Performance Question(s)
Maybe somebody on this list can save me from reinventing the wheel... I'm looking to get a better understanding of performance issues related to uniforms. How much overhead is there in having a uniform? If there only a performance hit if the uniform changes values or every frame. What if I change the Uniform in OSG to exactly the same value it already has, would there be a performance hit? I have uniforms that might not change values very often. Some are simply boolean flags. Can I have different shaders and somehow switch between them? Can I recompile the shader on-the-fly (i.e. defining these boolean using #define/#if-#endif)? In some cases, I have variables which can change within the shader, but I know these values when I create the scene graph so I currently use #define instead of passing them as uniforms (which will ever only have one value). Does this gain me much in performance? Also, is there a difference in performance in using four float uniforms versus setting a Vec4? Paul P. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Shader Uniform Performance Question(s)
Hi Paul, 2008/11/19 [EMAIL PROTECTED] Maybe somebody on this list can save me from reinventing the wheel... I'm looking to get a better understanding of performance issues related to uniforms. How much overhead is there in having a uniform? If there only a performance hit if the uniform changes values or every frame. What if I change the Uniform in OSG to exactly the same value it already has, would there be a performance hit? Firstly, uniform variables are intented to using in rarely changing values, and attributes is used while needing frequently changing values. So using uniform qualified saves your performance if your value not changing in every frame. But at that point if you update uniform variable by the initialized callback or visitor, your variables updating operation will be needless and I think will reduce your performance. So update your changed uniform variables by triggered function or operation. I have uniforms that might not change values very often. Some are simply boolean flags. Can I have different shaders and somehow switch between them? Can I recompile the shader on-the-fly (i.e. defining these boolean using #define/#if-#endif)? You can recompile or switch but I don't advice these operation. Only update your changed values by triggered functions. In some cases, I have variables which can change within the shader, but I know these values when I create the scene graph so I currently use #define instead of passing them as uniforms (which will ever only have one value). Does this gain me much in performance? It's good choice. Every variable which you send by unifrom variables will reduce the usable memory by GPU so this is most practical way for me. Also, is there a difference in performance in using four float uniforms versus setting a Vec4? Actually the preceded answer about memory usage is same situation too. Every memory usage reduce the performance I think. P.S : I am not guru' I only use GLSL about 2 months. Paul P. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org Regards. -- Ümit Uzun ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Shader Uniform Performance Question(s)
Paul, From my perspective : How much overhead is there in having a uniform? GLSL? Not much. If there only a performance hit if the uniform changes values or every frame. What if I change the Uniform in OSG to exactly the same value it already has, would there be a performance hit? I regularly use uniforms that change every frame, and I can't say I've noticed any performance penalty (in the context of an app that is doing real work). I have uniforms that might not change values very often. Some are simply boolean flags. Can I have different shaders and somehow switch between them? Yes. Some people use uniforms and in-shader dynamic branching to control the operation of shaders. (Some people obviously have too much GPU power for their own good ;). Me, I'm often stuck with older cards that can't support dynamic branching very sensibly, and so this kind of shader kills me. ). An alternative is to have a switch node, whose children all have different shaders on them, and who are all the parent of your object. There's a separate thread on this topic going on at this exact time with very similar issues to this approach, bearing in mind that shaders form part of the stateset. Can I recompile the shader on-the-fly (i.e. defining these boolean using #define/#if-#endif)? Bad idea in general, for performance reasons. In some cases, I have variables which can change within the shader, but I know these values when I create the scene graph so I currently use #define instead of passing them as uniforms (which will ever only have one value). Does this gain me much in performance? In general, yes - it's certainly better for performance (the extent is GPU dependent, obviously) and this solution is better for older hardware that doesn't support dynamic branching. Also, is there a difference in performance in using four float uniforms versus setting a Vec4? Off the top of my head, I'm not sure - this is probably driver dependent (good GLSL compilers might pack this up automatically). You might try the OpenGL / GLSL forums for this. Hope that helps, David ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Shader Uniform Performance Question(s)
Hi David, You are right there is much uniform variables can be changed in every frame but these all Built-in variables. I think this difference can change the state of your tenet. I have read OrangeBook and Randi Rost ( GLSL GURU :) ) advices using uniform variables if you rarely update and in converse situation for attributes. I don't know why but if they advices, this must be true :) Regards. 2008/11/19 David Spilling [EMAIL PROTECTED] Umit, Sorry to be picky, but: Firstly, uniform variables are intented to using in rarely changing values, and attributes is used while needing frequently changing values. Not quite. Lots of the fixed-function uniforms - which are deprecated under GL3 - potentially change every frame ( gl_ModelViewMatrix etc. ). Attributes are per-vertex data, like position, normals, texcoords and so on. Uniforms are the same across a set of vertices. David ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org -- Ümit Uzun ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Shader Uniform Performance Question(s)
Umit, Sorry to be picky, but: Firstly, uniform variables are intented to using in rarely changing values, and attributes is used while needing frequently changing values. Not quite. Lots of the fixed-function uniforms - which are deprecated under GL3 - potentially change every frame ( gl_ModelViewMatrix etc. ). Attributes are per-vertex data, like position, normals, texcoords and so on. Uniforms are the same across a set of vertices. David ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org