Animation & normals

Started by
6 comments, last by RichardGe 12 years, 2 months ago
Hi everyone,

Question concerning animation:

in a lot of samples (even in the official sample "Local Deformable PRT" of the SDK of DX ), I see something like that for animation in vertex shader:



struct VS_INPUT {
float4 Position : POSITION;
float3 Normal : NORMAL;
float3 Tangent : TANGENT;
float4 BlendWeights : BLENDWEIGHT;
float4 BlendIndices : BLENDINDICES;
.....
};

VertexShader
{
....
for (i = 0; i < 4; ++i)
{
blendPos += float4( mul( boneMatrix[blendIdx] , position).xyz, 1.0) * blendWgt;
normal += mul( (float3x3)boneMatrix[blendIdx] , normal) * blendWgt;
.......

}
......
}


My question is about the normal transformation:
I have studied boneMatrix[], and I found that all matrices of this array aren't always orthogonal (certainly because of not uniform scaling).
So they should transform the normal with the transpose of the inverse of the matrix.

Why in every samples (that use BLENDWEIGHT/BLENDINDICES) that I found, nobody use the inverse of transpose for the normal/tangent transformation?

My theory is that it's a big cost to compute/transfert/stock all the inverse matrices, so it's better to have a normal slightly false rather than an exact normal but a lower FPS.
Is my theory true? or am I missing something?

Thanks!
Have a great day!Richard Geslot, 3D game developermy 3D creation
Advertisement

My theory is that it's a big cost to compute/transfert/stock all the inverse matrices, so it's better to have a normal slightly false rather than an exact normal but a lower FPS.
Is my theory true? or am I missing something?


Almost, but not quite. If there is no scaling in the matrix, the inverse transpose, is the same as the original matrix. Scaling also introduces a number of additional complexities when computing the world space bone matrices (correcting for negative scale etc). This tends to make the code a lot more complex, which makes everything run just a bit slower.... Most people therefore disallow scaling in their animation systems as a result.
Thanks, actually, I made a small mistake:


[...] and I found that all matrices of this array aren't always orthogonal [...]

I was wrong: most samples that I found used only orthogonal matrices, so: no need to inverse&transpose!

One last thing about orthogonal matrices that I discovered during my research (maybe that will help someone... one day...):
In some articles I read that a matrix that contains a uniform scaling is orthogonal (and when we transform a vector, there is no need to inverse&transpose). This is false: the uniform scaling matrix isn't orthogonal!
BUT it's almost true: actually, if and only if, we don't care the norm of the vector because we normalize the vector just after the transformation (so in 99% of cases):
in this case, even if the matrix contains a uniform scaling (so isn't orthogonal), we don't need to inverse&transpose.
This isn't true for non-uniform scaling matrices.
Have a great day!Richard Geslot, 3D game developermy 3D creation

One last thing about orthogonal matrices that I discovered during my research (maybe that will help someone... one day...):
In some articles I read that a matrix that contains a uniform scaling is orthogonal (and when we transform a vector, there is no need to inverse&transpose). This is false: the uniform scaling matrix isn't orthogonal!

A uniform scaling matrix is orthogonal, but it's not orthonormal though. If the matrix is orthonormal, the inverse-transpose is the same as the original. That is not the case for orthogonal matrices.


BUT it's almost true: actually, if and only if, we don't care the norm of the vector because we normalize the vector just after the transformation (so in 99% of cases):
in this case, even if the matrix contains a uniform scaling (so isn't orthogonal), we don't need to inverse&transpose.
This isn't true for non-uniform scaling matrices.

Almost true != true.

You've replaced the inverse transpose with a vector normalisation, which works in this case. You are still multiplying the vector by the inverse transpose, you're just doing it in a slightly different way....

A uniform scaling matrix is orthogonal,


I'm not sure.
I hope the Wikipedia article isn't false:
http://en.wikipedia....thogonal_matrix
"a matrix Q is orthogonal if its transpose is equal to its inverse"

if I take a uniform scaling matrix:

s 0 0 0
0 s 0 0
0 0 s 0
0 0 0 1

the transpose is the same.

But the inverse is


1/s 0....0....0
0...1/s...0....0
0....0...1/s...0
0....0....0.....1

So I conclude that a uniform scaling matrix is not orthogonal ?
Have a great day!Richard Geslot, 3D game developermy 3D creation
The upper left 3x3 section of a uniform scaling matrix should always be orthogonal
However, that doesnt mean that the columns are unit length. the only such matrix is the identity matrix
1 0 0
0 1 0
0 0 1
all columns are unit length and orthogonal to each other
In the field of mathematics, the formal definitions are as follows:
orthogonal matrix: A matrix which has orthonormal column (and hence) row vectors. It is a property of orthogonal matrices that their inverse equals the transpose.
orthonormal matrix: There is no such thing.

The reason for the above definition is perhaps historical, and perhaps due to that matrices with orthogonal (but not necessarily normalized) column/row vectors do not have nice properties to be worth much for mathematicians in linear algebra, and the above definition stuck.

The 3D games programmers definition:
orthogonal matrix: A matrix which has orthogonal column (if you are a Matrix*vector guy) or row (if you are a vector*Matrix guy) vectors, but not necessarily normalized.
orthonormal matrix: A matrix which has orthonormal column (and hence row) vectors.

Note that if a matrix has orthogonal (but not normalized) column vectors, it does not follow that its row vectors would also be normalized (and vice versa).

One thing that both mathematicians and 3D programmers do agree are the definitions of a set of orthogonal vectors (a collection of vectors which are all perpendicular to each other), and a set of orthonormal vectors (a collection of vectors which are all normalized and perpendicular to each other).

The above ill-logical definitions are discussed in both books Geometric Tools for Computer Graphics and Mathematics for 3D Game Programming and Computer Graphics. As a programmer, I definitely prefer the programmers' definitions, and that is what I use in my MathGeoLib library (find the link in my signature).
Thanks clb!
Now, I understand the previous disagreements!
Have a great day!Richard Geslot, 3D game developermy 3D creation

This topic is closed to new replies.

Advertisement