View Full Version : 3x3 perspective projection matrix

myk45

09-17-2012, 05:29 AM

Hello All!

I was wondering if it is possible to construct a 3x3 perspective projection matrix? I searched for this, but could not find much help. I was able to find lots of information on 4x4 matrices. But, i just wanted to know if i somehow can do it using a 3x3 matrix. Also, i do not really want to preserve the Z values. So, it doesn't matter to me if A(x, y, z) and B(x1, y1, z1) are projected to the same value W(xWin, yWin).

Is it possible to do something like this?

Thanks in advance!

mhagain

09-17-2012, 05:54 AM

http://www.opengl.org/sdk/docs/man/xhtml/glFrustum.xml

All 4 rows and all 4 columns are used in a perspective projection.

You could construct a perspective projection on-the-fly in a shader (using the info on the glFrustum man page to calculate it), and only the 6 params to glFrustum would be needed to do so, but I'm having a hard time seeing any kind of use case where you'd actually want to do this.

myk45

09-17-2012, 06:03 AM

Hi mhagain,

I'm just curious to know if this is mathematically possible to use a 3x3 matrix. Also, in OpenGL, isn't the projection matrix generated invertible? I am not looking for an invertible matrix.

Thanks for the response :)

Alfonse Reinheart

09-17-2012, 07:50 AM

No, it is not. The perspective projection matrix generates 4D homogeneous coordinates. You cannot use a 3x3 matrix and generate a 4D vector from it.

myk45

09-17-2012, 08:04 AM

> No, it is not. The perspective projection matrix generates 4D homogeneous coordinates. You cannot use a 3x3 matrix and generate a 4D vector from it.

Hi Alfonse Reinheart,

Thanks for the reply. Well, i didn't want to obtain a 4D vector. I wanted to obtain a 2D vector. Just the window coordinates. Quoting myself:

But, i just wanted to know if i somehow can do it using a 3x3 matrix. Also, i do not really want to preserve the Z values. So, it doesn't matter to me if A(x, y, z) and B(x1, y1, z1) are projected to the same value W(xWin, yWin).

Thanks!

mhagain

09-17-2012, 08:56 AM

To the GPU a 2D vector ("just the window coordinates") is still a 4D vector - it's padded with [0,1] at the end; similarly 3D is padded with [1] at the end.

I'm not entirely certain why you feel you need to do this with a 3x3 matrix (which you can't anyway) - you may have some idea that you're going to "save memory" or "have less calculations" by doing so, but let me tell you right now - you're not. Your GPU will still use 4x4 internally anyway, so you may as well work with your GPU rather than against it.

Alfonse Reinheart

09-17-2012, 11:59 AM

Well, i didn't want to obtain a 4D vector. I wanted to obtain a 2D vector. Just the window coordinates.

You can't get to window coordinates without first passing through clip-space and normalized-device coordinates. Clip-space is 4D homogeneous, and NDC-space is 3D (the result of dividing the clip-space vector by its W component). You can't just pretend that these steps don't happen. And since perspective projection is a non-linear transform, it cannot be accomplished by a linear operation like a matrix multiply.

myk45

09-17-2012, 09:32 PM

Hi mhagain, Alfonse Reinheart,

Thanks for the replies. I think now its clear to me. We thus have two phases in the perspective projection:

1) Perspective transformation -> gets us to the clip space. and this is a linear operation.

2) Perspective divide -> this is the non-linear operation.

So, its not possible with a 3x3 matrix

Am i correct about this?

EDIT: in fact i had seen somewhere the use of a 3x3 matrix for perspective scaling/shearing. I assumed this is the same as perspective projection. Could you please tell me what exactly perspective scaling/shearing is?

Kopelrativ

09-18-2012, 04:53 AM

Shearing and scaling can be done with a 3x3 matrix. Also rotations, but not perspective scaling. The following matrix

a 0 0

0 b 0

0 0 c

will scale 'x' with a, 'y' with b and 'z' with c. Shearing is where, in the transformation process, one of the dimensions are added to one of the other (with a scale factor). See http://en.wikipedia.org/wiki/Shear_mapping for example.

Translation is a special case of this. The constant '1' in position 3,3 is added to 'x', 'y' or 'z' (scaled with a constant).

mhagain

09-18-2012, 08:34 AM

Should be added that you can easily take a 3x3 matrix and convert it to 4x4 - in the case above it's:

a 0 0 0

0 b 0 0

0 0 c 0

0 0 0 1

I.e. just pad each row and column with zeroes, with the exception of the very last entry, which is 1.

myk45

09-18-2012, 09:42 AM

Thanks for the replies Kopelrativ, mhagain.

@Kopelrativ:

> Shearing and scaling can be done with a 3x3 matrix. Also rotations, but not perspective scaling.

So, is perspective scaling same as perspective projection? I tried searching on google, but not much information is available on this topic.

PS: Kindly excuse me if this is too trivial a question to be asking. I would like to read more in depth about this. All books/links i refered just give a matrix that does the perspective projection. But i wanted to know how exactly this is derived and if there are other ways to do it. So, this is not for optimization or anything of that sort. Its just for learning more in detail about perspective projections in general.

Thanks!

Alfonse Reinheart

09-18-2012, 01:04 PM

So, is perspective scaling same as perspective projection?

He didn't say "perspective scaling"; he said scaling.

I would like to read more in depth about this. All books/links i refered just give a matrix that does the perspective projection.

*cough* (http://www.arcsynthesis.org/gltut/Positioning/Tut04%20Perspective%20Projection.html)

myk45

09-19-2012, 05:21 AM

> *cough* (http://www.arcsynthesis.org/gltut/Positioning/Tut04%20Perspective%20Projection.html)

haha! thanks :D

Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.