Uniform variable are a kind of 'global' variables that a shader can read. An application communicates with the shader by using uniform variables. In the shader editor, you can set the values of the uniforms you define with the 'Uniforms' tab. As an example how to use it, mofify the initial fragment shader in the following way: Add the line
uniform vec4 colorFromApp;
to the shader at global scope. This line defines a global variable (visible in the fragment shader) that can be set by the application. You can read this variable like any other variable, like for example:
gl_FragColor = colorFromApp;
Now you see nothing. The default value any uniforms is zero. And in this case it is a zero vector used as a color, which OpenGL interprets as black. Got to the 'Uniforms' tab and move around the XYZ sliders. Now you sould see the test model in a color you selected by setting the XYZ components to a RGB value. You can also select a color by using the colored button in the widget. Color selection works only with 3D and 4D float vectors.
If you define several uniforms, you can select uniform you want to manipulate in a combo box. Right to that combo box you can see the data type of that uniform. Data types define the values a uniform variable can store. For example, GL_BOOL only knows true and false, where GL_INT knows signed integer values.
You can use the sliders to select a value or you can enter the value directly in the spin box on the lest side. If you want to change the range of the slider, you can use the spin boxes on the left and the right side of the slider. If you want to edit matrix types, like GL_FLOAT_MAT3, you can only edit one matrix column at the same time. You can change the matrix column with the 'Active Matrix Column' spin box on the bottom of the widget. Matrices are initialized to identity matrices and not to zero matrices.
Uniform variables are available at all shader types, but they must be defined in all shaders that use them. If you define a uniform with the equal name but different type, the results are undefined!
There is one special uniform you cannot edit with the 'Uniforms' tab. This special uniform is declared as
uniform float time;
If you define a float uniform variable named 'time', the shader editor interprets it as a variable, that represents a counter of seconds since the GLSL program was linked. Because of that, the value of 'time' is set internally by the shader editor. You can test this functionality with the following code:
gl_FragColor = gl_Color * ( 0.5 + 0.5 * sin( time ) );
Now go on to the last tutorial, Geometry shaders.