Microsoft DirectX 8.0 (C++) |
Vertex shaders control the loading and processing of vertices. Microsoft® Direct3D® for Microsoft DirectX® 8.0 supports two types of vertex processing: programmable vertex processing and fixed-function vertex processing. In DirectX 8.0 documentation, the term vertex shader most often applies to the programmable mode, although the vertex shader API mechanism encompasses both types of functionality. Vertex shaders are defined at creation as using programmable vertex processing or fixed-function vertex processing. Once created, a vertex shader is referred to by its handle. Vertex shaders are not editable. To change a vertex shader, it must be destroyed and recreated.
Each vertex shader includes a function, which defines the operations to apply to each vertex, and a declaration, which defines the inputs to the shader, including how vertex elements in the input data streams are used by the shader.
Vertex processing performed by vertex shaders encompasses only operations applied to single vertices. The output of the vertex processing step is defined as individual vertices, each of which consists of a clip-space position (x, y, z, and w) plus color, texture coordinate, fog intensity, and point size information. The projection and mapping of these positions to the viewport, the assembling of multiple vertices into primitives, and the clipping of primitives is done by a subsequent processing stage and is not under the control of the vertex shader.
Fixed function vertex processing provides the same functionality as in Direct3D for DirectX 7.0, including transformation and lighting, vertex blending, and texture coordinate generation. Unlike programmed vertex shaders, where the operations applied to vertices are defined within the shader, fixed-function vertex processing is controlled by a device state set by methods on IDirect3DDevice8, which set lights, transforms, and so on. It is still useful to have multiple fixed-function vertex shaders, because even though the function is fixed and shared, the declarations can vary. This enables feeding the fixed-function shader with differing layouts of multistream inputs.
The input vertex elements for fixed-function vertex processing have fixed semantics. Thus the declaration tags specify input vertex elements as coordinate, normal, color, and so on. The vertex outputs for fixed-function vertex shaders always include coordinates, diffuse and specular colors, and multiple texture coordinates, as required by the current device state settings for pixel processing.
Programmed vertex shaders have a function defined by an array of instructions to apply to each vertex. The mapping of the input vertex elements to the vertex input registers for programmed vertex shaders is defined in the shader declaration, but the input vertex elements do not have specific semantics about their use. The interpretation of the input vertex elements is up to the shader instructions. The vertex outputs for programmed vertex shaders are explicitly written to by instructions in the shader function.
For more information on the Direct3DX vertex shader assembler, see Vertex Shader Assembler Reference.