# World, Bone and Normal Matrices

## Recommended Posts

jujumbura    209
Hello all,

I have been thinking for a while about the relationship between World, Bone and Normal matrices as they pertain to vertex processing. Assuming I have a mesh with position and normal data that needs to be transformed, it seems like I must do one of three things:

1) Send each matrix individually to the vertex shader, and have it transform the position and normal values multiple times. So the vertex shader would entail a multiplication of the position by the bone and then the world matrices, and a multiplication of the normal by the bone-normal and then the world-normal matrices.

2) Pre-multiply the matrices on the CPU so that the position and normal values only require a single transform. Then the vertex shader would only require a multiplication of the position by a combined matrix, and a multiplication of the normal by a combined matrix.

3) Some partial combination of 1) and 2).

So I'm wondering, is there some "tried and true" way of doing this or does it really just depend on my situation? If I am CPU bound and I am trying to draw lots of individually positioned meshes, then option 1) makes more sense. If I am GPU bound and I am trying to draw a few very complex meshes, then option 2) makes more sense. But I can't help wondering if there is some clever technique that tends to get the best of both worlds; this is surely something that has been tackled by many a graphics programmer.

##### Share on other sites
Zaoshi Kaba    8434
Pre-multiplying won't help GPU much, since it's only 4 operations to transform vertex, doing it on GPU won't help CPU much either, I doubt you have bizarre number of bones to make a difference. I'd just suggest to use whatever is more convenient.

##### Share on other sites
C0lumbo    4411
When you build your array of bone matrices, you're usually building them up with a hierarchical tree anyway, so it's probably convenient to put your world matrix at the root of the tree, and so you'll get rid of that more or less for free.

Also, often in human animation you wouldn't be using non-uniform scaling factors anyway, so you could use the same matrices for normals as you do for vertex positions (just disable the translation part in the vertex shader).