Vertex Shader/Defined Outputs: Difference between revisions

From OpenGL Wiki
Jump to navigation Jump to search
Centralizing vertex shader outputs.
(No difference)

Revision as of 06:23, 25 July 2013

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.

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: 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.

gl_PointSize is the pixel width/height of the point being rasterized. It is only necessary to write to this when rendering point primitives.

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.