Game Development Reference
In-Depth Information
VS_OUTPUT output = (VS_OUTPUT)0;
// transform to view space and project
output.position = mul(input.position, ViewProjMatrix);
// set vertex diffuse color to blue
output.diffuse = Blue;
//Output the projected and colored vertex.
return output;
}
16.1.1 Globals
First we instantiate two global variables:
matrix ViewProjMatrix;
vector Blue = {0.0f, 0.0f, 1.0f, 1.0f};
The first variable, ViewProjMatrix , is of the type matrix , which is a
4 4 matrix type that is built into the HLSL. This variable stores a
combined view and projection matrix, such that it describes both trans-
formations. This way we only have to do one vector-matrix multiplica-
tion instead of two. Notice that nowhere in the shader source code do
we initialize this variable. That is because we set it through the applica-
tion source codeā€”not the shader. Communication from the application
to the shader program is a frequently required operation and is
explained in section 16.2.1.
The second variable, Blue , is of the built-in type vector , which is
a 4D vector. We simply initialize its components to the color blue, treat-
ing it as an RGBA color vector.
16.1.2 Input and Output Structures
After the global variables are declared, we define two special struc-
tures, which we call the input and output structures. For vertex
shaders, these structures define the vertex data that our shader inputs
and outputs, respectively.
struct VS_INPUT
{
vector position : POSITION;
};
struct VS_OUTPUT
{
vector position : POSITION;
vector diffuse : COLOR;
};
Note:
The input and output structures for pixel shaders define pixel
data.
Search WWH ::




Custom Search