Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we need perspective division?

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?

like image 971
Megharaj Avatar asked Jun 24 '13 07:06

Megharaj


People also ask

What Does perspective divide do?

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.

What is perspective divide in computer graphics?

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.

What is W in 3D graphics?

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.


3 Answers

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.

like image 147
a.lasram Avatar answered Oct 03 '22 21:10

a.lasram


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.

like image 20
datenwolf Avatar answered Oct 03 '22 22:10

datenwolf


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.

like image 32
Steven Lu Avatar answered Oct 03 '22 21:10

Steven Lu