The Icabod Projection Matrix

Icabod has spent many an evening extolling the virtues of his alternative projection matrix to me and has since posted details about it on his blog. I can see the benefits it brings – intuitive parameters to a matrix that gives much more control to a camera system. I’ll leave it to Icabod to expand on that and explain why his matrix is an improvement over the traditional approaches to projections.

So without further ado here it is the Icabod Projection Matrix, albeit with stereoscopic eye separation omitted and in a somewhat cramped state;

A – The point being projected.
C – The resulting projection before hardware normalisation.
E – The eye position – traditionally this is the origin (ie; [0,0,0])
V – Centre of the viewport.
w – Viewport width.
h – Viewport height.
n – Near plane distance.
f – Far plane distance.
p – The amount of perspective [0,1] where 0 is a parallel projection.

With some help I set about working out how this matrix comes to be, and what follows is a summary of my “adventure”…

The X and Y rows

Both these rows serve the same purpose; to project Ax and Ay onto the eye plane and map that in to the interval [-1,1]. While the canonical perspective projection matrix takes into account the hardware divide-by-Cw here, Icabod disregards it here for reasons that will become clear when discussing the matrix’s W row. So, we’re simply dealing with a parallel projection like this;

Considering just the X row, firstly it projects A onto the eye plane. This involves finding t and subtract that from Ax. An additional term is also introduced to move A into eye-space. To find t we can use similar triangles and rearrange it so it’s matrix-friendly.

Finally the point needs to be mapped to [-1,1] such that left side of the viewport is -1 and the right side is 1;

This gives us the matrix’s X and Y rows;

The W row

The projection matrices we are most familiar with do little with this row, either passing through Az (perspective) or 1 (parallel). Icabod’s matrix uses the W row to scale the width of the viewport as A moves along the Z-axis (relying on the divide-by-Cw normalisation that the hardware does). A variable p has been added that controls the amount of scaling, allowing both parallel and perspective projection (or somewhere in between).

A solution for when p=1 that gives Cw=0 when Az=Ez and Cw=1 when Az=Vz is as follows;

A term p has been added into this equation so it remains unchanged when p=1 and evaluates to 1 when p=0;

Now we have the W row of Icabod’s projection matrix. Just one more row to go;

The Z row

No fancy diagrams here, just some simultaneous equations. After normalisation we expect Cz/Cw=-1 when Az=n and Cz/Cw=1 when Az=f. This gives us the following;

Two equations and two unknowns. We can solve for K and substitute in L and M from the W row (I have no idea why I’m doing K first);

This process can be repeated for J;

That gives the Z row of the matrix;

That’s it! Thanks for spotting my mistakes Will!

  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • LinkedIn
  • Reddit
  • Slashdot
This entry was posted in Maths, Rendering and tagged , , , . Bookmark the permalink.

Comments are closed.