less_retarded_wiki

main page, file list (598), source, all in md+txt+html+pdf, commit RSS feed, report abuse, stats, random article, consoomer version

Shader

Shader is a computer program running on the graphics processing unit (GPU), typically in many parallel instances so as to utilize the GPU's highly parallel nature and so achieve very high processing speed. As such shaders are simple to mid complexity programs. There are different types of shaders based on what kind of data they process -- most notable are probably fragment (also pixel) shaders that process pixels which then end up on the screen -- without explicitly mentioning what kind of shader we are talking about it is usually assumed we mean fragment shaders. The word shader is also used more loosely as a synonym for a special visual effect or material look in 3D graphics (e.g. games), because shaders are usually the means of achieving such effects.

Shaders are normally written in a special shading language such as GLSL in the OpenGL API, HLSL (proprietary) in Direct3D API or the Metal shading language (proprietary) in Metal API. These languages are often similar to C with some additions (e.g. vector and matrix data types) and simplifications (e.g. no function recursion or dynamic memory allocation). High level frameworks like Blender many times offer visual programming (point-n-click) of shaders with graph/node editors.

Initially (basically early 2000s) shaders were used only for graphics, i.e. to transform 3D vertices, draw triangles and compute pixel colors. Later on as GPUs became more general purpose (GPGPU), flexibility was added to shaders that allowed to solve more problems with the GPU and eventually general compute shaders appeared (OpenGL added them in version 3.3 in 2010).

To put shaders in the context, the flow of data is this: a CPU uploads some data (3D models, textures, ...) to the GPU and then issues a draw command -- this makes the GPU start its pipeline consisting of different stages, e.g. the vertices of 3D models are transformed to screens space (the vertex stage), then triangles are generated and rasterized (the shading stage) and the data is output (on screen, to a buffer etc.). Some of these stages are programmable and so they have their own type of a shader. The details of the pipeline differ from API to API, but in general, depending on the type of data the shader processes (the stage), we talk about:


Powered by nothing. All content available under CC0 1.0 (public domain). Send comments and corrections to drummyfish at disroot dot org.