transform question

I have several objects with separate shader programs and have uniform modelview and projections matrices in all of these shaders programs. What if one of these matrices changes? How to update the matrices in all the shader programs I use?

In other words, do I need to change the uniform model-view matrix in all the shader programs for each model-view matrix change? I can’t use the global gl_ModelViewProjection matrix or any of its siblings.

I think the answer lies in bindable uniforms and named interface blocks of GLSL 1.50.

I was perplex, since GLSL 1.30 spec tags gl_ModelViewProjection matrix and its siblings deprecated, without providing an elegant mechanism to replace this loss of access to GL state.

I think you’re close. Yeah, with traditional uniforms and shared parameters, you end up having to push a copy to every shader that needs to reference that shared uniform. However, I’ve read here that Bindable Uniforms are deprecated, and it’s much better to use Uniform Buffer Objects (UBOs). There’s also an NVidia extension (NV_shader_buffer_load) that allows you to reference uniforms/etc. directly from GPU memory via pointer in GLSL shader, rather than go through a buffer object handle (essentially you bind the GPU address of the buffer rather than the buffer handle), but that is currently NVidia-only. See the presentation on the previous link for more details.

Going traditional way, you can upload the changed state of the uniform only on shader activation (not going though all of them with each state change).
I’d advice you to store all actual used uniforms values for each shader in order to skip updating of constant values.

Well, if the modelview matrix changes rapidly (and it does in my code), this would basically mean an update before every render :frowning:

Yeah, that’s what we do.

Nevertheless, that means N updates per shared uniform, where N is the maximum number of shaders referenced within a single change of that shared uniform, vs. 1.

If ever render always uses a different shader, then yes. But I’d be surprised if this was the case.

Question is: How many applications of different shaders would you on-average apply for each modelview change. If this number is down near 1, then there isn’t much difference between these two options for you.

Also, IIRC I’ve read folks here stating that UBOs can be more expensive than standard uniforms to update. So bench both ways and see.

I guess there is less bookkeeping with UBOs then, their use also probably simplifies the code a little.

Question is: How many applications of different shaders would you on-average apply for each modelview change. If this number is down near 1, then there isn’t much difference between these two options for you.

I was under the impression, that these days almost every world object has it’s own shader program and these objects are becoming more varied as time goes on, even if they belong to the same “class” of object; and so requiring the use of different shaders even within this class of objects. For this reason ‘N’ will surely keep rising.

Anyway, I’ve made UBOs work on my NVIDIA linux box, after messing with glew a bit and tossing glee out of my code. Thanks!

Can’t speak to general stats across all apps, but this definitely isn’t the case in our world.