DirectX - Geometry Shaders



The geometry-shader (GS) stage completely runs application-specified shader code with vertices taken as an input to create the ability to generate vertices which is mentioned as output.

The Geometry Shader

Unlike vertex shaders which operate on a single vertex, the geometry shader's inputs are the vertices which include full primitive with two vertices for lines, three vertices for triangles and single vertex for the mentioned point. Geometry shaders can also bring together in the vertex data for the edge-adjacent primitives which is considered as input.

The following illustration of geometry shader shows a triangle and draws a line with adjacent vertices −

Geometry-Shader

The abbreviated forms of various geometrical shaders are mentioned below −

Abbreviated Form Meaning
TV Triangle vertex
AV Adjacent vertex
LV Line vertex

The geometry shaders consumes more space with respect to SV PrimitiveID which allows per primitive data to be fetched or completed which is needed.

The geometry-shader stage includes the capability of creating the outputs of multiple vertices forming a single selected topology. The number of primitives which is emitted can include number of vertices which can be emitted statically. It includes strip lengths which can be created with the help of required function.

Geometry shader creates an output which is fed to rasterizer stage and/or to a vertex buffer in memory with the help of stream output stage. Output fed to the mentioned memory is always expanded to individual point/line/triangle lists.

When a geometry shader is always considered as active, it is invoked once for every primitive passed down or generated with respect to pipeline. Each invocation of the respective geometry shader should include the input of the required data for invoking primitive, whether that is a single point, a single line, or a single triangle.

A triangle strip from earlier mentioned pipeline would result in the invocation of the geometry shader for mentioned individual triangle as in the strip.

Various types of algorithms that can be implemented in the geometry shader include −

  • Point Sprite Expansion
  • Dynamic Particle Systems
  • Fur/Fin Generation
  • Shadow Volume Generation
  • Single Pass Render-to-Cubemap

The code snippet for the implementation of geometry shader in comparison to pixel shader or vertex shader is mentioned below −

PrimitiveType DataType Name [ NumElements ]
point VS_OUTPUT input[1] // Point of single element,
line VS_OUTPUT input[2] // Output with second element
line adj VS_OUTPUT input[4]
triangle VS_OUTPUT input[3]
triangle adj VS_OUTPUT input[6]
Advertisements