#REDIRECT [[Shader#Types]]
'''Vertex''' and '''pixel''' (or '''fragment''') '''shaders''' are [[shader]]s that run on a [[graphics card]], executed once for every [[vertex]] or [[pixel]] in a specified [[3D computer graphics|3D]] [[mesh]]. They operate in the context of interactively [[rendering (computer graphics)|rendering]] a 3D scene, usually using either the [[Direct3D]] or [[OpenGL]] [[API]].
{{Rcat shell|
==Background==
{{R to section}}
}}
Flexible shaders were initially used for non-interactive rendering applications like Pixar's [[RenderMan]], which was designed to render [[film]]-quality images.
3D hardware previously used fixed-function pipelines in which, for example, one was stuck with the [[lighting]] model chosen by the hardware vendor. Graphics hardware was able to do transformation and lighting (T&L for short) on the GPU, but it was not flexible. A vertex shader sidesteps the T&L stage in the pipeline and lets the user add on to it.
Pixel shaders operate after the [[geometry pipeline]] and before final [[rasterization]]. They operate in parallel with multitexturing to produce a final pixel color and z-value for the final, rasterization step in the graphics pipeline (where alpha blending and depth testing occur).
Since [[2001]], video cards from [[Nvidia]] and [[ATI Technologies]] have begun supporting pixel and vertex shaders in hardware, allowing their use for real-time rendering. The technology has gone through several iterations since then, and the latest generation of games, including ''[[Doom 3]]'' and ''[[Half-Life 2]]'' make increasing use of hardware shaders. ATI and Nvidia have often caused standards confusion by supporting different instructions and capabilities, but the existence of standard shader models in [[DirectX]] has prevented a full-blown standards war so far.
==Details==
The programs are written in either the native assembly language of the card or in a high-level shader language like the aptly named [[HLSL|High Level Shader Language]]. Some key facts about vertex and pixel shaders are that they
* can only access data in the graphics card's own memory, such as texture and geometry data, and therefore cannot access data in the computer's main memory or cache.
* operate independently for each vertex or pixel. This ensures that they can be trivially [[parallel computing|parallelized]]. For instance, ATI's latest cards run 16 shaders at a time.
* have access to a rich [[instruction set]] including many [[Vector (spatial)|vector]] and [[Matrix (mathematics)|matrix]] operations, but often no branching.
* may be limited to a certain number of instructions and texture reads per vertex or pixel, which varies by card and shader language version.
Out of the most common graphics API's, DirectX has issued successively more powerful standard shader models, while [[OpenGL]] supports shaders primarily through hardware vendor provided extensions. Ignoring point releases, DirectX 8 supported Shader Model 1.0, which had little or no branching capability and limited pixels to 8-bit color, while DirectX 9 introduced Shader Models 2.0 and 3.0, which supported high dynamic range color and more advanced branching. [[Windows Vista]] is expected to add a new shader standard with more functionality.
==Capabilities==
The capabilities of vertex and pixel shaders are still being explored, and since hardware capabilites are improving with each generation of graphics cards, we can expect their abilities to approach those of programmable shaders such as RenderMan's.
There exist vertex shaders that:
* Apply an arbitrary deformation to the vertices of a mesh
* Perform [[toon shader|toon rendering]]
* Fake [[motion blur]]
* Apply a [[fisheye lens]] effect to the scene
There exist pixel shaders that:
* Apply an accurate per-pixel [[Phong lighting]] model
* Simulate multilayer metallic paint
* Fake [[volume lighting]], so that a spotlight lights up dust motes in the air
* Simulate turbulent air flow and display swirling wisps of smoke
* Apply [[depth of field]] to the scene
One of the most intriguing uses of hardware shaders is for physical simulation. The powerful vector math and parallelized architecture make current graphics cards much faster than general-purpose [[Central processing unit|CPU's]] for certain simulations where the current state at a certain point is only dependent upon the previous state for a small area around it, like turbulent flow. Several projects are exploiting this unintended use.
==The future==
New technologies, including [[DirectX]]'s Pixel Shader 3.0 specification and accompanying implementations, promise to increase shaders extensibility. Capabilities of more advanced programming languages, such as loops and if/then constructs, are being extended to the shader languages. Many experts see the logical continuation of this increasing flexibility to be the eventual merging of the pixel and vertex shaders into one unit. It seems likely that in the future the [[Graphics Processing Unit]], already rivaling the complexity of the CPU, will take over more graphically related tasks currently performed by CPUs. (Note: The Pixel Shader 3.0 is already available in new [[NVidia]] cards, for example in GeForce 6800).
To add possibility to generate a geometry inside the GPU, and further offload CPU of graphics related calculations, "Geometry Shaders" are considered as a future extension. Vertex Shaders can process vertices, however they can not create them.
==See also==
* [[Cg programming language]]
* [[List of computer games that require Pixel Shaders]]
* [[OpenGL Shading Language]]
== External links ==
* [http://www.ati.com/developer/sdk/radeonSDK/html/Tools/RenderMonkey.html ATI's RenderMonkey (very useful shader development tools) home page]
* [http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndrive/html/directx02192001.asp Microsoft DirectX vertex shader tutorial (for DirectX 8, but it applies to DX9 as well)]
* [http://www.opengl.org/documentation/oglsl.html OpenGL shading language]
[[Category:3D computer graphics]]
|