Problems about Perspective Projection

Started by
2 comments, last by blaze02 17 years, 10 months ago
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!
Advertisement
Quote:Original post by DingOunan2006
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?


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.
-------Harmotion - Free 1v1 top-down shooter!Double Jump StudiosBlog
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?

Quote:Original post by DingOunan2006
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?



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.
-------Harmotion - Free 1v1 top-down shooter!Double Jump StudiosBlog

This topic is closed to new replies.

Advertisement