All Topics  
Shader

 

   Email Print
   Bookmark   Link






 

Shader



 
 
A shader in the field of computer graphics
Computer graphics

Computer graphics are graphics created by computers and, more generally, the representation and manipulation of pictorial data by a computer....
 is a set of software instructions, which is used primarily to calculate rendering
Rendering (computer graphics)

Rendering is the process of generating an image from a 3D model, by means of computer programs. The model is a description of three-dimensional objects in a strictly defined language or data structure....
 effects on graphics hardware with a high degree of flexibility. Shaders are used to program the graphics processing unit
Graphics processing unit

A graphics processing unit or GPU is a dedicated graphics rendering device for a personal computer, workstation, or game console. Modern GPUs are very efficient at manipulating and displaying computer graphics, and their highly parallel structure makes them more effective than general-purpose Central processing unit for a range of com...
 (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.

ially, shaders were used to perform pixel shading
Shading

Shading refers to wikt:depicting depth in 3D models or illustrations by varying levels of darkness....
 only (see Pixel shader
Pixel shader

A pixel shader is a shader program, often executed on a graphics processing unit. It adds 3D shading and lighting effects to pixels in an image, for example those in video games....
).






Discussion
Ask a question about 'Shader'
Start a new discussion about 'Shader'
Answer questions from other users
Full Discussion Forum



Encyclopedia


A shader in the field of computer graphics
Computer graphics

Computer graphics are graphics created by computers and, more generally, the representation and manipulation of pictorial data by a computer....
 is a set of software instructions, which is used primarily to calculate rendering
Rendering (computer graphics)

Rendering is the process of generating an image from a 3D model, by means of computer programs. The model is a description of three-dimensional objects in a strictly defined language or data structure....
 effects on graphics hardware with a high degree of flexibility. Shaders are used to program the graphics processing unit
Graphics processing unit

A graphics processing unit or GPU is a dedicated graphics rendering device for a personal computer, workstation, or game console. Modern GPUs are very efficient at manipulating and displaying computer graphics, and their highly parallel structure makes them more effective than general-purpose Central processing unit for a range of com...
 (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.

Introduction

Initially, shaders were used to perform pixel shading
Shading

Shading refers to wikt:depicting depth in 3D models or illustrations by varying levels of darkness....
 only (see Pixel shader
Pixel shader

A pixel shader is a shader program, often executed on a graphics processing unit. It adds 3D shading and lighting effects to pixels in an image, for example those in video games....
). However, the term stuck and is used for other graphics pipeline stages now, too.

As Graphics Processing Unit
Graphics processing unit

A graphics processing unit or GPU is a dedicated graphics rendering device for a personal computer, workstation, or game console. Modern GPUs are very efficient at manipulating and displaying computer graphics, and their highly parallel structure makes them more effective than general-purpose Central processing unit for a range of com...
s evolved, major graphics software libraries such as OpenGL
OpenGL

OpenGL is a standard specification defining a cross-language cross-platform Application programming interface for writing applications that produce 2D computer graphics and 3D computer graphics....
 and Direct3D
Direct3D

Direct3D is part of Microsoft's DirectX application programming interface. Direct3D is only available for Microsoft's various Microsoft Windows operating systems and is the base for the graphics API on the Xbox and Xbox 360 console systems....
 began to exhibit enhanced ability to program these new GPUs by defining special shading functions in their API
Application programming interface

An application programming interface is a set of subroutine, data structures, class and/or Protocol provided by library and/or operating system Service s in order to support the building of applications....
.

Types of shaders

The Direct3D
Direct3D

Direct3D is part of Microsoft's DirectX application programming interface. Direct3D is only available for Microsoft's various Microsoft Windows operating systems and is the base for the graphics API on the Xbox and Xbox 360 console systems....
 and OpenGL
OpenGL

OpenGL is a standard specification defining a cross-language cross-platform Application programming interface for writing applications that produce 2D computer graphics and 3D computer graphics....
 graphic libraries use three types of shaders.

  • Vertex shader
    Vertex shader

    Vertex shader is a shader program, normally executed on the Graphics processing unit....
    s 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 shader
    Geometry shader

    A geometry shader is a shader program model introduced with Shader Model 4.0 of DirectX 10. NVIDIA GeForce 8800 Graphics processing unit were the first providing hardware support for Geometry Shaders....
    s 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 shader
    Pixel shader

    A pixel shader is a shader program, often executed on a graphics processing unit. It adds 3D shading and lighting effects to pixels in an image, for example those in video games....
    s, 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
    Bump mapping

    Bump mapping is a computer graphics technique where at each pixel, a perturbation to the surface normal of the object being rendering is looked up in a heightmap and applied before the illumination calculation is done ....
     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
Unified shader model

Unified Shader Model term is used to describe two similar but separate concepts: Unified Shading Architecture and Unified Shader Model....
 unifies the three aforementioned shaders in OpenGL
OpenGL

OpenGL is a standard specification defining a cross-language cross-platform Application programming interface for writing applications that produce 2D computer graphics and 3D computer graphics....
 and Direct3D 10. See .

As these shader types are processed within the GPU
Graphics processing unit

A graphics processing unit or GPU is a dedicated graphics rendering device for a personal computer, workstation, or game console. Modern GPUs are very efficient at manipulating and displaying computer graphics, and their highly parallel structure makes them more effective than general-purpose Central processing unit for a range of com...
 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
    Shading language

    A shading language is a special programming language adapted to easily map on shader programming. Those kind of languages usually have special data types like color and normal....
     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
Parallel computing

Parallel computing is a form of computing in which many calculations are carried out simultaneously, operating on the principle that large problems can often be divided into smaller ones, which are then solved Concurrency ....
, and most modern GPUs have a multi-core
Multi-core (computing)

A multi-core processor combines two or more independent cores into a single package composed of a single integrated circuit , called a Die , or more dies packaged together....
 design to facilitate this, vastly improving efficiency of processing.

Programming shaders

OpenGL
OpenGL

OpenGL is a standard specification defining a cross-language cross-platform Application programming interface for writing applications that produce 2D computer graphics and 3D computer graphics....
 (version 1.5 and newer) provides a C
C (programming language)

C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
-like Shader language called OpenGL Shading Language, or GLSL. There are also interfaces for the Cg shader language, developed by Nvidia
NVIDIA

Nvidia is a multinational corporation specializing in the manufacture of graphics processing unit technologies for workstations, desktop computers, and mobile devices....
, which is syntactically somewhat similar to GLSL.

In the Microsoft Direct3D
Direct3D

Direct3D is part of Microsoft's DirectX application programming interface. Direct3D is only available for Microsoft's various Microsoft Windows operating systems and is the base for the graphics API on the Xbox and Xbox 360 console systems....
 API (Direct3D 9 and newer), shaders are programmed with High Level Shader Language, or HLSL.

See also

  • List of common shading algorithms
    List of common shading algorithms

    Below is the list of common shading algorithms:* Lambertian reflectance* Gouraud shading* Phong shading* Blinn?Phong shading model* Oren-Nayar diffuse model...
  • GPGPU
    GPGPU

    General-purpose computing on graphics processing units is the technique of using a graphics processing unit, which typically handles computation only for computer graphics, to perform computation in applications traditionally handled by the central processing unit....
     allows general-purpose computations on the GPU. For example, nVidia's CUDA
    Cuda

    Cuda may refer to:* Plymouth Barracuda, a Chrysler automobile* CUDA, a computer processing technology* Cuda, a czechlosovakian last name...
     programming language.


External links



Further reading

  • : 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
    Ken Perlin

    Ken Perlin is a professor in the Department of Computer Science at New York University. His research interests include graphics, animation, multimedia, and science education....
    , Steven Worley: Texturing and modeling: a procedural approach, AP Professional, ISBN 0-12-228730-4. Ken Perlin
    Ken Perlin

    Ken Perlin is a professor in the Department of Computer Science at New York University. His research interests include graphics, animation, multimedia, and science education....
     is the author of Perlin noise
    Perlin noise

    Perlin noise is a Procedural_generation Texture_%28computer_graphics%29 primitive, used by visual effects artists to increase the appearance of realism in computer graphics....
    , an important procedural texturing primitive.
  • Randima Fernando, Mark Kilgard
    Mark Kilgard

    Mark J. Kilgard is a graphics software engineer working at Nvidia.Prior to joining Nvidia, Mark worked at Compaq and Silicon Graphics. While at Silicon Graphics, he authored the OpenGL Utility Toolkit, better known as GLUT, to make it easy to write OpenGL-based 3D examples and demos....
    . The Cg Tutorial: The Definitive Guide to Programmable Real-Time Graphics, Addison-Wesley Professional, ISBN 0-321-19496-9
  • Randi J. Rost
    Randi J. Rost

    Randi J. Rost is a computer graphics professional and frequent contributor to graphics standards. He was an early participant in the personal computer industry, creating a game called King Cribbage for the Apple II computer in 1981 and publishing numerous instructional and review articles in trade publications....
    : OpenGL Shading Language, Addison-Wesley Professional, ISBN 0-321-19789-5
  • : HLSL Tutorial using DirectX with lots of sample code
  • GPGPU
    GPGPU

    General-purpose computing on graphics processing units is the technique of using a graphics processing unit, which typically handles computation only for computer graphics, to perform computation in applications traditionally handled by the central processing unit....
    : general purpose GPU
  • MSDN: