Game Development Reference
In-Depth Information
In this sample, the vertex that we input into our vertex shader contains
only a position component. The vertex that our shader outputs contains
a position component and a color component.
The special colon syntax denotes a semantic , which is used to spec-
ify the usage of the variable. This is similar to the flexible vertex
format (FVF) of a vertex structure. For example, in VS_INPUT ,we
have the member:
vector position : POSITION;
The syntax “ : POSITION ” says that the vector position is used to
describe the position of the input vertex. As another example, in
VS_OUTPUT we have:
vector diffuse : COLOR;
Here “ : COLOR ” says that the vector diffuse is used to describe the
color of the output vertex. We talk more about the available usage iden-
tifiers in the next two chapters on vertex and pixel shaders.
Note: From a low-level perspective, the semantic syntax associates
a variable in the shader with a hardware register. That is, the input
variables are associated with the input registers, and the output vari-
ables are associated with the output variables. For example, the
position member of VS_INPUT is connected to the vertex input posi-
tion register. Similarly, diffuse is connected with a particular vertex
output color register.
16.1.3 Entry Point Function
As with a C++ program, every HLSL program has an entry point. In
our sample shader, we call our entry point function Main ; however, that
name is not mandatory. The shader's entry point function name can be
any valid function name. The entry point function must have an input
structure parameter, which is used to pass the input vertex into our
shader. The entry point function must also return an output structure
instance, which is used to output the manipulated vertex from our
shader.
VS_OUTPUT Main(VS_INPUT input)
{
Note: In actuality, it isn't mandatory to use input and output struc-
tures. For example, you will sometimes see syntax similar to the
following used, particularly with pixel shaders:
float4 Main(in float2 base : TEXCOORD0,
in float2 spot : TEXCOORD1,
in float2 text : TEXCOORD2) : COLOR
{
Search WWH ::




Custom Search