Graphics Reference
In-Depth Information
To support the vertex skinning algorithm, our model im-
porter must support a different type of per-vertex information.
The new vertex format must include the information that speci-
fies which bone it is associated with, as well as what weighting
amount each bone should have on the outcome of the interpola-
tion. To accomplish this, each bone must be assigned an integer
index that can be used as an index into an array of matrices. We
will allow up to four bones to influence each vertex, which indi-
cates that we will need a four-component set of bone indices, as well
Figure 8.13. The vertex lay-
out for our vertex-skinning
implementation.
as a four-component set of bone weights. The updated vertex structure is shown in Figure 8.13. Of
course, with a new vertex structure a new input layout object must be generated as well.
To use the new vertex data, we must modify our vertex shader according to the algorithm
we specified in the theory section. The first step is to gain access to the transformation matrices
that the application provides. The matrices are made available to the vertex shader through a
constant buffer, and essentially replace the world transformation matrix portion of the concat-
enated transform from our previous example. This means that the will calculate the world-space
position of each vertex within the vertex shader, and then transform this resulting position by
the view and projection matrices that will be concatenated into a single matrix. In addition to the
bone transformation matrices, we also include the normal vector bone transformation matrices,
to produce a correct world-space skinned vertex-normal vector as well. The modified vertex
shader is shown in Listing 8.3.
cbuffer SkinningTransforms
{
matrix WorldMatrix;
matrix ViewProjMatrix;
matrix SkinMatrices[6];
matrix SkinNormalMatrices[6];
};
cbuffer LightParameters
{
float3 LightPositionWS;
float4 LightColor;
};
Texture2D ColorTexture : register( t0 );
SamplerState LinearSampler : register( s0 );
struct VS_INPUT
{
float3 position : POSITION;
int4 bone : BONEIDS;
float4 weights : BONEWEIGHTS;
float3 normal : NORMAL;
float2 tex
: TEXC00RDS;
};
 
Search WWH ::




Custom Search