Shader
From Wikipedia, the free encyclopedia
A Shader in the field of computer graphics is a set of software instructions, which is used by the graphic resources primarily to perform rendering effects.
Contents |
[edit] Introduction
From a technical view a "Shader" is a part of the renderer, which is responsible for calculating the color of an object - as opposed to calculating the visibility of an object.
As Graphics Processing Units evolved their ability to provide shading functions, the major graphics libraries such as DirectX and OpenGL began to reflect this by defining special shading functions to the API. The aforementioned was introduced in DirectX-Version 8 and in the platform independent graphic library OpenGL 2.0.
[edit] Types of shader
The DirectX and OpenGL graphic libraries use four types of shader.
- Pixel shader
- Vertex shader
- Geometry shader
- Unified shader
As these shader types are processed within the Graphics Processing Unit pipeline, the following gives an example how their are embedded in the pipeline:
[edit] Simplified graphic processing unit pipeline
- CPU sends instructions and geometry data to the graphic card respectively the graphic processing unit
- Within the vertex shader the geometry is transformed and some lighting calculations are performed.
- If a geometry shader is in the graphic processing unit, some changes of the geometries in the scene are done now.
- The calculated geometry from the past processes are put in the triangle setup. Furthermore triangles are transformed into Quads (one Quad is a 2 × 2 pixel primitive.).
- Pixel shader is applied.
- Visibility test is performed(z-test). If visible, write the pixels in the framebuffer.
[edit] Parallel processing
Shaders are written to apply a transformations to a large set of elements at a time, for example, to each pixel in an area of the screen, or for every vertex of a model. This is well suited to parallel processing, and most modern GPUs have a multi-core design to facilitate this, vastly improving efficiency of processing.
[edit] Programming Shaders
Since the version 2.0, OpenGL has included a C-like Shader-Language, called OpenGL Shading Language, or GLSL.
In DirectX, shaders are programmed with High Level Shader Language, but the types and complexity of shader programs allowed differ depending on what version of DirectX is used.
The following table shows the relations between DirectX-Versions:
DirectX-Version | Pixel-Shader | Vertex-Shader |
---|---|---|
8.0 | 1.0, 1.1 | 1.0 |
8.1 | 1.2, 1.3, 1.4 | |
9.0 | 2.0 | 2.0 |
9.0a | 2_A, 2_B | 2.x |
9.0c | 3.0 | 3.0 |
10.0 | 4.0 | 4.0 |
[edit] See also
[edit] External links
- All about pixel shaders
- All about vertex shaders
- Geometry shader tutorial
- Help scientists do DNA research with the shader units in your ATI graphics card or Playstation 3.
- nVidia releases a new programming environment and language compiler specifically for writing science applications that run on the shader units of its graphics cards. Also see developer's home page.
- OpenGL geometry shader extension
[edit] Further reading
- GLSL: OpenGL Shading Language @ Lighthouse 3D - GLSL Tutorial
- Steve Upstill: The RenderMan Companion: A Programmer's Guide to Realistic Computer Graphics, Addison-Wesley, ISBN 0-201-50868-0
- David S. Elbert, F. Kenton Musgrave, Darwyn Peachey, Ken Perlin, Steven Worley: Texturing and modeling: a procedural approach, AP Professional, ISBN 0-12-228730-4. Ken Perlin is the author of Perlin noise, an important procedural texturing primitive.
- Randima Fernando, Mark Kilgard. The Cg Tutorial: The Definitive Guide to Programmable Real-Time Graphics, Addison-Wesley Professional, ISBN 0-321-19496-9
- Randi J. Rost: OpenGL Shading Language, Addison-Wesley Professional, ISBN 0-321-19789-5
- Riemer's DirectX & HLSL Tutorial: HLSL Tutorial using DirectX with lots of sample code
- GPGPU: general purpose GPU
[edit] References
- ↑ Search ARB_shader_objects for the issue "32) Can you explain how uniform loading works?". This is an example of how a complex data structure must be broken in basic data elements.
- ↑ Required machinery has been introduced in OpenGL by ARB_multitexture but this specification is no more available since its integration in core OpenGL 1.2.
- ↑ Search again ARB_shader_objects for the issue "25) How are samplers used to access textures?". You may also want to check out "Subsection 2.14.4 Samplers".