Why do we need perspective division?
Asked Answered
U

4

19

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 have anything to do with clipping?

Underlaid answered 24/6, 2013 at 7:0 Comment(4)
Perhaps you would be better off with that on Maths.se than here :) (IOW OpenGL is completely not related)Filament
scratchapixel.com/lessons/3d-advanced-lessons/…Rainwater
Possible duplicate of Understanding the Projection MatrixEarlie
Excellent question. Answers to questions regarding "why things work" are so important and I find are often neglected in favor of the how.Tallu
A
8

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.

Accuse answered 24/6, 2013 at 7:39 Comment(1)
In fact, the simplest perspective matrix you could possibly have just copies z into w, so that when perspective divide occurs x and y get smaller the further away from the camera they are. This video might help youtu.be/o1n02xKP138?t=994Slav
B
19

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.

Boylston answered 26/6, 2013 at 1:12 Comment(2)
Shouldn't w = d / z?Spector
@Spector No, y * d/z = y / w = y * (1/w), so 1/w = d/z, and then w = z / dLang
A
8

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.

Accuse answered 24/6, 2013 at 7:39 Comment(1)
In fact, the simplest perspective matrix you could possibly have just copies z into w, so that when perspective divide occurs x and y get smaller the further away from the camera they are. This video might help youtu.be/o1n02xKP138?t=994Slav
P
1

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.

Pelham answered 24/6, 2013 at 16:50 Comment(0)
A
0

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.

Activate answered 12/6, 2019 at 19:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.