Difference between revisions of "Vertex Shader/Defined Outputs"

From OpenGL Wiki
Jump to navigation Jump to search
(Centralizing vertex shader outputs.)
 
(Formatting.)
 
(8 intermediate revisions by 4 users not shown)
Line 7: Line 7:
 
   float gl_PointSize;
 
   float gl_PointSize;
 
   float gl_ClipDistance[];
 
   float gl_ClipDistance[];
}
+
};
 
</source>
 
</source>
  
 
{{code|gl_PerVertex}} defines an [[Interface Block (GLSL)|interface block]] for outputs. The block is defined without an instance name, so that prefixing the names is not required.
 
{{code|gl_PerVertex}} defines an [[Interface Block (GLSL)|interface block]] for outputs. The block is defined without an instance name, so that prefixing the names is not required.
  
{{code|gl_Position}} is the output position of the current vertex. If the vertex shader is the last active shader stage before the fragment shader, and rasterization is still active (ie: {{enum|GL_RASTERIZER_DISCARD}} is not enabled), then the vertex shader must write to this variable. In that case, this value should be the clip-space vertex position.
+
These variables only take on the meanings below if this shader is the last active [[Vertex Processing]] stage, and if rasterization is still active (ie: {{enum|GL_RASTERIZER_DISCARD}} is not enabled). The text below explains how the [[Vertex Post-Processing]] system uses the variables. These variables may not be redeclared with interpolation qualifiers.
  
{{code|gl_PointSize}} is the pixel width/height of the point being rasterized. It is only necessary to write to this when rendering [[Primitive#Point_Primitives|point primitives]].
+
; {{code|gl_Position}}
 
+
: the clip-space output position of the current vertex.
{{code|gl_ClipDistance}} allows the shader to set the distance from a vertex to each clip plane. A positive distance means that the vertex is inside/behind the clip plane, and a negative distance means it is outside/in front of the clip plane. In order to use this variable, the user must manually redeclare it with an explicit size.
+
; {{code|gl_PointSize}}
 +
: the pixel width/height of the point being rasterized. It only has a meaning when rendering [[Point Primitive|point primitives]]. It will be clamped to the {{enum|GL_POINT_SIZE_RANGE}}.
 +
; {{code|gl_ClipDistance}}
 +
: allows the shader to set the distance from the vertex to each [[User-Defined Clip Plane|user-defined clipping half-space]]. A non-negative distance means that the vertex is inside/behind the clip plane, and a negative distance means it is outside/in front of the clip plane. Each element in the array is one clip plane. In order to use this variable, the user must manually redeclare it with an explicit size.  With {{require glsl|4.10|separate_shader_objects}}, the whole {{code|gl_PerVertex}} block needs to be redeclared. Otherwise just the {{code|gl_ClipDistance}} built-in needs to be redeclared.

Latest revision as of 04:04, 12 April 2019

Vertex Shaders have the following predefined outputs.

out gl_PerVertex
{
  vec4 gl_Position;
  float gl_PointSize;
  float gl_ClipDistance[];
};

gl_PerVertex defines an interface block for outputs. The block is defined without an instance name, so that prefixing the names is not required.

These variables only take on the meanings below if this shader is the last active Vertex Processing stage, and if rasterization is still active (ie: GL_RASTERIZER_DISCARD is not enabled). The text below explains how the Vertex Post-Processing system uses the variables. These variables may not be redeclared with interpolation qualifiers.

gl_Position
the clip-space output position of the current vertex.
gl_PointSize
the pixel width/height of the point being rasterized. It only has a meaning when rendering point primitives. It will be clamped to the GL_POINT_SIZE_RANGE.
gl_ClipDistance
allows the shader to set the distance from the vertex to each user-defined clipping half-space. A non-negative distance means that the vertex is inside/behind the clip plane, and a negative distance means it is outside/in front of the clip plane. Each element in the array is one clip plane. In order to use this variable, the user must manually redeclare it with an explicit size. With GLSL 4.10 or ARB_separate_shader_objects, the whole gl_PerVertex block needs to be redeclared. Otherwise just the gl_ClipDistance built-in needs to be redeclared.