Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  Global uniform variables in OpenGL/GLSL?  (Read 1197 times)
0 Members and 2 Guests are viewing this topic.
Offline Flo

JGO n00b
*

Posts: 2



« on: 2011-09-09 15:40:47 »

Hello  Smiley,
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.
Offline lhkbob

JGO Neuromancer
****

Posts: 1174
Medals: 35



« Reply #1 on: 2011-09-09 17:47:04 »

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.

Offline Flo

JGO n00b
*

Posts: 2



« Reply #2 on: 2011-09-11 12:53:26 »

thank you ... i've read something about it .. i will definitely try this !
Games published by our own members! Go get 'em!
Offline theagentd

JGO Wizard
****

Posts: 1392
Medals: 88



« Reply #3 on: 2011-09-11 16:31:00 »

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".

There is no god.
Offline Spasi

JGO Ninja
***

Posts: 589
Medals: 26


Molon Lave


« Reply #4 on: 2011-09-12 03:35:11 »

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.
Offline theagentd

JGO Wizard
****

Posts: 1392
Medals: 88



« Reply #5 on: 2011-09-12 06:05:05 »

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

There is no god.
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.082 seconds with 20 queries.