Game Development Reference
In-Depth Information
'
reason, you
ll know about it here. The vertex shader is then created with a call to
ID3D11Device::CreateVertexShader() .
Next, the vertex input layout is defined and set for the shader. Recall the definition
for VS_INPUT in the vertex shader? That input structure needs a layout definition,
which is defined as follows:
// Create our vertex input layout
const D3D11_INPUT_ELEMENT_DESC D3D11VertexLayout_UnlitTextured[] =
{
{ “POSITION”, 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,
D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ “NORMAL”, 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12,
D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ “TEXCOORD”, 0, DXGI_FORMAT_R32G32_FLOAT,
0, 24,
D3D11_INPUT_PER_VERTEX_DATA, 0 },
};
This is the data structure sent into ID3D11Device::CreateInputLayout () , and
is an array of D3D11_INPUT_ELEMENT_DESC structures. For each member, it defines
a single element of each vertex. The first member of the D3D11_INPUT_ ELEMENT_
DESC structure is the SemanticName , which the vertex shader will use to access the
data. The next member, SemanticIndex , enables you to send in more than one
value with the same SemanticName , as you might do if there were multiple texture
coordinates for each vertex. The next member, Format , is a value from the DXGI_
FORMAT enum defined in Direct3D, which has 115 different members. The values
chosen for our vertex format define 3D, 32-bit floating-point vectors for the position
and normal data, and a 2D 32-bit floating-point vector for the texture data. The
fourth member defines the input slot, which for this simple example with only one
vertex buffer is set to zero. If your shader accepted more than one vertex buffer,
you
d set the input slot to match which vertex buffer the shader should read from.
The fifth member defines the AlignedByteOffset , which you always set to the
byte offset of the data member. The last two members, set to their defaults for this
simple example, are used when a vertex shader can draw instances of the same object
in multiple positions by using additional transformation matrices.
With the input layout defined, it is sent into the ID3D11Device::CreateInput-
Layout() method, which results in the initialization of the m_pVertexLayout11
member of our class. With all that homework complete, the pVertexShaderBuffer
is no longer needed, so it is released.
The next block of code in this shader setup routine creates the data structure that
maps to the cbuffer cbPerObject structure in the vertex shader that holds the
'
Search WWH ::




Custom Search