Share on Facebook Share on Twitter Email
Answers.com

Shader

 
Dictionary: Shad·er

n.

One who, or that which, shades.


Search unanswered questions...
Enter a question here...
Search: All sources Community Q&A Reference topics
Wikipedia: Shader
Top

In the field of computer graphics, a shader is a set of software instructions, which is used primarily to calculate rendering effects on graphics hardware with a high degree of flexibility. Shaders are used to program the graphics processing unit (GPU) programmable rendering pipeline, which has mostly superseded the fixed-function pipeline that allowed only common geometry transformation and pixel shading functions; with shaders, customized effects can be used.

Contents

Technology overview

Initially, shaders were used to perform pixel shading only (see Pixel shader). However, the term stuck and is used for other graphics pipeline stages now, too.

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.

Shaders are simple programs that describe the traits of either a vertex or a pixel. Vertex shaders describe the traits (position, texture coordinates, colors, etc.) of a vertex, while pixel shaders describe the traits (color, z depth and alpha value) of a pixel. A vertex shader is called for each vertex in a primitive (possibly after tessellation) - thus one vertex in - one (updated) vertex out. Each vertex is then rendered as a series of pixels on the screen (or more correctly, onto a surface (block of memory) that will eventually be sent to the screen.

Shaders replace a section of video hardware that's typically called the Fixed Function Pipeline (FFP). This is because it performs lighting and texture mapping in a hard-coded manner, while shaders let you replace this hard-coded approach with a programmable one.[1]

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. 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 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 multiple shader pipelines to facilitate this, vastly improving computation throughput.

Programming shaders

OpenGL (version 1.5 and newer) provides a C-like Shader language called OpenGL Shading Language, or GLSL.

In the Microsoft Direct3D API (Direct3D 9 and newer), shaders are programmed with High Level Shader Language, or HLSL.

Cg or C for Graphics is a high-level shading language developed by Nvidia in close collaboration with Microsoft for programming vertex and pixel shaders. It is very similar to Microsoft's HLSL.

See also

External links

Further reading

References

  1. ^  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.
  2. ^  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.
  3. ^  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".
  4. See http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter01.html for more details on Cg

Shopping: Shader
Top
 
 

 

Copyrights:

Dictionary. Webster 1913 Dictionary edited by Patrick J. Cassidy  Read more
Wikipedia. This article is licensed under the Creative Commons Attribution/Share-Alike License. It uses material from the Wikipedia article "Shader" Read more