Jump to content
  • Advertisement
Sign in to follow this  
normalperson

Remove Perspective Transformation

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!