Shader

Shader

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. Shaders are used to allow a 3D application designer to program the graphics processing unit (GPU) "programmable pipeline", which has mostly superseded the older "fixed-function pipeline", allowing more flexibility in making use of advanced GPU programmability features.

Introduction

From a technical view a "shader" is a part of the renderer, which is responsible for calculating the color of an object.

As Graphics Processing Units evolved, major graphics software libraries such as OpenGL and Direct3D began to exhibit enhanced ability to program these new GPUs by defining special shading functions in their API. Changes were introduced to reflect shader capabilities in the platform independent graphics library OpenGL version 1.5, and in the proprietary Direct3D version 8.

Types of shaders

The Direct3D and OpenGL graphic libraries use three types of shaders.

* Vertex shaders are run once for each vertex given to the graphics processor. The purpose is to transform each vertex's 3D position in virtual space to the 2D coordinate at which it appears on the screen (as well as a depth value for the Z-buffer). Vertex shaders can manipulate properties such as position, color, and texture coordinate, but cannot create new vertices. The output of the vertex shader goes to the next stage in the pipeline, which is either a geometry shader if present or the rasterizer otherwise.
* Geometry shaders can add and remove vertices from a mesh. Geometry shaders can be used to generate geometry procedurally or to add volumetric detail to existing meshes that would be too costly to process on the CPU. Direct3D 10 added geometry shader support to the Direct3D API. OpenGL supports geometry shaders through the use of an extension, though it may be incorporated into the standard itself with version 3.1. If geometry shaders are being used, the output is then sent to the rasterizer.
* Pixel shaders, also known as fragment shaders, calculate the color of individual pixels. The input to this stage comes from the rasterizer, which fills in the polygons being sent through the graphics pipeline. Pixel shaders are typically used for scene lighting and related effects such as bump mapping and color toning. (Direct3D uses the term "pixel shader," while OpenGL uses the term "fragment shader." The latter is arguably more correct, as there is not a one-to-one relationship between calls to the pixel shader and pixels on the screen. The most common reason for this is that pixel shaders are often called many times per pixel for every object that is in the corresponding space, even if it is occluded; the Z-buffer sorts this out later.)

The Unified shader model unifies the three aforementioned shaders in OpenGL and Direct3D 10. See [http://www.nvidia.com/object/geforce_8600_8500_faq.html NVIDIA faqs] .

As these shader types are processed within the GPU pipeline, the following gives an example how they are embedded in the pipeline:

Simplified graphic processing unit pipeline

* The CPU sends instructions (compiled shading language programs) and geometry data to the graphics processing unit, located on the graphics card.
* Within the vertex shader, the geometry is transformed and lighting calculations are performed.
* If a geometry shader is in the graphic processing unit, some changes of the geometries in the scene are performed.
* The calculated geometry is triangulated (subdivided into triangles).
* Triangles are transformed into pixel quads (one pixel quad is a 2 × 2 pixel primitive).

Parallel processing

Shaders are written to apply 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.

Programming shaders

Since version 1.5, OpenGL has had a C-like Shader-Language available to it, called OpenGL Shading Language, or GLSL. There are also interfaces for the Cg shader language, developed by Nvidia, which is syntactically somewhat similar to GLSL.

In Direct3D, shaders are programmed with High Level Shader Language, or HLSL, but the types and complexity of shader programs allowed differ depending on what version of Direct3D is used.

The following table shows the relations between Direct3D versions:

See also

*List of common shading algorithms

External links

* [http://appsrv.cse.cuhk.edu.hk/~ymxie/Geometry_Shader Geometry shader tutorial]
* [http://wiki.directxers.com/index.php?title=Tutorial_5:_Geometry_Shader Direct3D Geometry shader tutorial code]
*nVidia releases a [http://www.nvidia.com/object/IO_37226.html new programming environment] and language compiler specifically for writing science applications that run on the shader units of its graphics cards. Also see [http://developer.nvidia.com/object/cuda.html developer's home page] .
* [http://www.msi.unilim.fr/~porquet/glexts/GL_EXT_geometry_shader4.txt.html OpenGL geometry shader extension]

Further reading

* [http://www.lighthouse3d.com/opengl/glsl/ 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. Ebert, 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
* [http://www.riemers.net/eng/Tutorials/DirectX/Csharp/series3.php Riemer's DirectX & HLSL Tutorial] : "HLSL Tutorial using DirectX with lots of sample code"
*GPGPU: "general purpose GPU"
*MSDN: [http://msdn2.microsoft.com/en-us/library/bb205123.aspx Pipeline Stages (Direct3D 10)]

References

# Search [http://oss.sgi.com/projects/ogl-sample/registry/ARB/shader_objects.txt 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 [http://oss.sgi.com/projects/ogl-sample/registry/ARB/multitexture.txt ARB_multitexture] but this specification is no more available since its integration in core OpenGL 1.2.
# Search again [http://oss.sgi.com/projects/ogl-sample/registry/ARB/shader_objects.txt 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".


Wikimedia Foundation. 2010.

Игры ⚽ Нужно решить контрольную?

Look at other dictionaries:

  • Shader — sind Hardware oder Software Module, die bestimmte Rendering Effekte bei der 3D Computergrafik implementieren. Inhaltsverzeichnis 1 Hardware Shader 1.1 Verarbeitungskette 2 Programmierung …   Deutsch Wikipedia

  • Shader — Shad er, n. One who, or that which, shades. [1913 Webster] …   The Collaborative International Dictionary of English

  • Shader — Un shader (le mot est issu du verbe anglais to shade pris dans le sens de « nuancer ») est une suite d instructions donnée à un ordinateur, utilisé en image de synthèse, pour paramétrer une partie du processus de rendu réalisé par une… …   Wikipédia en Français

  • Shader — La tecnología shaders es cualquier unidad escrita en un lenguaje de sombreado que se puede compilar independientemente. Es una tecnología reciente y que ha experimentado una gran evolución destinada a proporcionar al programador una interacción… …   Wikipedia Español

  • shader — vaizdo inžinierius statusas T sritis profesijos apibrėžtis Televizijos studijos inžinierius, atsakingas už vaizdų, gaunamų iš įvairių kamerų, kokybę. Jis valdo visas vaizdų įrašymo, mišrinimo ir jų perdavimo į televizijos siųstuvą operacijas.… …   Inžinieriai, technikai ir technologai. Trikalbis aiškinamasis žodynėlis

  • shader — shade ► NOUN 1) comparative darkness and coolness caused by shelter from direct sunlight. 2) a colour, especially with regard to how light or dark it is. 3) a position of relative inferiority or obscurity: your bravery puts me in the shade. 4) a… …   English terms dictionary

  • Shader Language — Shader Un shader (anglais, du verbe to shade : ombrager ou estomper, nuancer) est un programme[Quoi ?] utilisé en image de synthèse pour paramétrer une partie du processus de rendu réalisé par une carte graphique ou un moteur de rendu… …   Wikipédia en Français

  • Shader Model — Shader Un shader (anglais, du verbe to shade : ombrager ou estomper, nuancer) est un programme[Quoi ?] utilisé en image de synthèse pour paramétrer une partie du processus de rendu réalisé par une carte graphique ou un moteur de rendu… …   Wikipédia en Français

  • Shader language — Shader Un shader (anglais, du verbe to shade : ombrager ou estomper, nuancer) est un programme[Quoi ?] utilisé en image de synthèse pour paramétrer une partie du processus de rendu réalisé par une carte graphique ou un moteur de rendu… …   Wikipédia en Français

  • Shader Radio — Shader is a blend of comedy and music and is South Jersey s home for hard rock and heavy metal. You can hear Shader every Thursday from 10pm 2am in the Philly/south Jersey area on 88.9, 95.1, 100.7 FM and online at http://www.z889.org/ . Shader… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”