# Remove Perspective Transformation

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

## Recommended Posts

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

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
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'

##### Share on other sites
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?

##### Share on other sites
ProcessVertices() produces 2D screen-space coordinates, not clip-space coordinates.

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
Quote:
 Original post by normalpersonI 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.

You won't be able to apply the inverse perspective matrix to a 3D point, so you have to make it 4D by adding a W component of 1.0. First convert X and Y from screen-space into clip-space, by dividing by the viewport width and height, and then inverting Y (Y = 1 - Y) since screen-space coordinates are inverted along the Y axis. After that, you should be able to apply the inverse perspective matrix and divide out the W to get a 3D point again, which should be in view space. That's assuming that the original 3D point maintained it's clip-space Z value. I just tested everything out on my end with a bunch of random points and a perspective transformation, and it worked.

##### Share on other sites

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