The problem with 3D projection: the value of Z does not lie in [1, -1] after dividing the perspective

I am trying to make a simple perspective projection in the process of rasterizing a three-dimensional point. Here are all the matrices and other information. All matrices have a number of basic values. The coordinate system has the right.

The camera is at [0,0, -1], and the point is at [0,0,0] (w = 1 for matrix operations)

Model representation matrix (inverse cam matrix ie, tx = 0; ty = 0; tz = 1):

[1 0 0 tx] [0 1 0 ty] [0 0 1 tz] [0 0 0 1 ] 

Perspective Matrix:

 [f/aspect,0,0,0] 0,f,0,0 0,0,-(near+far)/(near-far),2*far*near/(near-far) 0,0,1,0] 
Aspect

equals 1 because the viewport is square. Far = 100 and Near = 0.1 f = 1 / tan (fovDegress * M_PI / 360);

Resulting Matrix:

 1.94445, 0, 0, 0 0, 1.944445, 0, 0 0, 0, 1.020202, -2.020202 0, 0, 1, 0 

Now I apply the model representation matrix, and then the projection matrix to the point vector, and then I get a new point Pv = {x, y, z, w} Then I get the normalized coordinates x '= x / w; y '= y / w; and z '= z / w; x 'and y' always lie between [-1,1] while the point is truncated. But the same is true for z '. As the point approaches the camera, z 'values โ€‹โ€‹increase exponentially. When the point is at [0,0,0], the value of z is -1.

Now I need to copy some lines, so I need the value of z to be between [1, -1]. I wonder what happened to my procedure. Thanks.

+4
source share
1 answer

What you experience is the non-linearity of the perspective display of depth. With the projection matrix of the truncated body, this follows the 1 / x law with distance from the point of view.

EDIT:

Just double check your matrices: you have the wrong matrix of a truncated contour. Regular truncated cone matrix

 f/aspect, 0, 0, 0 0, f, 0, 0 0, 0, -(far+near)/(far-near), 2*far*near/(far-near) 0, 0, 1, 0 

However, if you get closer to the origin, you will encounter division by zero. Just put the vector (0,0,0,1) through this thing, which results in (x = 0, y = 0, z = 2 * far * close / (far-close), w = 0) in the clip space, And then the homogeneous division {x, y, z} / (w = 0) โ† grows.

+2
source

All Articles