Matrix transformations

This topic is 2531 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hello,

I am learning about advanced transformations and i am trying to understand, how can i use inversed matrices.

My questions are:
Let's say, i have WorldViewProj matrix and i would like to get World matrix. when i multiplay it with Inversed ViewProj, i get World matrix back ?
if yes, i would like to learn, how can i transform a 3D position from space to space.

Let's say, i have a camera space and light space. I would like to transform a point from camera space to lightspace .. so

i will multiply Camera_WorldViewProj matrix with Camera_InverseViewProj and result, i will multiply it with Light_ViewProj, is it ok ?
Is there a faster way, how can i transform it with less multiplications ?

What happend, if i multiply Camera_WorldViewProj with Light_InverseViewProj ?

thank you very much it will help me to understand, how these transformations work. if you know any book with these transformation, i would like to read it

Share on other sites

Let's say, i have WorldViewProj matrix and i would like to get World matrix. when i multiplay it with Inversed ViewProj, i get World matrix back ?

Given is M composed from W, V and P as (using row vectors for demonstration here)
M := W * V * P
then expanding both sides with the inverse of ViewProj
M * ( V * P )[sup]-1[/sup] = W * V * P * ( V * P )[sup]-1[/sup]
= W * V * P * P[sup]-1[/sup] * V[sup]-1[/sup]
= W
Hence: Yes.

But notice the side at which the inverse is multiplied: On the right of M and W * V * P, resp. If you chose the wrong side, then you get
( V * P )[sup]-1[/sup] * M = ( V * P )[sup]-1[/sup] * W * V * P
and this isn't what you want, because W cannot be isolated this way; the matrix product isn't commutative!

if yes, i would like to learn, how can i transform a 3D position from space to space.

Any transformation can be understood as transforming a vector (be it a point of direction) into another space. The result is again a point or direction vector, resp., and hence can be transformed by another matrix. And so on ... Hence any composed transformation also transforms a vector into another space as well. You simply have to ensure that you use a transformation from and into the correct spaces. E.g. don't transform a vector given in space A by a matrix that is given to transform from space B into space C (or even A)!

Let's say, i have a camera space and light space. I would like to transform a point from camera space to lightspace .. so

i will multiply Camera_WorldViewProj matrix with Camera_InverseViewProj and result, i will multiply it with Light_ViewProj, is it ok ?
Is there a faster way, how can i transform it with less multiplications ?

You need to transform up into the "lowest common space". E.g. if you want to transform from model space into view space with W being the model's world matrix, and the view space is defined by a camera in world space with C being the camera's world matrix, then the world space is a common space. Hence model -> world -> view would be appropriate (again using row vectors for demonstration):
W * C[sup]-1[/sup] = W * V

The same with a light: If the light's world matrix is L, then
W * L[sup]-1[/sup]
would transform from model space into light space.

Of course, you may jump first into view and projection space, but because of
W * V * P * P[sup]-1[/sup] * V[sup]-1[/sup] * L[sup]-1[/sup] = W * L[sup]-1[/sup]
you would end up in the same.

However, if your light space is something other than the light local space w.r.t. the world space, then other rules may count.

What happend, if i multiply Camera_WorldViewProj with Light_InverseViewProj ?

Don't know exactly what you mean here. But perhaps the above explanations already give you an answer?!

Share on other sites
Hello, thank you for a nice tutorial, i have few questions.

first part answered my question, but there is something unclear to me.

M * ( V * P )[sup]-1[/sup] = W * V * P * ( V * P )[sup]-1[/sup]
= W * V * P * P[sup]-1[/sup] * V[sup]-1[/sup]
= W

It seems from this equadration, that ( V * P )[sup]-1 [/sup]= P[sup]-1[/sup] * V[sup]-1[/sup], it is right ?
Otherwise, i understand to this part.

So let's say, i would like to reconstruct a 3D point from camera depth map. I know XYZ of the pixel and i know, this pixel is transformed W * V[sub]c[/sub] * P[sub]c [/sub]
I would like to transform this 3D point and find it on light depth map.

So, what should i do ? Can i make a float4 ( x, y, z, 1.0 ) and multiply it with P[sub]C[/sub][sup]-1[/sup] * V[sub]c[/sub][sup]-1[/sup] * V[sub]L[/sub] * P[sub]L[/sub] ?

if this is correct, it's about my last question, how can i calculate it with less multiplying

thank you

Share on other sites

M * ( V * P )[sup]-1[/sup] = W * V * P * ( V * P )[sup]-1[/sup]
= W * V * P * P[sup]-1[/sup] * V[sup]-1[/sup]
= W

It seems from this equadration, that ( V * P )[sup]-1 [/sup]= P[sup]-1[/sup] * V[sup]-1[/sup], it is right ?

Yes.

So let's say, i would like to reconstruct a 3D point from camera depth map. I know XYZ of the pixel and i know, this pixel is transformed W * V[sub]c[/sub] * P[sub]c [/sub]
I would like to transform this 3D point and find it on light depth map.

So, what should i do ? Can i make a float4 ( x, y, z, 1.0 ) and multiply it with P[sub]C[/sub][sup]-1[/sup] * V[sub]c[/sub][sup]-1[/sup] * V[sub]L[/sub] * P[sub]L[/sub] ?

Well, may be. The problem here is that it is unclear to me what the point q := [ x y z 1 ] and the matrices exactly mean.

If you perform the first multiplication q * P[sub]C[/sub][sup]-1[/sup] then you transform q from device space into view space. A perspective projection matrix has a structure that gives you a projected point as
[ f[sub]x[/sub](x) f[sub]y[/sub](y) f[sub]z[/sub](z) f[sub]w[/sub](z) ]

for a point [ x y z 1 ] given in view space, where especially f[sub]w[/sub](z) != 1 (and != 0, of course). The foreshortening comes then from normalizing that projected point
[ f[sub]x[/sub](x)/f[sub]w[/sub](z) f[sub]y[/sub](y)/f[sub]w[/sub](z) f[sub]z[/sub](z)/f[sub]w[/sub](z) 1 ]
Notice that this is not part of a matrix product. Have you considered this issue (i.e. in its inverse form) when you determine q?

Assuming that q is okay, then
q * P[sub]C[/sub][sup]-1[/sup] * V[sub]C[/sub][sup]-1[/sup]
will probably transform from device space into view space into world space, assuming that P[sub]C[/sub] denotes the projection matrix (of the camera) and V[sub]C[/sub][sup]-1[/sup] the view matrix (of the camera), in other words V[sub]C[/sub] is the placement of the camera in the world.

From here on, you multiply with V[sub]L[/sub]. Well, I'd normally assume that V[sub]L[/sub] is the view matrix of the light, in other words the inverse of the placement of the light in the world. If so then all is fine, because the current q is given in world space and V[sub]L[/sub] would transform from world space into light's local space. Otherwise, i.e. if V[sub]L[/sub] is the placement of the light in the world, you have to use its inverse here.

Last you multiply with P[sub]L[/sub], probably a kind of projection matrix for the light. Its purpose is to transform from light's local space into light's projection space, and that is probably fine; perhaps you need to consider point normalization here, too. The purpose is usually to treat all lights as directed lights in some kind of shadow map computation. However, whether this is what you need is out of my scope.

if this is correct, it's about my last question, how can i calculate it with less multiplying

The only possibility I'm aware of is that, as long as all participating matrices are constant, you can compose parts of the formula once and reuse it for the same light and several points. I.e.
K := P[sub]C[/sub][sup]-1[/sup] * V[sub]C[/sub][sup]-1[/sup]
is constant for the camera in a given frame and for any point q. Furthermore,
L[sub]i[/sub] := V[sub]L[/sub] * P[sub]L[/sub]
is constant for a given light source and any point q. Hence you have to compute K once, and L[sub]i[/sub] as well as K * L[sub]i[/sub] once for every light used herein, and finally
q * K * L[sub]i[/sub]
once for every point of interest (here each "once" means per frame).

1. 1
Rutin
24
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 38
• 23
• 13
• 13
• 17
• Forum Statistics

• Total Topics
631712
• Total Posts
3001850
×