The Projection Matrix Lecture 26 Fri Nov 18

  • Slides: 30
Download presentation
The Projection Matrix Lecture 26 Fri, Nov 18, 2005

The Projection Matrix Lecture 26 Fri, Nov 18, 2005

The Graphics Pipeline Object Coords Model Trans M World Coords View Trans V Eye

The Graphics Pipeline Object Coords Model Trans M World Coords View Trans V Eye Coords Lighting Calculations Perspective Divide Normal Dev Coords Proj Trans P Clip Coords Clipping Window Coords Framebuffer Rasterization, Shading Hidden-surface Removal, Texture Application

Homogeneous Coordinates Points are stored in homogeneous coordinates (x, y, z, w). The true

Homogeneous Coordinates Points are stored in homogeneous coordinates (x, y, z, w). The true 3 D coordinates are (x/w, y/w, z/w). Therefore, for example, the points (4, 3, 2, 1) and (8, 6, 4, 2) represent the same 3 D point (4, 3, 2). This fact will play a crucial role in the projection matrix.

Coordinate Systems Eye coordinates n n The camera is at the origin, looking in

Coordinate Systems Eye coordinates n n The camera is at the origin, looking in the negative z-direction. View frustrum (right – left, bottom – top, near – far). Normalized device coordinates n n n -1 x 1 -1 y 1 -1 z 1

The Transformation Points in eye coordinates must be transformed into normalized device coordinates. But

The Transformation Points in eye coordinates must be transformed into normalized device coordinates. But first they are transformed to clipping coordinates.

The Transformation For example, n n The point (r, t, -n, 1) is first

The Transformation For example, n n The point (r, t, -n, 1) is first transformed to the point (n, n, -n, n). The point (l(f/n), b(f/n), -f, 1) is first transformed to the point (-f, f, f).

The Transformation Later, Open. GL divides by the w-coordinate to get normalized device coordinates.

The Transformation Later, Open. GL divides by the w-coordinate to get normalized device coordinates. n n (n, n, -n, n) (1, 1, -1) (-f, f, f) (-1, 1) This is called the homogeneous divide, or perspective division. It is a nonlinear transformation. It occurs at a later stage in the pipeline.

The Perspective Transformation – x, y Points in eye coordinates are projected onto the

The Perspective Transformation – x, y Points in eye coordinates are projected onto the near plane, sort of. n n The x- and y-coordinates are projected onto the near plane. The z-coordinated is scaled to the range [-n, f].

The Perspective Transformation – x, y Consider the projection in the yz-plane. near plane

The Perspective Transformation – x, y Consider the projection in the yz-plane. near plane P(x, y, z) t b -n -f

The Perspective Transformation – x, y Consider the projection in the yz-plane. near plane

The Perspective Transformation – x, y Consider the projection in the yz-plane. near plane P(x, y, z) t b y -z -f

The Perspective Transformation – x, y Consider the projection in the yz-plane. near plane

The Perspective Transformation – x, y Consider the projection in the yz-plane. near plane P(x, y, z) t y b n -z y -f

The Perspective Transformation – x, y By similar triangles, y /n = y/(-z), Therefore,

The Perspective Transformation – x, y By similar triangles, y /n = y/(-z), Therefore, Similarly,

The Perspective Transformation – x, y Notice that these transformation are not linear. That

The Perspective Transformation – x, y Notice that these transformation are not linear. That is, x and y are not linear combinations of x, y, and z. Therefore, this transformation cannot be carried out by matrix multiplication. We will perform the multiplication by n using a matrix, but dividing by -z, i. e. , w, will have to be postponed.

The Perspective Transformation – z The z-coordinate is handled differently because we must not

The Perspective Transformation – z The z-coordinate is handled differently because we must not lose the depth information yet. In the z-direction, we want to map the interval [-n, -f] to the interval [-n, f]. Later, the perspective division will map [-n, f] into [-1, 1].

The Perspective Transformation – z Since this is a linear transformation, we will have

The Perspective Transformation – z Since this is a linear transformation, we will have z = az + b, for some a and b, to be determined. We need Therefore,

The Perspective Transformation That is, we will map (r, t, -n, 1) (nr, nt,

The Perspective Transformation That is, we will map (r, t, -n, 1) (nr, nt, -n, n), (l(f/n), b(f/n), -f, 1) (fl, fb, f, f), etc. which is a linear transformation. These points are equivalent to (r, t, -1), (l, b, 1), etc.

The Perspective Transformation The perspective matrix is Represents division by –z (perspective division)

The Perspective Transformation The perspective matrix is Represents division by –z (perspective division)

The Perspective Transformation This transforms this frustum… P(x, y, z) t b -n -f

The Perspective Transformation This transforms this frustum… P(x, y, z) t b -n -f

The Perspective Transformation …into this frustum ft P(x, y, z) nt -n nb fb

The Perspective Transformation …into this frustum ft P(x, y, z) nt -n nb fb f

The Perspective Transformation Later, the perspective division will transform this into a cube. 1

The Perspective Transformation Later, the perspective division will transform this into a cube. 1 P(x, y, z) 1 -1 -1

The Perspective Transformation Verify that P 1 maps n n n n (r, t,

The Perspective Transformation Verify that P 1 maps n n n n (r, t, -n, 1) (nr, nt, -n, n) (r, t, -1) (l, t, -n, 1) (nl, nt, -n, n) (l, t, -1) (r, b, -n, 1) (nr, nb, -n, n) (r, b, -1) (l, b, -n, 1) (nl, nb, -n, n) (l, b, -1) (r(f/n), t(f/n), -f, 1) (fr, ft, -f, f) (r, t, -1) (l(f/n), t(f/n), -f, 1) (fl, ft, -f, f) (l, t, -1) (r(f/n), b(f/n), -f, 1) (fr, fb, -f, f) (r, b, -1) (l(f/n), b(f/n), -f, 1) (fl, fb, -f, f) (l, b, -1)

The Projection Transformation The second part of the projection maps w (nr, nt, -n,

The Projection Transformation The second part of the projection maps w (nr, nt, -n, n) (n, n, -n, n) (1, 1, -1) w (nl, nt, -n, n) (-n, n, -n, n) (-1, 1, -1) w (nr, nb, -n, n) (n, -n, n) (1, -1) w (nl, nb, -n, n) (-n, -n, n) (-1, -1) w (fr, ft, -f, f) (f, f, f, f) (1, 1, 1) w (fl, ft, -f, f) (-f, f, f, f) (-1, 1, 1) w (fr, fb, -f, f) (f, -f, f, f) (1, -1, 1) w (fl, fb, -f, f) (-f, f, f) (-1, 1)

The Projection Transformation The matrix of this transformation is

The Projection Transformation The matrix of this transformation is

The Projection Matrix The product of the two transformations is the projection matrix.

The Projection Matrix The product of the two transformations is the projection matrix.

The Projection Matrix The function gl. Frustum(l, r, b, t, n, f) creates this

The Projection Matrix The function gl. Frustum(l, r, b, t, n, f) creates this matrix and multiplies the projection matrix by it. gl. Matrix. Mode(GL_PROJECTION); gl. Load. Identity(); gl. Frustum(l, r, b, t, n, f);

The Projection Matrix The function glu. Perspective(angle, ratio, near, far) also creates the projection

The Projection Matrix The function glu. Perspective(angle, ratio, near, far) also creates the projection matrix by calculating r, l, t, and b. gl. Matrix. Mode(GL_PROJECTION); gl. Load. Identity(); glu. Perspective(angle, ratio, n, f);

The Projection Matrix The formulas are n n t = n tan(angle/2) b =

The Projection Matrix The formulas are n n t = n tan(angle/2) b = -t r = t ratio l = -r

Question When choosing the near and far planes in the glu. Perspective() call, why

Question When choosing the near and far planes in the glu. Perspective() call, why not let n be very small, say 0. 000001, and let f be very large, say 1000000. 0?

Orthogonal Projections The matrix for an orthogonal projection is much simpler. All it does

Orthogonal Projections The matrix for an orthogonal projection is much simpler. All it does is rescale the x-, y-, and zcoordinates to [-1, 1]. n The positive direction of z is reversed. It represents a linear transformation; the wcoordinate remains 1.

Orthogonal Projections The matrix of an orthogonal projection is

Orthogonal Projections The matrix of an orthogonal projection is