Jump to content
• Advertisement

# Problems about Perspective Projection

This topic is 4531 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

1.In Perspective Projection Matrix,the Z's interpolation is different from the X and Y's,it's said that the depth needs to be linear interpolated. (perspective correct interpolation) But I think the perspective correct interpolation problem occurs only when the raster happens, why is it used in Perspective Projection Matrix? 2.After projection,I get a unit cubic,how can I get the 2D image which I want to put it on the screen? I suppose that a scan line form a ray from view point to every pixel in my window,check where the ray intersects the unit cubic,then calculates its color,..., and in the end draw the pixel on the screen. Is it right? I want to study the pipeline carefully. Is it usefull if I writing a soft render? Can you introduce me some Soft Render to study? Thanks!

#### Share this post

##### Share on other sites
Advertisement
Quote:
 Original post by DingOunan20061.In Perspective Projection Matrix,the Z's interpolation is different from the X and Y's,it's said that the depth needs to be linear interpolated. (perspective correct interpolation) But I think the perspective correct interpolation problem occurs only when the raster happens, why is it used in Perspective Projection Matrix?

Your perspective projection matrix does not do any interpolation. It simply maps x,y,z to x',y',z'. It converts your view frustum to the unit cube (or -1 to 1 cube, whatever). The interpolation happens in the rasterizer when you are drawing the scanlines of your triangles. You mention an "interpolation problem", what is it?

Quote:
 2.After projection,I get a unit cubic,how can I get the 2D image which I want to put it on the screen? I suppose that a scan line form a ray from view point to every pixel in my window,check where the ray intersects the unit cubic,then calculates its color,..., and in the end draw the pixel on the screen. Is it right?

Your unit brick is the 2D image. Imagine all the z-values were the same (flatten it), and that is your screen. The Z-values are only used in the depth buffer.

Quote:
 I want to study the pipeline carefully. Is it usefull if I writing a soft render?Can you introduce me some Soft Render to study?Thanks!

If I still had my old projects, I'd be glad to. Unfortunately, I formatted my harddrive and only saved a link to the code directories (instead of the directories themselves). Although I did successfully save all my porn. True story. If I had to pick one or the other... I dunno.

Anyways, hope I could help.

#### Share this post

##### Share on other sites
The Z elements in the Perspective Projection Matrix is Calculated in this way:

Z' is a linear function of 1/Z,
for example: Z'=A/Z+B ------------------(1)

Because OpenGL needs the cubic's Depth Value falls in [-1,1]

assume that n: near plane, f: far plane
so I can rewrite (1):
1=-A/f+B and -1=-A/n+B
solve A and B:
A=2nf/(f-n) and B=(f+n)/f-n)

now the (1) is
Z'=-2nf/(f-n)(-1/Z)+(f+n)/(f-n)

then I can get the Z elements in the Perspective Projection Matrix

My Problem is: why Z' is 1/Z 's linear function?
Is it used for Perspective Correct Interpolation?

#### Share this post

##### Share on other sites
Quote:
 Original post by DingOunan2006The Z elements in the Perspective Projection Matrix is Calculated in this way:Z' is a linear function of 1/Z,for example: Z'=A/Z+B ------------------(1)Because OpenGL needs the cubic's Depth Value falls in [-1,1]assume that n: near plane, f: far planeso I can rewrite (1): 1=-A/f+B and -1=-A/n+Bsolve A and B: A=2nf/(f-n) and B=(f+n)/f-n)now the (1) is Z'=-2nf/(f-n)(-1/Z)+(f+n)/(f-n)then I can get the Z elements in the Perspective Projection MatrixMy Problem is: why Z' is 1/Z 's linear function?Is it used for Perspective Correct Interpolation?

I haven't implemented hyperbolic interpolation before. I thought that it used the W coordinate for perspective correction. I don't think Z is used for that at all because Z should be linearly interpolated during the rendering of a straight-edged polygon.

Maybe I don't understand your question too well. This may help answer it:
http://www.opengl.org/resources/code/samples/sig99/advanced99/notes/node28.html

I know what you mean in terms of the Z buffer having trouble with depth fighting. It does not map the z-values linearly, thus, moving your near clip plane away from the camera is much more effective than moving your far clip plane closer to the camera.

I think the reason this happens, is that the perspective projection matrix needs to map z = nearclip to -1 and z = farclip to 1. Once that is complete the job is done. I don't think there is an implementation of the matrix that linearly maps your z-values.

You only need to be concerned with what z-value you get... correcting z-fighting is up to the caller of the API. And perspective correct texturing uses the W coordinate. Do a search for hyperbolic interpolation if you want to know how all that is done.

2*zn/w.... 0.... 0.... 0
0.... 2*zn/h.... 0.... 0
0.... 0.... zf/(zf-zn).... 1
0.... 0.... zn*zf/(zn-zf).... 0

Laters.

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
Rutin
49
2. 2
3. 3
4. 4
5. 5
• Advertisement

• 10
• 28
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633410
• Total Posts
3011723
• ### Who's Online (See full list)

There are no registered users currently online

×

## 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!