Geometry Shader

Revision as of 08:21, 31 May 2010 by LtJax (Talk | contribs)

Jump to: navigation, search

A Geometry Shader (GS) is a Shader program that governs the processing of primitives. It happens after primitive assembly, as an additional optional step in that part of the pipeline. A GS can create new primitives, unlike vertex shaders, which are limited to a 1:1 input to output ratio. A GS can also do layered rendering; this means that the GS can specifically say that a primitive is to be rendered to a particular layer of the framebuffer.

Unlike other shader stages, a geometry shader is optional and does not have to be used.

Geometry shaders were incorporated into core OpenGL in version 3.2 and were previously available through the extensions GL_EXT_geometry_shader4 and GL_ARB_geometry_shader4.

Input/Output Specification

To use a geometry shader, its input and output primitive types have to be set. Also, a maximum number of output vertices has to be defined. Prior to their incorporation into core OpenGL, these variables had to be set via extension specific functions: glProgramParameteriEXT and glProgramParameteriARB for the EXT and ARB extensions respectively.

Since their promotion to a core feature however, these variables are now set directly in the GLSL source via layout qualifiers. A typical setup looks like this:

   layout(triangles) in;
   layout(triangle_strip, max_vertices=10) out;

Allowed input standard primitive types are points, lines, triangle as well as lines_adjacency and triangles_adjacency for primitives with adjacency information. Valid output primitives are points, line_strip and triangle_strip.