Microsoft DirectX 9.0

Pixel Shaders

Before Microsoft?DirectX?8.0, 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 run 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 text looks similar to assembly language and is assembled using Direct3D extensions (D3DX) 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 IDirect3DDevice9::CreatePixelShader. There are several pixel shader version. See Shader Reference.

Instruction sets are rapidly evolving, refer to each hardware vendors web site for details on how to best order instructions to avoid stalls. Alternatively, you can make maximum use of the High-Level Shader Language in order to get very efficiently compiled shader instructions using D3DX.

© 2002 Microsoft Corporation. All rights reserved.