Dynamically Uniform Expression

From OpenGL.org
Revision as of 01:04, 5 December 2012 by Alfonse (Talk | contribs) (Added warning about image variables.)

Jump to: navigation, search
Dynamically Uniform Expression
Core in version 4.5
Core since version 4.0

A Dynamically Uniform Expression is a GLSL expression in which all invocations of that shader within a particular rendering command will compute the same value. This concept only matters in GLSL 4.00 and above.



Compile-time constant expressions (literals and const​-qualified global and local variables) are always dynamically uniform. uniform​-qualified variables are dynamically uniform. Mathematical expressions based on these are dynamically uniform. Values sampled from images using constant or uniform expressions are dynamically uniform.





  • The array index for arrays of opaque types.
  • The index to buffer-backed interface blocks.


Here are some examples of expressions that are and are not dynamically uniform:

in vec3 fromPrevious;
in uvec2 fromRange;

const int foo = 5;
const uvec2 range = uvec2(2, 5);
uniform vec2 pairs;

uniform sampler2d tex;

void main()
  foo; //constant expressions are dynamically uniform.
  uint value = 21; //value is dynamically uniform.
  value = range.x; //still dynamically uniform.
  value = range.y + fromRange.y; //not dynamically uniform; current value comes from a non-dynamically uniform source.
  value = 4; //dynamically uniform again.
  if(fromPrevious.y < 3.14)
    value = 12;
  value; //NOT dynamically uniform. The value of this variable depends on fromPrevious, an input variable.

  float number = abs(pairs.x); //number is dynamically uniform.


    i; //Therefore, it is dynamically uniform.

    i; //Not dynamically uniform; `fromRange` is not dynamically uniform.