Graphics Reference
In-Depth Information
public PerArmature()
{
Bones = new Matrix[MaxBones];
}
public static int Size()
{
return Utilities.SizeOf<Matrix>() * MaxBones;
}
}
11. Within the D3DApp.CreateDeviceDependentResources method, initialize a new
SharpDX.Direct3D11.Buffer field member as shown in the following screenshot.
We use the PerArmature.Size() method to determine the correct buffer size.
perArmatureBuffer = ToDispose(new Buffer(device,
ConstantBuffers.PerArmature.Size() , ResourceUsage.Default,
BindFlags.ConstantBuffer, CpuAccessFlags.None,
ResourceOptionFlags.None, 0));
12. Now assign the buffer to the fourth vertex shader constant buffer slot.
context.VertexShader.SetConstantBuffer(3,
perArmatureBuffer);
This completes the changes necessary to support vertex skinning in our vertex shader.
How it works…
In order to apply the bone influences on our vertices, we must be able to pass through the
bone indices and the weighting of the influence they have on the current vertex. For this
purpose, we will re-use the existing structure defined within Common.Mesh .
Our implementation supports up to four bone influences per vertex. This is not only the
maximum number supported by the CMO file format produced by Visual Studio, but the four
bone indices and weights fit conveniently within a HLSL uint4 and float4 as you can see
from the input layout we defined for the IA stage and the updated HLSL vertex structure.
As already discussed, the key component of skinning is the hierarchy of transformations
that is produced from the bones of an armature. These transformations or skin matrices are
implemented using the trusty old 4 x 4 affine transformation matrix. However, instead of
transforming from the local object space to world space as we have done previously,
we will be applying these transformations in bone space.
 
Search WWH ::




Custom Search