VertexShaders are programmable functions in the rendering pipeline, that get executed for every vertex of a mesh.
They are used to transform the individual attributes of vertices, eg. vertex colors, normals, position, rotation, scale, lighting and most importantly, transformations from one space (dimension) into another (eg. model-space to projection-space).
1. Preprocessors
VertexShaders need specific preprocessors at the beginning, so that global-shader-constants, defined within shader_vars.h, can be mapped correctly.
For that to work, you obv. have to include shader_vars.h too.
Shader constants, just like Code-Textures or Code-Variables, are exposed by code and pre-defined.
Most of them are read-only and used to hold general data like:
matrices, time, lighting-information, fog-information, screen-size, parameters assigned within your technique, samplers …
Some constants defined in shader_vars.h can only be used within VertexShaders (constants explicitly registered via VERTEX_REGISTER( index )). Note: Some of them still work within PixelShaders (eg. renderTargetSize). What this should tell you is, that shader_vars.h is not
a stock file and not 100% correct. Using matrices within PixelShaders will def. throw an error … trust me, I tried.
3. Input and Output - structs
The vertex input-struct has to include all semantics that are defined within the technique that called your shader. See »[Technique/Semantics]
Using structs to manage your In- and Output is advised, tho there are different ways of managing your data.
/* snippet */
the above is an example, using a technique with the following semantics defined:
/* snippet */
using structs requires your vs_main function to return a completely initialized output struct:
Example:
if you only need some of the input parameters within the VertexShader, eg. to modify vertex positions, you don’t need to pass them to your PixelShader:
Example:
You can use the TEXCOORD 0-6 Semantic if you want to use certain values or constants within your PixelShader,
that are only accessible within the VertexShader stage: