Why do we need perspective division?

后端 未结 4 1199
独厮守ぢ
独厮守ぢ 2021-02-04 10:33

I know perspective division is done by dividing x,y, and z by w, to get normalized device coordinates. But I am not able to understand the purpose of doing that. Also, does it h

相关标签:
4条回答
  • 2021-02-04 10:52

    I mean why do we need that?

    In layman terms: To make perspective distortion work. In a perspective projection matrix, the Z coordinate gets "mixed" into the W output component. So the smaller the value of the Z coordinate, i.e. the closer to the origin, the more things get scaled up, i.e. bigger on screen.

    0 讨论(0)
  • 2021-02-04 10:58

    To really distill it to the basic concept, and why the op is division (instead of e.g. square root or some such), consider that an object twice as far should appear with dimensions exactly one half as large. Obtain 1/2 from 2 by... division.

    There are many geometric ways to arrive at the same conclusion. A diagram serves as visual proof for this, really.

    0 讨论(0)
  • 2021-02-04 11:01

    Some details that complement the general answers:

    The idea is to project a point (x,y,z) on screen to have (xs,ys,d). The next figure shows this for the y coordinate.

    enter image description here

    We know from school that

    tan(alpha) = ys / d = y / z

    This means that the projection is computed as

    ys = d*y/z = y /w

    w = z / d

    This is enough to apply a projection. However in OpenGL, you want (xs,ys,zs) to be normalized device coordinates in [-1,1] and yes this has something to do with clipping.

    The extrema values for (xs,ys,zs) represent the unit cube and everything outside it will be clipped. So a projection matrix usually takes into consideration the clipping limits (Frustum) to make a single transformation that, with the perspective division, simultaneously apply a projection and transform the projected coordinates along with the z to normalized device coordinates.

    0 讨论(0)
  • 2021-02-04 11:08

    Actually, via standard notational convention from a 4x4 perspective matrix with sightline along a 'z' direction, 'w' differs by 1 from the distance ratio. Also that ratio, though interpreted correctly, is normally expressed as -z/d where 'z' is negative (therefore producing the correct ratio) because, again, in common notational convention, the camera is looking in the negative 'z' direction. The reason for the offset by 1 needs to be explained. Many references put the origin at the image plane rather than the center of projection. With that convention (again with the camera looking along the negative 'z' direction) the distance labeled 'z' in the similar triangles diagram is thereby replaced by (d-z). Then substituting that for 'z' the expression for 'w' becomes, instead of 'z/d', (d-z)/d = [1-z/d]. To some these conventions may seem unorthodox but they are quite popular among analysts.

    0 讨论(0)
提交回复
热议问题