Graphics Reference
In-Depth Information
3.
Add an appropriate constructor to the
Vertex
structure. This allows us to initialize
the
Skin
property we had added previously.
4.
As always, after updating the vertex structure, we need to change the input
layout that is passed to the Input Assembler (IA) stage. Within the
D3DApp.
CreateDeviceDependentResources
method, change the definition of
the input layout to include the new vertex properties.
vertexLayout = ToDispose(new InputLayout(device,
vsBytecode.GetPart(ShaderBytecodePart.InputSignatureBlob),
new[]
{
new InputElement("SV_POSITION",0,Format.R32G32B32_Float,
0,0),
new InputElement("NORMAL", 0,
Format.R32G32B32_Float,12,0),
new InputElement("COLOR", 0, Format.R8G8B8A8_UNorm,
24,0),
new InputElement("TEXCOORD", 0, Format.R32G32_Float,
28,0),
// "SkinIndices"
new InputElement("BLENDINDICES", 0, Format.R32G32B32A32_UInt,
36, 0)
,
// "SkinWeights"
new InputElement("BLENDWEIGHT", 0, Format.R32G32B32A32_Float,
52, 0)
,
}));
5.
To complete our vertex structure changes, we need to update the vertex shader
and pixel shader inputs within
.\Shaders\Common.hlsl
.
6.
Change the
VertexShaderInput
structure to include the two new vertex properties.
uint4 SkinIndices : BLENDINDICES; // blend indices
float4 SkinWeights : BLENDWEIGHT; // blend weights
7. To store the list of bone influences (matrices) that will be used within the vertex
shader, we need to create a new constant buffer. This buffer will be updated
per armature
.
// Constant buffer to hold our skin matrices for each bone.
// Note: 1024*64 = max bytes for constant buffers in SM4/5
cbuffer PerArmature : register(b3)
{
float4x4 Bones[1024];
};
With our shader structures and constant buffers in place, we will update the vertex
shader in
\Shaders\VS.hlsl
to apply the vertex skinning.