Game Development Reference
In-Depth Information
struct SInputData
{
float4 position : POSITION;
float4 color : COLOR0;
float2 texCoord : TEXCOORD0;
};
struct SVertexData
{
float4 position : SV_Position;
float4 color : COLOR0;
float2 texCoord : TEXCOORD0;
};
SVertexData vs_default( SInputData input )
{
SVertexData output;
output.position = mul(projection, mul(view, mul(world, input.position)));
output.texCoord = input.texCoord;
output.color = input.color;
return output;
};
The first part defines the values that we will expect to be set into the constant registers of
the graphics hardware, this is done on the CPU side just prior to rendering, in this case we
expect that a valid view, projection and world matrix will be provided, each as a block of
4x4 float matrices. Different hardware and different hardware versions will have varying
limitations on the number of constant registers available.
The next part defines a structure, SInputData , this structure holds the layout of the geo-
metry's data as it will be sent from the CPU to the graphics device, this structure must
match the structure of the vertex data used to create the geometry.
Thenextstructurethatwedefine SVertexData istheoutputdatasentfromthevertexshader
to the pixel shader, whatever operations the vertex shader performs, the results will be
stored in this structure and later on it will be used as the input parameter for the pixel
shader.
Finally, the vertex shader program itself, this simple shader computes the projection/view/
world transform and then transforms the input world-space position into screen space.
float4x4 wvp = mul(projection, mul(view, world));
output.position = mul(wvp, input.position);
The operation being done is the following, given the vertex's position p
The screen-space position will be given by:
Search WWH ::




Custom Search