OpenGL Shading Language

The OpenGL Shading Language (abbreviated: GLSL or glSlang ) is a programming language in order to execute on the GPU using OpenGL own programs called shaders.

  • 3.1 Vertex Shader
  • 3.2 fragment shader

Emergence and development

Under shading, the change of individual vertices or fragments is referred to within the graphics pipeline in computer graphics. The shaders calculate the appearance of an object or create special effects. Typical tasks include the texturing and lighting. In the classical (so-called Fixed Function) OpenGL pipeline, the individual calculation steps of the shader are immutable and it can only individual parameters are configured. To overcome this limitation, GLSL 1.4 was introduced as an extension to the OpenGL version. GLSL allows you to define parts of the pipeline free of customized programs. Thus, for example, a particular illumination model or a texture effect as bump mapping can be implemented.

With the OpenGL version 2.0, the language became an official part of the OpenGL specification that defines the functionality of OpenGL. The initial GLSL version offered only one vertex and fragment shaders. With the OpenGL version 3.2 it has been supplemented by the Geometry Shader with the version 4.0 to the tessellation control and tessellation evaluation shaders and version 4.3 in order to compute shader.

With today based on GLSL pipeline can be, with the exception of the rasterization program all processing steps on the graphics card.

In the specification of GLSL also keywords ( precision qualifier ) of the programming language GLSL ES daughter were taken. These are exclusively designed for portability with OpenGL ES and possible extensions, as such, but have no function or meaning in GLSL. The functionalities of GLSL ES are described in a separate specification, and is thus not part of GLSL.

GLSL is in competition with HLSL, which provides the equivalent functionality for Direct3D.

Speech features

GLSL is a C-like programming language that is specially adapted to the needs of shaders. Thus, there are built-in types for vectors, matrices, and a variety of math and graphics functions. Many of the operations offered on multiple data elements can operate simultaneously ( SIMD ). In contrast to C, there is no pointer ( pointer).

There are five different GLSL shader types; Vertex, tessellation, geometry and fragment shaders as part of the rendering pipeline and independent thereof compute shader. Each shader type has characteristic input and output parameters. The application developer shall deliver to the OpenGL drivers for each shader type the shader source code and any additional variables and constants. The driver compiles and links the shaders to a shader program. There are not necessarily use all types of shaders.

Each primitive, which will draw the viewer now passes the shader contained in the shader program in the following order:

1 Vertex Shaders

For each vertex of the vertex shader is executed once. Only the shader has access to the vertex being treated (including its texture coordinates, normals, and other data handed ), but not on the neighboring vertices, the topology or the like.

2 Tessellationshader

In Tessellationshadern can be divided into smaller areas, a surface ( triangle or quadrangle ). In the implementation distinguishes between tessellation control shaders and tessellation evaluation shader.

3 Geometryshader

In Geometryshader (point, line, triangle) new primitives can be created from an existing primitive.

4 fragment shader

The fragment shader for each fragment (pixel before they are displayed on the display device ) executed once. Here, the color is calculated for the corresponding fragment. Fragment shaders are the equivalent to Direct3Ds pixel shader.

Compute Shader

This shader type can edit and thus perform GPGPU calculations in OpenGL Context independent of the graphics pipeline data.

Example

An example of a GLSL program from a vertex and a fragment shader. The program generates a red silhouette of all objects.

Vertex shader

This vertex shader behaves like the classical (Fixed Function) OpenGL pipeline. He sets the foreground color of the vertex to the specified color by the application ( GL_COLOR ) and the matrix gl_ModelViewProjectionMatrix positioned vertex ( gl_Vertex ) relative to the camera in space.

Void main (void)    {      gl_FrontColor = GL_COLOR;      gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;    } fragment shader

This simple fragment shader ignores the input color ( GL_COLOR ), and sets the color to red fragment.

Void main (void)    {      gl_FragColor = vec4 (1.0, 0.0, 0.0, 1.0);    } Revision history

  • OpenGL 2.0
  • First release
  • OpenGL 2.1
  • Non-square matrices
  • Centroid - based interpolation between vertex and fragment shaders
  • Invariant values ​​from the same expressions of different programs
  • Outer product of a linear algebraic matrix multiplication
  • Transpose of a matrix
  • Coordinates of the current fragment within a point primitive
  • OpenGL 3.0
  • Multiple selection
  • Integer texture data types
  • Unsigned Ganzahl, vector and texture data types
  • Non- linear interpolation and non- perspective interpolation
  • Hyperbolic angle functions
  • Deposit and round floating-point numbers
  • OpenGL 3.1
  • Format layout for variable declaration
  • Inverting a matrix
  • OpenGL 3.2
  • Choice between core profile and compatibility profile
  • Determine a matrix
  • Geometry Shader
  • OpenGL 3.3
  • Full conversion between Ahlen and floating-point numbers with maintaining the bit -level representation
  • OpenGL 4.0
  • Floating-point data type double precision
  • Packing and unpacking of floating point numbers
  • Tessellation shader
  • OpenGL 4.1
  • OpenGL 4.2
  • Access control of memory variables
  • Packing and unpacking of integers
  • OpenGL 4.3
  • Compute Shader
  • OpenGL 4.4
269586
de