Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
4 Variables and Types<br />
If multiple shaders are linked together, then they will share a single global uniform name space, including<br />
within a language as well as across languages. Hence, the types and initializers of uniform variables with<br />
the same name must match across all shaders that are linked into a single program.<br />
It is legal for some shaders to provide an initializer for a particular uniform variable, while another shader<br />
does not, but all provided initializers must be equal.<br />
4.3.6 Outputs<br />
Shader output variables are declared with the out or centroid out storage qualifiers. They form the<br />
output interface between the declaring shader and the subsequent stages of the <strong>OpenGL</strong> pipeline. Output<br />
variables must be declared at global scope. During shader execution they will behave as normal<br />
unqualified global variables. Their values are copied out to the subsequent pipeline stage on shader exit.<br />
Only output variables that are read by the subsequent pipeline stage need to be written; it is allowed to<br />
have superfluous declarations of output variables.<br />
There is not an inout storage qualifier at global scope for declaring a single variable name as both input<br />
and output to a shader. Output variables must be declared with different names than input variables.<br />
However, nesting an input or output inside an interface block with an instance name allows the same<br />
names with one referenced through a block instance name.<br />
Vertex and geometry output variables output per-vertex data and are declared using the out storage<br />
qualifier, the centroid out storage qualifier, or the deprecated varying storage qualifier. They can only be<br />
float, floating-point vectors, matrices, signed or unsigned integers or integer vectors, or arrays or<br />
structures of any these.<br />
Individual vertex and geometry outputs are declared as in the following examples:<br />
out vec3 normal;<br />
centroid out vec2 TexCoord;<br />
invariant centroid out vec4 Color;<br />
noperspective out float temperature; // varying is deprecated<br />
flat out vec3 myColor;<br />
noperspective centroid out vec2 myTexCoord;<br />
These can also appear in interface blocks, as described in the section 4.3.7 “Interface Blocks”. Interface<br />
blocks allow simpler addition of arrays to the interface from vertex to geometry shader. They also allow a<br />
fragment shader to have the same input interface as a geometry shader for a given vertex shader.<br />
Fragment outputs output per-fragment data and are declared using the out storage qualifier. It is an error<br />
to use centroid out in a fragment shader. Fragment outputs can only be float, floating-point vectors,<br />
signed or unsigned integers or integer vectors, or arrays of any these. Matrices and structures cannot be<br />
output. Fragment outputs are declared as in the following examples:<br />
out vec4 FragmentColor;<br />
out uint Luminosity;<br />
31