Pixel Shaders

DirectX8

Microsoft DirectX 8.1 (C++)

Pixel Shaders

Before Microsoft® DirectX® 8.x, Microsoft® Direct3D® used a fixed function pipeline for converting three-dimensional (3-D) geometry to rendered screen pixels. The user sets attributes of the pipeline that control how Direct3D transforms, lights, and renders pixels. The fixed function vertex format is declared at compile time and determines the input vertex format. Once defined, the user has little control over pipeline changes during run time.

Shaders add a new dimension to the graphics pipeline by allowing the vertex transform, lighting, and individual pixel coloring functionality to be programmed. Pixel shaders are short programs that execute for each pixel when triangles are rasterized. This gives the user a new level of dynamic flexibility over the way that pixels are rendered.

A pixel shader contains pixel shader instructions made up of ASCII text. Arithmetic instructions can be used to apply diffuse and/or specular color. Texture addressing instructions provide a variety of operations for reading and applying texture data. Functionality is available for masking and swapping color components. The shader ASCII text looks similar to assembly language and is assembled using Direct3DX assembler functions from either a text string or a file. The assembler output is a series of opcodes that an application may provide to Direct3D by means of IDirect3DDevice8::CreatePixelShader. The Pixel Shader Reference has a complete listing of shader instructions.

To understand more about pixel shaders, see the following sections.

  • Create a Pixel Shader contains a code sample that uses a pixel shader to apply Gouraud interpolated diffuse colors to an object. This example contains a detailed explanation of the methods used.
  • Texture Considerations details the texture stage states that are ignored during pixel shaders.
  • Confirming Pixel Shader Support gives a more detailed explanation of the structures for enumerating pixel shader support.
  • Pixel Shader Examples shows more code samples that add textures and blend vertex colors and textures.
  • Converting Texture Operations gives examples of converting texture operations to pixel shader instructions.
  • Debugging provides debugging information.