Global uniform variables in OpenGL/GLSL?

Hello :),
is there a way to set global uniform variables in OpenGL so that every GLSL shader can use them?
Like the build-in variables. For example you define fog parameters and then you can access them in every shader via gl_fog.
It would be great if that would be possible with my own parameters.

I think the closes thing is a newer feature called uniform buffers. These work similarly to VBOs in that you create the buffer and fill it with data, but you can then tell OpenGL to pull all values for the GLSL shader’s uniforms from the bound uniform buffer.

All of your shaders would need to declare your custom uniforms, but you could set the values in the uniform buffer, and just have them all use the same uniform buffer.

I’ve never used them myself, though, so take this with a grain of salt.

thank you … i’ve read something about it … i will definitely try this !

What…?

All uniform variables are “global” in the sense that if you define the same variable in your vertex, geometry and/or fragment shader they will all be the same value. If you have a uniform vec3 normal; in your vertex shader and a uniform vec3 normal; in your fragment shader, they can both be set with a single call to glUniform3f. So yes, they are “global”.

What he means is global across shader programs. This was something that was available with the low-level shader interface (ARB_vertex_program etc), namely the program environment parameters. Something like that never made it into GLSL, probably because it was a “simulated” feature in the first place.

Oh, my bad. I can see the usefulness of it though. The same matrices are usually used in many different shader programs.