Part I: Vertex Shader Reference

A vertex shader is made up of a set of instructions that operate on data for a single vertex. The shader is executed once for each vertex in a render primitive. A vertex shader will have one vertex input provided to it and will be expected to have one vertex output.

QUICK OVERVIEW

A vertex shader must do at least one thing: place the vertex's position in clip-space coordinates in the output position register. That is, the vertex position must be transformed by the current model/world/view transformation matrix. Now if your world, model, and projection matrix were identity, then you could just pass in the value that is fed to the shader, but usually you'd be getting the vertex position in world coordinates, and you'll need to transform the point and store that in the output register.

And though this will make the shader assembler happy, it doesn't do anything about describing how the vertex looks. So the second thing that is necessary to get it to be a useful shader is to specify how the vertex looks. There's more than one way to do this. If you are using a pixel shader, then the pixel shader decides what the pixel color will be, and you can get away with not setting it in the vertex shader. If you're using the fixed function pipeline, you should set the color either by setting the color register or by sampling a texture.

Failing to set the color (at least on hardware drivers) leaves these values undefined. On most debugging drivers and on the reference rasterizer, the color will default to black.

In addition, you'll need to specify the vertex shader version you are using as your first shader instruction to get the shader to assemble at all.



Real-Time Shader Programming(c) Covering Directx 9. 0
Real-Time Shader Programming (The Morgan Kaufmann Series in Computer Graphics)
ISBN: 1558608532
EAN: 2147483647
Year: 2005
Pages: 104
Authors: Ron Fosner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net