Graphics Reference
In-Depth Information
As we can see in Listing 8.3, the input position is calculated by transforming the ob-
ject space position for each of the bones specified in the vertex's bone ID attribute, and the
resulting position is scaled by the bone weighting value from the vertex's bone weight attri-
bute. The normal vector is transformed in a similar manner, except with the inverse trans-
pose of the transformation matrix. Finally, the four weighted results are added together to
find the final world space position and normal vector. The world space position can then be
transformed into clip space with the ViewProjMatrix parameter, and the remainder of the
vertex shader is the same as in the static mesh rendering case.
This implementation provides a few additional indicators of how the various parts of
the rendering pipeline are typically applied to particular aspects of a model's appearance.
For example, we modified how the geometry of a model is calculated, which required
only a change to the vertex shader. The remainder of the pipeline configuration (other
than the input layout) is the same. This is often the case when the geometric properties of
a model are determined in the earlier stages and the surface properties of the geometry are
determined in the later stages. With this separation of duties, we can use individual shader
programs for more than one pipeline configuration, when it is appropriate. This reduces the
number of different shader programs that need to be written. It is a good idea to keep this
in mind when developing a new algorithm, since a shader program that is already written
is much faster to develop than one written from scratch!
8.2.3 Conclusion
If we consider how vertex skinning operates, we can gain some insight into how the per-
formance of the algorithm will vary with different input models. If we take the static mesh
algorithm as our baseline for performance, then add vertex skinning, we must upload a
larger constant buffer (to hold the bone matrices), and must perform some additional math
on the vertex before it is passed out of the vertex shader. Since we are allowing four bones
per-vertex, our vertex shader is written to access and calculate one transformed position
for each bone, which is then weighted and summed to find the final location. Even if fewer
than four bones are used in each vertex (if some of the weights are equal to 0), they must
all still be calculated, regardless of if the resulting weighted position produces an all-zero
position that will not contribute to the output position. Therefore, the cost associated with
performing vertex skinning should be constant from vertex to vertex.
This also means that the algorithm's performance will scale with the number of ver-
tices included in the model. If a highly detailed geometry model is rendered, its corre-
sponding rendering cost will be proportionally higher than that of a less-detailed geometric
model. Depending on the overall pipeline configuration and the hardware that an applica-
tion is running on, this can limit the available model detail that can be used for a given
scene. In many cases this may not make any difference, but if geometry processing is
Search WWH ::




Custom Search