Remove Perspective Transformation

Started by
9 comments, last by Zipster 18 years ago
Hi math lords, this is my first post. I have a question about how to remove perspective transformations from a set of vertices. This is what I am doing with directx * Create a vertex buffer of a simple cube. * Apply a perspective matrix to the dx device with a fov of whatever, lets say 45 deg. * Process the vertices with device->ProcessVertices. This returns a buffer of verts that have been transformed with the worldviewperspective thing. !!The above steps cannot be altered to solve this problem. What steps do I need to take to remove only the perspective transformations from the new set of vertices? The verts would only retain the world and view transforms in model space. I think this is the right place (Math and Physics) to ask this one. normalperson
Advertisement
What information do you have? If you have the perspective transformation matrix, then you can just multiply all the vertices by its inverse to get them into regular view space. Otherwise, you'd need at least the field-of-view, aspect ratio, and near and far plane distances to build the inverse perspective transform from scratch. If you're lucky enough to have the vertices in homogeneous coordinates (W value hasn't been divided out yet), then you'll only need the field-of-view and aspect ratio. This is all assuming a DX-/OGL-style perspective transformation.
Quote:What information do you have?
I have the original perspective matrix. It seems like I tried the inverse of it and didn't have any luck. I'll try it again. Thanks. I'll post back with the results.
Mathematically, the answer is simple. Given
    v = the point in model space    v' = the point in clip space    W = model-to-world transform    V = world-to-view transform    P = view-to-clip transform 
then
    v' = PVWv 
and
    v = W-1V-1P-1v' 
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Thanks but let's just assume that I have only the original perspective matrix or an identical one.

I am having strange results. The cube points are transformed by the perspective. I create the inverse of the perspective matrix (D3DXMatrixInverse) and transform each vert with it (D3DXVec3Transform).

The final rendered model is flat as though all verts are smashed on a plane.

Any ideas?
ProcessVertices() produces 2D screen-space coordinates, not clip-space coordinates.
So I'm not simply trying to remove the perspective transformations. According to the sdk docs ProcessVertices calculates screen coordinates in this order

* Transform vertices to projection space using the world + view + projection matrix.
* Compute screen coordinates using viewport settings.

Is there a way to convert the screen coordinates back to projection space so that I can then remove the perspective transformations?

In short I'd like to convert the data from ProcessVertices back to a non-warped model.

Sorry for the confusion.
I'm not familiar with ProcessVertices(), but if all you have are 2D coordinates, there's no going back. If you try, then you'll get, as you experienced, a flat plane.
Quote:I'm not familiar with ProcessVertices(), but if all you have are 2D coordinates, there's no going back. If you try, then you'll get, as you experienced, a flat plane.
I don't fully understand ProcessVertices() myself. I do not get back 2D screen space coords - I get back 3D coords. And together they make a slightly warped version of my original cube which is translated slightly, probably because of the camera position. It seems like the 3D coords are in projection space. When I apply the inverse projection I get a flattened version of the warped 3D cube. Nuts!

I could manually transform the cube into projection space and compare the results. I'll also start a thread tomorrow in the directx forums to find out exactly what ProcessVertices() is doing.
Projection matrices are non-invertible ... by definition. You cannot "undo" a projection unless you provide, somehow, the information that got lost in the process. No amount of mathematical massaging of the data will let you retrieve it from the projected data: it has to come from somewhere else.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement