Game Development Reference
In-Depth Information
...
}
The parameters are inputs into the shader; in this example we are
inputting three texture coordinates. The shader returns a single color
as output, which is denoted by the : COLOR syntax following the func-
tion signature. This definition is equivalent to:
struct INPUT
{
float2 base : TEXCOORD0;
float2 spot : TEXCOORD1;
float2 text : TEXCOORD2;
};
struct OUTPUT
{
float4 c : COLOR;
};
OUTPUT Main(INPUT input)
{
...
}
The body of the entry point function is responsible for computing the
output vertex given the input vertex. The shader in this example sim-
ply transforms the input vertex to view space and projection space, sets
the vertex color to blue, and returns the resulting vertex. First we
instantiate a VS_OUTPUT instance and set all of its members to 0.
VS_OUTPUT output = (VS_OUTPUT)0; // zero out all members
Then our shader transforms the input vertex position by the
ViewProjMatrix variable using the mul function, which is a built-in
function that can do both vector-matrix multiplication and matrix-
matrix multiplication. We save the resulting transformed vector in the
position member of the output instance:
// transform and project
output.position = mul(input.position, ViewProjMatrix);
Next we set the diffuse color member of output to Blue :
// set vertex diffuse color to blue
output.diffuse = Blue;
Finally, we return our resulting vertex:
return output;
}
Team-Fly ®
Search WWH ::




Custom Search