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?
Each point produced by the perspective matrix multiplication has a nonunitary fourth component that represents the perspective divide by z. Dividing each point by its fourth component completes the perspective transformation.
The perspective divide The projection matrix sets things up so that after multiplying with the projection matrix, each coordinate's W will increase the further away the object is. OpenGL will then divide by w: X, Y, Z will be divided by W.
So traditionally, in 3D graphics, directional lights are differentiated from point lights by the value of W in the position vector of the light. If W=1, then it is a point light. If W=0, then it is a directional light.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With