Glsl defines specific variables for different rendering stages. These predefined attributes (also called built-in variables) have specific attributes. All predefined variables start with GL. User-Defined variables cannot start with this.
The following categories are introduced.
(1) vertex coloring machine input
in int gl_VertexID;
in int gl_InstanceID;
Gl_vertexid is the index of the currently processed vertex. For array rendering, It is the index of the current vertex in the array; For indexed rendering, It is the index value obtained from the element buffer.
Gl_instanceid indicates the currently rendered instance, when instancedrendering is used.
(2) vertex coloring machine output
OutGl_pervertex
{
Vec4Gl_position;
FloatGl_pointsize;
FloatGl_clipdistance [];
}
Defines a block interface for the output.
Gl_positionIs the output coordinate of the current vertex (if there is no geometric coloring tool, it is in Clip-space ). This value is not required. However, if this parameter is not specified, unexpected results may occur. You can ignore this value if you use a conversion feedback, or if you disable Rasterization, or use a geometric coloring tool that uses User-Defined output to generate coordinates.
Gl_pointsizeSpecifies the width and height of a vertex. It is only necessary to specify its value when drawing a vertex.
Gl_clipdistanceAllows the shader to set the distance from a vertex to each cut plane. A positive value indicates that the vertex is inside (behind) the shear plane, and a negative value indicates outside (Before) the shear plane ).
(3) geometric coloring machine input
in gl_PerVertex
{
vec4 gl_Position;
float gl_PointSize;
float gl_ClipDistance[];
} gl_in[];
in int gl_PrimitiveIDIn;
Gl_pervertexContains the values transmitted from the front vertex shader.
Note: they have a prefix in the geometric coloring tool.Gl_inIsBlock. The size of this array depends on the inputLayoutKeyword. If you do not declare the block with a specific size, the system automatically completes the block. Functions availableLength ()Obtain its size.
Gl_primitiveidinIs the number of elements in the rendering process, that isGldraw ()Number of elements processed by the call.
The following definitions are available for glsl4.00 and later versions:
in int gl_InvocationID;
The geometric coloring tool can be called multiple times. This value specifies the current call.
(4) geometric coloring device output
out gl_PerVertex
{
vec4 gl_Position;
float gl_PointSize;
float gl_ClipDistance[];
};
out int gl_PrimitiveID;
out int gl_Layer;
Gl_pervertexIt has the same significance as the vertex coloring er stage.
Gl_primitiveidIs the User-Defined identifier of the element. It is directly transmitted to the part shader. If the part coloring er uses its related input but the geometric coloring er does not specify its value, then its value is predefined (if there is no geometric coloring tool OpenGL will automatically generate ).
Gl_layerUsed for renderingLayeredframebuffer objects,Specifies the layer to which a specific element is rendered.
Glsl4.10 also defines the following output:
out int gl_ViewportIndex;
It indicates that the current element will be used and the cropping test will be transformed by the view. Use andGl_layerSimilar.
(5) Part coloring machine input
in vec4 gl_FragCoord;
in bool gl_FrontFacing;
in float gl_ClipDistance[];
in vec2 gl_PointCoord;
in int gl_PrimitiveID;
Gl_fragcoordContains the window-space coordinates of the current part. If the entry does not reload it, its Z component will be written to the depth buffer. Its W component is 1/wclip (wclip is the W component of the output gl_position of the vertex or geometric coloring device)
Gl_frontfacing: If the element is viewed from the front, it is true; otherwise, it is false.
Gl_clipdistanceContains the output of the vertex coloring tool, but after linear interpolation based on the elements.
Gl_pointcoord: The position inside the vertex, which specifies the position of the part. It is the normalized value in [0, 1]. () The origin position depends on the coordinate settings of OpenGL. The default position is in the lower left corner.
Gl_primitiveid is the output of the geometric coloring tool. If it is not used, it is produced by OpenGL. It represents the raster metadata index.
Glsl4.00 added the following input:
in int gl_SampleID;
in vec2 gl_SamplePosition;
in int gl_SampleMaskIn[];
Some attributes of the sample in the pixel area are specified.
(6) global variables of the part shader
struct gl_DepthRangeParameters
{
float near;
float far;
float diff;
};
uniform gl_DepthRangeParameters gl_DepthRange;
This struct provides access to gldepthrange near and far values. Diff is equal to the difference between far and near.
(7) Part coloring er output
out float gl_FragDepth;
It is the value to be written into the depth buffer. It will also be used for deep testing. The part coloring er does not have to specify its value. It may beGl_fragcoord.z. Auto fill. It should be noted that if it is specified somewhere else, it must also be specified elsewhere.
The following output is added to glsl4.00:
out int gl_SampleMask[];
When multi-sample rendering is used, it is written.