OpenGL Shading Language

from Wikipedia, the free encyclopedia
OpenGL Shading Language
Publishing year: 2002
Developer: Khronos Group
Current  version : 4.60   (July 23, 2017)
Influenced by: C.
www.opengl.org/documentation/glsl/

The OpenGL Shading Language (short: GLSL or glSlang ) is a programming language for executing your own programs, so-called shaders , on the graphics processor using OpenGL .

Creation and further development

In computer graphics , shading refers to the change in individual vertices or fragments within the graphics pipeline . The shaders calculate the appearance of an object or create special effects. Typical tasks are, for example, texturing and lighting. In the classic (so-called Fixed Function) OpenGL pipeline, the individual calculation steps of the shader cannot be changed and only individual parameters can be configured. To overcome this limitation, GLSL was introduced as an extension in OpenGL version 1.4. GLSL allows parts of the pipeline to be freely defined using your own programs. So z. B. a special lighting model or a texture effect such as bump mapping can be implemented.

With OpenGL version 2.0, the language became an official part of the OpenGL specification , which defines the functional scope of OpenGL. The initial GLSL version only offered a vertex and fragment shader . With the OpenGL version 3.2 the geometry shader was added , with the version 4.0 with the tessellation control and tessellation evaluation shaders and with the version 4.3 with the compute shader .

With today's GLSL-based pipeline , all processing steps of the graphics card can be programmed directly , with the exception of rasterization .

Keywords (precision qualifiers) of the subsidiary programming language GLSL ES were also included in the specification of GLSL . These are intended exclusively for portability with OpenGL ES and possible extensions, but as such have no function or meaning in GLSL. The functionalities of GLSL ES are described in a separate specification and are therefore not part of GLSL.

GLSL competes with HLSL , which provides the equivalent functionality for Direct3D .

Language features

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

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

Each primitive that the application wants to draw now passes through the shaders contained in the shader program in the following order:

1. Vertex shader

The vertex shader is executed once for each vertex. The shader only has access to the vertex that has just been handled (including its texture coordinates, normals and other transferred data), but not to neighboring vertices, the topology or the like.

2. Tessellation shaders

A surface (triangle or square) can be subdivided into smaller surfaces in the tessellation square. In the implementation, a distinction is made between tessellation control shaders and tessellation evaluation shaders.

3. Geometryshader

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

4. Fragment shader

The fragment shader is executed once for each fragment (pixels before they are displayed on the display device). The color for the corresponding fragment is calculated here. Fragment shaders are the equivalent of Direct3D's pixel shaders.

Compute shader

This shader type can process data independently of the graphics pipeline and thus perform GPGPU calculations in the OpenGL context.

example

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

Vertex shader

This vertex shader behaves like the classic (fixed function) OpenGL pipeline. It sets the foreground color of the vertex to the color specified by the application ( gl_Color) and the matrix gl_ModelViewProjectionMatrixpositions the 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 fragment color to red.

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

history

Legend: Old version Older version; still supported Current version Current preliminary version Future version
version publication Description / changes
Older version; no longer supported: 1.10 April 30, 2004
  • OpenGL 2.0
  • first publication
Older version; no longer supported: 1.20 August 2, 2006
  • OpenGL 2.1
  • Non-square matrices
  • Centroid-based interpolation between vertex and fragment shaders
  • Invariant values ​​from the same expressions in different programs
  • Outer product of a linear algebraic matrix multiplication
  • Transpose a matrix
  • Coordinates of the current fragment within a point primitive
Older version; no longer supported: 1.30 August 11, 2008
  • OpenGL 3.0
  • Multiple choice
  • Integer texture data types
  • Unsigned integer, vector, and texture data types
  • non-perspective linear interpolation and non-interpolation
  • hyperbolic angle functions
  • truncate and round floating point numbers
Older version; no longer supported: 1.40 March 24, 2009
  • OpenGL 3.1
  • Format layout for variable declaration
  • Invert a matrix
Older version; no longer supported: 1.50 August 3, 2009
  • OpenGL 3.2
  • Choice between core profile and compatibility profile
  • determine a matrix
  • Geometry shader
Older version; no longer supported: 3.30 March 11, 2010
  • OpenGL 3.3
  • Conversion between integers and floating point numbers with retention of the bit-level representation
Older version; no longer supported: 4.00 March 11, 2010
  • OpenGL 4.0
  • Double precision floating point data type
  • Packing and unpacking floating point numbers
  • Tessellation shader
Older version; no longer supported: 4.10 July 26, 2010
  • OpenGL 4.1
Older version; no longer supported: 4.20 August 8, 2011
  • OpenGL 4.2
  • Access control of memory variables
  • Packing and unpacking integers
Older version; no longer supported: 4.30 August 6, 2012
  • OpenGL 4.3
  • Compute shader
Older version; no longer supported: 4.40 22. July 2013
  • OpenGL 4.4
Older version; no longer supported: 4.50 20th July 2014
  • OpenGL 4.5
  • Compatibility profile to OpenGL ES 3.1
  • Extended control of the calculation of derivatives
Current version: 4.60 23rd July 2017
  • OpenGL 4.6
  • Support for OpenGL SPIR-V

literature

  • Randi Rost: OpenGL Shading Language . 1st ed. Pearson Education, 2004, ISBN 0-321-19789-5 .
  • Heiko Ihde: Shader with GLSL: An introduction to the OpenGL Shading Language . 1st ed. Diplomica, 2009, ISBN 3-8366-7927-2 .

Web links

Individual evidence

  1. Language specification, version 4.30 (PDF; 830 kB; English)