Graphics Reference
In-Depth Information
These are illustrated in the examples below, but they are prety self-explan-
atory. You should expect to have several instances of EmitVertex( ) as you go
through the shader program, but you may or may not call EndPrimitive( ) ,
depending on whether you are emiting only one primitive from the shader,
or several. There is no need to call EndPrimitive( ) at the end of the geometry
shader; this is implied.
New GLSL Variables and Variable Types
There are new kinds of variables that can be used in the geometry shader. If
there is a geometry shader, output variables from the vertex shader are col-
lected by the primitive assembly step and passed to the geometry shader once
enough vertices have been collected for the current primitive's topology type.
The user-defined variables that are input to the geometry shader from the ver-
tex shader are declared in the vertex shader as out and in the geometry shader
as in . The geometry shader's output variables, emited to be interpolated in
the rasterizer, are declared as out .
Geometry shaders use GLSL variables just like the vertex, tessellation, and
fragment shaders. Geometry shaders can access uniform variables, just like the
other shaders, and geometry shaders can access all the uniform variables from
the application (as well as the standard OpenGL-defined variables, such as the
transformation matrices, if you are working in compatibility mode). Thus, you
can transform the original vertices in the vertex shader, or transform them as
they are being emited from the geometry shader, whichever is more conve-
nient. However, there are several new GLSL variables to describe the data that
comes to the geometry shader from the vertex or tessellation shader. These are
described in detail in the next section.
Communication between a Vertex or Tessellation Shader
and a Geometry Shader
If there is a geometry shader, variables from the vertex or tessellation shader
are collected by a primitive assembly step and passed to the geometry shader
once enough vertices have been collected for the current topology type.
The geometry shader will take all the products of the vertex or tessel-
lation shader, from the geometric parts ( gl_Position , ...) to the appearance
parts ( vColor , vST , ...) and use them as parts of the primitives it assembles.
Notice that a vertex shader does not change the geometric primitive that is
defined in your application, but is free to write out values as needed for the
primitives it assembles.
Search WWH ::




Custom Search