wh1sp3rik 248 Report post Posted August 11, 2011 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 0 Share this post Link to post Share on other sites
haegarr 7372 Report post Posted August 11, 2011 [quote name='wh1sp3rik' timestamp='1313083703' post='4847779'] 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 ? [/quote] Given is [b]M[/b] composed from [b]W[/b], [b]V[/b] and [b]P[/b] as (using row vectors for demonstration here) [b]M[/b] := [b]W[/b] * [b]V[/b] * [b]P[/b] then expanding both sides with the inverse of ViewProj [b]M[/b] * ( [b]V[/b] * [b]P[/b] )[sup]-1[/sup] = [b]W[/b] * [b]V[/b] * [b]P[/b] * ( [b]V[/b] * [b]P[/b] )[sup]-1[/sup] = [b]W[/b] * [b]V[/b] * [b]P[/b] * [b]P[/b][sup]-1[/sup] * [b]V[/b][sup]-1[/sup] = [b]W[/b] Hence: Yes. But notice the side at which the inverse is multiplied: On the right of [b]M[/b] and [b]W[/b] * [b]V[/b] * [b]P[/b], resp. If you chose the wrong side, then you get ( [b]V[/b] * [b]P[/b] )[sup]-1[/sup] *[b] M[/b] = ( [b]V[/b] * [b]P[/b] )[sup]-1[/sup] * [b]W[/b] * [b]V[/b] * [b]P[/b] and this isn't what you want, because [b]W[/b] cannot be isolated this way; the matrix product isn't commutative! [quote name='wh1sp3rik' timestamp='1313083703' post='4847779'] if yes, i would like to learn, how can i transform a 3D position from space to space. [/quote] 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)! [quote name='wh1sp3rik' timestamp='1313083703' post='4847779'] 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 ? [/quote] You need to transform up into the "lowest common space". E.g. if you want to transform from model space into view space with [b]W[/b] being the model's world matrix, and the view space is defined by a camera in world space with [b]C[/b] 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): [b]W[/b] * [b]C[/b][sup]-1[/sup] = [b]W[/b] * [b]V[/b] The same with a light: If the light's world matrix is L, then [b]W[/b] * [b]L[/b][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 [b]W[/b] * [b]V[/b] * [b]P[/b] * [b]P[/b][sup]-1[/sup] * [b]V[/b][sup]-1[/sup] * [b]L[/b][sup]-1[/sup] = [b]W[/b] * [b]L[/b][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. [quote name='wh1sp3rik' timestamp='1313083703' post='4847779'] What happend, if i multiply Camera_WorldViewProj with Light_InverseViewProj ? [/quote] Don't know exactly what you mean here. But perhaps the above explanations already give you an answer?! 0 Share this post Link to post Share on other sites
wh1sp3rik 248 Report post Posted August 11, 2011 Hello, thank you for a nice tutorial, i have few questions. first part answered my question, but there is something unclear to me. [b]M[/b] * ( [b]V[/b] * [b]P[/b] )[sup][size="2"]-1[/size][/sup] = [b]W[/b] * [b]V[/b] * [b]P[/b] * ( [b]V[/b] * [b]P[/b] )[size="2"][sup]-1[/sup] [/size] = [b]W[/b] * [b]V[/b] * [b]P[/b] * [b]P[/b][sup][size="2"]-1[/size][/sup] * [b]V[/b][size="2"][sup]-1[/sup] [/size] = [b]W[/b] It seems from this equadration, that ( [b]V[/b] * [b]P[/b] )[size="2"][sup]-1 [/sup]= [b][size="2"]P[/size][/b][sup][size="2"]-1[/size][/sup][size="2"] * [/size][size="2"][b]V[/b][/size][size="2"][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 [b]W * V[sub]c[/sub] * P[sub]c [/sub] [/b]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 [b]P[sub]C[/sub][sup]-1[/sup][/b] * [b]V[sub]c[/sub][sup]-1[/sup] * V[sub]L[/sub] * P[sub]L[/sub][/b] ? if this is correct, it's about my last question, how can i calculate it with less multiplying thank you [/size] [/size] 0 Share this post Link to post Share on other sites
haegarr 7372 Report post Posted August 12, 2011 [quote name='wh1sp3rik' timestamp='1313093590' post='4847879'] [b]M[/b] * ( [b]V[/b] * [b]P[/b] )[sup][size="2"]-1[/size][/sup] = [b]W[/b] * [b]V[/b] * [b]P[/b] * ( [b]V[/b] * [b]P[/b] )[size="2"][sup]-1[/sup] [/size] = [b]W[/b] * [b]V[/b] * [b]P[/b] * [b]P[/b][sup][size="2"]-1[/size][/sup] * [b]V[/b][size="2"][sup]-1[/sup] [/size] = [b]W[/b] It seems from this equadration, that ( [b]V[/b] * [b]P[/b] )[size="2"][sup]-1 [/sup]= [b][size="2"]P[/size][/b][sup][size="2"]-1[/size][/sup][size="2"] * [/size][size="2"][b]V[/b][/size][size="2"][sup]-1[/sup], it is right ? [/size][/size] [size="2"][size="2"][/quote][/size][/size] [size="2"][size="2"]Yes.[/size][/size] [size="2"][size="2"] [size="3"][quote name='wh1sp3rik' timestamp='1313093590' post='4847879'] [/size]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 [b]W * V[sub]c[/sub] * P[sub]c [/sub] [/b]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 [b]P[sub]C[/sub][sup]-1[/sup][/b] * [b]V[sub]c[/sub][sup]-1[/sup] * V[sub]L[/sub] * P[sub]L[/sub][/b] ? [size="3"] [size="2"][size="2"][size="2"][size="2"][/quote][/size][/size][/size][/size] [size="2"][size="2"][size="2"][size="2"]Well, may be. The problem here is that it is unclear to me what the point [b]q[/b] := [ x y z 1 ] and the matrices[/size][/size][/size][/size][size="2"] exactly mean.[/size] [size="2"]If you perform the first multiplication [b]q[/b] * [/size][size="2"][b]P[sub]C[/sub][sup]-1[/sup][/b][/size][size="2"] then you transform [b]q[/b] from device space into view space. A perspective projection matrix has a structure that gives you a projected point as[/size] [size="2"][ f[sub]x[/sub](x) f[sub]y[/sub](y) f[sub]z[/sub](z) f[sub]w[/sub](z) ][/size] [size="2"][size="2"][size="2"][size="2"][size="3"] [size="2"]for a point [/size][size="2"][ x y z 1 ] given in view space, where especially [/size][size="2"]f[sub]w[/sub](z) != 1 (and != 0, of course). The foreshortening comes then from normalizing that projected point[/size][size="2"][size="3"] [size="2"][ f[sub]x[/sub](x)/[/size][size="2"]f[sub]w[/sub](z)[/size][size="2"] f[sub]y[/sub](y)/[/size][size="2"]f[sub]w[/sub](z)[/size][size="2"] f[sub]z[/sub](z)/[/size][size="2"]f[sub]w[/sub](z)[/size][size="2"] 1 ][/size][/size][/size][/size][/size][/size][/size][/size] [size="2"][size="2"][size="2"][size="2"]Notice that this is not part of a matrix product. Have you considered this issue (i.e. in its inverse form) when you determine [b]q[/b]?[/size][/size][/size][/size] [size="2"] [/size] [size="2"][size="2"][size="2"][size="2"]Assuming that [b]q[/b] is okay, then[/size][/size][/size][/size] [size="2"][size="2"][size="2"][size="2"][b]q[/b] * [/size][/size][/size][/size][size="2"][b]P[sub]C[/sub][sup]-1[/sup][/b] * [b]V[sub]C[/sub][sup]-1[/sup] [/b][/size] [size="3"][size="2"]will probably transform from device space into view space into world space, assuming that [b]P[/b][sub]C[/sub] denotes the projection matrix (of the camera) and [b]V[/b][sub]C[/sub][sup]-1[/sup] the view matrix (of the camera), in other words [b]V[/b][sub]C[/sub] is the placement of the camera in the world.[/size][/size] [size="3"][size="2"]From here on, you multiply with [b]V[/b][sub]L[/sub]. Well, I'd normally assume that [b]V[/b][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 [b]q[/b] is given in world space and [b]V[/b][sub]L[/sub] would transform from world space into light's local space. Otherwise, i.e. if [b]V[/b][sub]L[/sub] is the placement of the light in the world, you have to use its inverse here.[/size][/size] [size="3"][size="2"]Last you multiply with [b]P[/b][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.[/size][/size] [/size] [size="2"][size="2"][size="3"][quote name='wh1sp3rik' timestamp='1313093590' post='4847879'] [/size][/size][/size]if this is correct, it's about my last question, how can i calculate it with less multiplying [size="3"][/quote][/size] [/size][/size]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. [b]K[/b] := [size="2"][b]P[sub]C[/sub][sup]-1[/sup][/b] * [b]V[sub]C[/sub][sup]-1[/sup][/b][/size] is constant for the camera in a given frame and for any point [b]q[/b]. Furthermore, [b]L[/b][sub]i[/sub] := [size="2"][b]V[sub]L[/sub] * P[sub]L[/sub][/b] [/size] [size="2"]is constant for a given light source and any point [b]q[/b]. Hence you have to compute [b]K[/b] once, and [b]L[/b][sub]i[/sub] as well as [b]K[/b] * [b]L[/b][sub]i[/sub] once for every light used herein, and finally[/size] [size="2"][b]q[/b] * [b]K[/b] * [b]L[/b][sub]i[/sub][/size] [size="2"]once for every point of interest (here each "once" means per frame).[/size] 0 Share this post Link to post Share on other sites