Shader

Shader ( from the English shade for " shaders " ) are hardware or software modules that implement certain rendering effects in the 3D computer graphics.

Hardware shader

Hardware shaders (also shader units, Shader Units ) are small processing units in current graphics chip ( on Windows since DirectX version 8, platform independent since OpenGL 2.0 approachable ). Shaders can be programmed to produce 3D effects. While fragment shaders alter the fragments and ultimately to calculate the resulting pixel color, serve vertex shader geometric calculations and dynamic changes of objects. Thus, for example, produce both shader combines the water effect in the computer game Far Cry. They can also be used for the calculation of lava, paint, fur, etc.. Since DirectX 10 and OpenGL 3.2 has been added as a third shader type of the Geometry shader that receives the output from the vertex shader polygon data and can edit them far more flexible, can even add more geometry to the scene ( the vertex shader can only existing geometry manipulate ). With DirectX 11 and OpenGL 4.0 tessellation has been added shader that in two steps ( Tessellation Tessellation Control and Evaluation ( OpenGL terminology ) or Hull and Domain shaders (DirectX terminology) ) can refine the geometry between the vertex and the Geometry Shader.

Shader units must not be understood as separate from the rest of computation units ( such as co-processors ), but as an integral part of the graphics chip within its rendering pipelines. Thus, the vertex shader is simply a programmable T & L unit, the pixel shader arose historically from the combiner - the exact structure of shader hardware is not fully documented. Conformity of the shader units to the standards DirectX and OpenGL is established via the graphics driver.

Since the functions of vertex and pixel shaders always further increased with time, ultimately the concept of unified shader was developed in which the hardware side difference between vertex, pixel shader disappears. This also had the advantage that no special hardware was needed for the later added shader types ( Geometry and Tessellation ), that is, they are implemented with the same hardware that also use vertex and pixel shaders. Here, all shader units of the graphics chip can now perform the same operations, which is a fixed separation between the shader types is no longer meaningful. As a result, now the graphics driver to decide which shader unit at which time as fitted, potentially means better performance yield as for video cards with fixed scheduled shader types.

Processing chain

  • CPU sends control commands and geometry data to the graphics card.
  • In the vertex shader, the key points of the geometry are transformed.
  • In the tessellation shaders (more precisely, tessellation control shaders and tessellation evaluation shaders ) the primitives ( eg triangles) are further subdivided.
  • Is a Geometry shader on the graphics chip is present and active, the geometry data through this now, this further changes to the scene are made.
  • Now the primitive is rasterized, where individual fragments are created. The only per vertex (vertex ) This information is here interpolated across the triangle area.
  • In the fragment shader, there are arithmetic arithmetic units ( shader units ) and texture units (Texture Mapping Units, TMUs ).
  • Once the fragment has been calculated, the test is performed on (Z test) visibility. When visibility, a write operation takes place in the frame buffer. This step can, under certain circumstances already be made directly after rasterization (Early Z test).

Programming

Shaders are written in specially designated languages ​​( in the early stages: assembly language today: Cg, GLSL, HLSL ) and the runtime of the 3D application from the graphics card driver translated into machine code understood by the graphics card, which is then executed in the shader units. For low-cost graphics chips, the shader units but are often omitted, so that the shader using the CPU must be calculated, which is much slower.

Thus, the functionality of the shader can be uniformly used by applications, both DirectX and OpenGL provide interfaces for their application. Over time, functionality and performance have increased the initially fairly simple shader units strong; Today is their programmability so advanced that you can do many calculations with them, which could only perform traditional CPUs, often even faster. This is known as General Purpose Computation on Graphics Processing Unit.

Problems with different versions

The first hardware shaders were relatively simple in concept, therefore had a software interface accordingly offer little. However, as with time, the functionality of the shader grew, the interfaces had to be extended accordingly, which often happened in particular with DirectX in consultation with the graphics card manufacturers. As a result, does not support any graphics chip each shader version, it's been no upward compatibility. This means that you have to pay for programming 3D graphics with shaders that serves as a fallback for older graphics cards exist that do not support the actually desired shader version, otherwise they are not, or only changed greatly display the graphic. If an application contains several shader solutions for various shader versions or different graphics cards, it is called these solutions render paths (English rendering path). Especially in the phases in which the former graphics card main competitor ATI and Nvidia released its own special shader versions, it was often necessary, and therefore continuous, two (or more ) render paths installed in applications: an ATI optimized and an Nvidia optimized, maybe even more.

DirectX

Under Direct3D, the 3D graphics interface of DirectX, shaders programmed in the language HLSL, and depending on the version of DirectX various shader versions are offered. The following table shows the relationship between the individual and DirectX shader versions:

OpenGL

In OpenGL own C-like shader language since version 2.0 integrated, the OpenGL Shading Language, GLSL short. Previously shader programming was possible only through manufacturer-specific interfaces. Through the use of GLSL you are no longer limited to the use of proprietary technology and use on the Windows platform and shaders can now use on a variety of platforms such as Mac OS X or Linux.

712562
de