UBO Best Practices

Hello,

Can anyone share any best practices they’ve found while converting existing GLSL shaders to use UBOs? Or just best practices with UBOs in general? I’m curious to know if it is worth making a uniform block even if it only contains a single field (e.g. the model-view-projection matrix) but the field is used across a large number of shaders. I’m under the impressive that this is worthwhile since you would only set this value once per frame with glBufferSubData, etc instead of using glUniformMatrix per shader.

Thanks,
Patrick

I’m leaning towards yes to using uniform blocks with a single field if it is used across several shaders based on the following from Appendix F of the red book:

Using uniform buffer objects (in particular, the shader variety) will help significantly reduce the overhead of loading uniform variables when changing between shaders.

Just remember that you have a set limit to the number of uniform buffers that can be on a shader. Using one UBO for a single uniform is possible, but it does waste a UBO slot.