What is a "pixel shader"?

I have noticed that some games quote the requirement for "pixel shader 3.0 or better".

What is a pixel shader and is it some software requirements or hardware requirements?


Simple answer

Pixel shaders are tiny programs that can do operations on a single pixel on the screen, as opposed to geometry shaders and vertex shaders which work on the geometrical primitives (triangles) that make up everything you see on the screen. The most common use for pixel shaders is 'shading', approximation to real world lighting. Commonly used shading model is Phong.

Pixel shaders are executed on your video card, so your video card needs to support them. Each new version provides more capabilities, so an older video card will not run newer shaders. A new version of the pixel shader specification (e.g. Pixel Shader 3.0) is usually released for each new version of DirectX (more accurately, Direct3D).

Software Requirements

You need to have the correct version of Direct3D (or OpenGL) installed in order to use the shaders. For example, Pixel Shader 4.0 requires at least Direct3D 10. Normally you don't have to worry about this, every game that uses Direct3D will install the correct version for you when you install the game. The only exceptions are Direct3D 10 and later, which will not run on Windows XP or earlier. You will need at least Windows Vista in order to play a game that uses Direct3D 10 or 11.

Wikipedia provides a nice list of Pixel Shader versions, the version of Direct3D you need, and the types of graphics cards that work with them.


Technical answer

The 'standard' stages of a 3D rendering pipeline are as follows (somewhat simplified):

  • Transformation (Moving, rotating and scaling all the objects in the scene)
  • Lighting
  • Projection ('Squashing' the 3D world into a 2D plane)
  • Clipping (Removing anything outside the field of view)
  • Rasterising (Converting the vector graphics (triangles, etc) into raster graphics (pixels))
  • Texturing
  • Display

Pixel Shaders are used as an alternative to the standard texturing phase. During rasterisation, each triangle is converted into pixels. These pixels do not have their final colour yet, but the do have a bunch of parameters associated with them. These include base colour, texture coordinates, lighting information, etc. The Pixel Shader is a small program that takes these parameters and uses them to calculate the final colour as it is displayed on the screen. The Pixel Shader has access to all texture data, and can use them to do interesting things such as blending two textures (to create a 'dirty' look), using a texture as a bump map (to simulate a relief), or to simulate reflections.

Hardware

On the hardware side, Pixel Shaders are executed on 'Shader Units', small processors on your GPU. Each Shader Unit is basically a very simple CPU, but a modern video card may contain thousands of these things (an AMD Radeon HD6990 contains over 3000). Older GPUs had different Shader Units for different tasks: Pixel Shaders were executed on different parts of the system than Vertex Shaders. Modern GPUs have so called 'unified shader units' which can perform all of these operations.


They are both a hardware and software requirement.

Pixel shaders (and shaders in general) are part of your video card (or GPU) hardware. However, you also need a version of DirectX/OpenGL recent enough to support that video card's capabilities, or your game can't really use them.

Shaders are part of the rendering process that contribute massively to your game looking totally awesome and they do it with very little resources. They rock, so every game developer is going to be using them. If new games are beginning to warn you that you need new shader versions, your system's becoming obsolete.

Need to upgrade?

Wikipedia has a list which covers the maximum shader version supported by various video card series. Make sure your DirectX/OpenGL are up to date, update them if not, then go buy yourself a new video card.

Pixel Shader 3.0 was released in 2004, so considering how old it is, video cards that don't support it probably aren't even sold anymore.


Basically, you start off with the base pixel which has some color.

Then you give the pixel shader details about where the pixel is (lighting, z-level etc) and it computes the modified color.

Think about a bright red pixel in the sun. When it's in the shade, or in the background, that pixel will be a darker color. That's pretty much it.

Note that it only works on one pixel at a time.