Download Presentation
Viewing and Perspective

Loading in 2 Seconds...

1 / 47

# Viewing and Perspective - PowerPoint PPT Presentation

Viewing and Perspective. Kurt Akeley CS248 Lecture 9 23 October 2007 http://graphics.stanford.edu/courses/cs248-07/. Projection. Projection Transforms points from an n to an n-1 coordinate system Other definitions? … Surface of projection Typically a plane (“planar”)

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

## PowerPoint Slideshow about 'Viewing and Perspective' - leia

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### Viewing and Perspective

Kurt Akeley

CS248 Lecture 9

23 October 2007

http://graphics.stanford.edu/courses/cs248-07/

Projection

Projection

• Transforms points from an n to an n-1 coordinate system
• Other definitions? …

Surface of projection

• Typically a plane (“planar”)
• Curved in special cases
• E.g., dome simulator

Projectors (connect points through the center of projection)

• Typically straight lines (“geometric”)
• Curved in special cases
• Cartographic (e.g., Mercator)
• Fish-eye lens (e.g., Omnimax)

Image courtesy of Wikipedia

Image courtesy of Wikipedia

Planar geometric projections

Straight lines project to straight lines

• p1, p2, and c define a plane
• The intersection of this plane and the plane of projection is a line

But distances may be distorted

p1

p2

c

Center of projection(aka point of projection, viewpoint)

Plane of projection

Taxonomy of planar geometric projections

Planar geometric

Parallel

Perspective

Orthographic

Oblique

1-point

2-point

3-point

Top

Front

Side

Cabinet

Cavalier

True projection type

Viewing transformation

The vertex pipeline

Application

struct { float x,y,z,w; float nx,ny,nz; float r,g,b,a;} vertex;

Vertex assembly

Vertex operations

Primitive assembly

Primitive operations

Rasterization

Fragment operations

Framebuffer

Display

OpenGL coordinate systems

no

vo

Object coordinates

“Model-view” transformation(non-rigid)

Transform vo by MTransform no by M-1

Eye coordinates(lighting calculations)

ne

ve

Vertex operations

Transform ve by P

Projection transformation(non-rigid)

vc

Clip coordinates

The vertex pipeline

struct { float x,y,z,w; float nx,ny,nz; float r,g,b,a;} vertex;

Application

Vertex assembly

Vertex operations

struct { float x,y,z,w; float r,g,b,a;} clipvertex;

Primitive assembly

Primitive operations

Rasterization

Fragment operations

Framebuffer

Display

OpenGL coordinate systems

Object coordinates

no

vo

Transform vo by MTransform no by M-1

Model-view transformation

Vertex operations

Eye coordinates(lighting calculations)

ne

ve

Transform ve by P

Projection transformation

vc

Primitive assembly

Clip coordinates(clip to unit cube)

Divide by wc

Homogenize

Normalized device coordinates

vd

Primitive operations

Map to Window

Viewport transformation

vw

Window coordinates

Coordinates systems are convenient

Object coordinates

• Defined by modeler

Eye coordinates

• Eye is at the origin, looking down the -z axis, +x to the right
• Convenient for lighting calculations

Clip coordinates

• Unit cube (+/- 1) centered at the origin
• Convenient for clipping calculations (plane equations are trivial)

Normalized device coordinates

• Homogenized clip coordinates
• Convenient for rasterization and frame buffer arithmetic

Window coordinates

• Pixels are unit squares, origin at lower-left corner of window
• Z values fill available depth-buffer range
Viewing transformation

Puts eye at origin looking down the -z axis, +x to the right

Transformation is rigid, one rotation and one translation

• GLU helper routine is available (next slide)

y

x

z

gluLookAt

gluLookAt(double ex, double ey, double ez, // eye

double cx, double cy, double cz, // center

double ux, double uy, double uz); // up

Light positions

Specified position is transformed by the modelview matrix

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

gluLookAt(ex,ey,ez,cx,cy,cz,ux,uy,uz);

// now in world coordinates

Float vec[4] = {px, py, pz, pw};

glLightfv(GL_POSITION, vec, 4); // specify in world coordinates

glMultMatrixf(…);

glLightfv(GL_POSITION, vec, 4); // specify in object coordinates

Orthographic projection

Only scaling is required

But the interface supports scaling and translation:

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

glOrtho(l,r,b,t,n,f);

n and f are signed distances, not coordinates

Clip testing

vc is within the unit cube centered at the origin if:

Assuming wc is positive,

this is equivalent to:

yc

xc

zc

Clipping arithmetic

Points outside the unit cube are discarded

Lines (or edges) that straddle a face of the unit cube are clipped

• A new vertex is location is computed at the intersection
• Appropriate attribute values are assigned to this vertex

p2

p

p1

Clipping details

The calculation of p must be invariant to the order of p1 and p2

• An edge shared by two triangles must not “crack”
• Easiest implementation is canonical:
• Sort the vertexes into canonical order, then compute p

Line clipping never generates more than two vertexes

Triangle clipping can generate a vertex for each clipping plane

• E.g., Sutherland-Hodgman
• Later in this lecture
• SGI paid royalties on this
Homogenization

Divide by wc:

Discard wd:

Viewport transformation

Transform the [-1,1] range device coordinates to window coordinates:

glViewport(int l, int b, int w, int h);

glDepthRange(double n, double f);

glViewport(0, 0, 10, 6);

glDepthRange(0.0, 1.0);

One pixel

The vertex pipeline

struct { float x,y,z,w; float nx,ny,nz; float r,g,b,a;} vertex;

Application

Vertex assembly

Vertex operations

struct { float x,y,z,w; float r,g,b,a;} clipvertex;

Primitive assembly

Primitive operations

struct { winvertex v0,v1,v2 } triangle;

Rasterization

struct { float x,y,z; float r,g,b,a;} winvertex;

Fragment operations

Framebuffer

Display

Window coordinates

Window coordinates are:

• Continuous, not discrete
• Not homogeneous
• Can be used directly for rasterization
• 3-D, not 2-D
• Projection did not reduce 3-D to 2-D
• 3-D homogeneous was reduced to 3-D non-homogeneous
• But this was done by homogenization, not by the projection transformation

Where did the parallel “projection” happen?

Oblique projection

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

glOrtho(l,r,b,t,n,f);

float s = 0.5; // Cabinet

float m[16] = {1,0,0,0, 0,1,0,0, -s,-s,1,0, 0,0,0,1};

glMultMatrixf(m);

Change only the projection matrix

Object coordinates

no

vo

Transform vo by MTransform no by M-1

Model-view transformation

Vertex operations

Eye coordinates(lighting calculations)

ne

ve

Transform ve by P

Projection transformation

vc

Primitive assembly

Clip coordinates(clip to unit cube)

Divide by wc

Homogenize

Normalized device coordinates

vd

Primitive operations

Map to Window

Viewport transformation

vw

Window coordinates

Orthographic projection

Only scaling is required

But the interface supports scaling and translation:

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

glOrtho(l,r,b,t,n,f);

Perspective projection

Specify a frustum:

n and f are distances, not coordinates. Both must be positive.

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

glFrustum(l,r,b,t,n,f);

Where does projection happen?

There are two ways to think about this:

• In the projection transformation
• “Thinking homogeneously”
• Setting wc= –ze warps the eye-coordinate system
• From a frustum in eye coordinates
• To the unit cube in clip coordinates
• Homogenization doesn’t really change anything further
• Hence “projection transformation”
• During homogenization and the discarding of the wd
• “Thinking geometrically”
• Dividing by –ze causes the projection
• This is where coordinates are reduced from 4D to 3D
Remaining topics

Perspective-correct attribute parameterization

Sutherland-Hodgman clipping

Near-plane clipping

The “direction” of a projection

Wide field-of-view projection (planar doesn’t work well)

Rasterization revisited

struct { float x,y,z,w; float nx,ny,nz; float r,g,b,a;} vertex;

Application

Vertex assembly

Vertex operations

struct { float x,y,z,w; float r,g,b,a;} clipvertex;

Primitive assembly

Primitive operations

struct { winvertex v0,v1,v2 } triangle;

Rasterization

struct { float x,y,z; float r,g,b,a;} winvertex;

Fragment operations

Framebuffer

Display

Planar geometric projection

Straight lines project to straight lines

• Only vertexes need to be transformed
• That’s why we’re interested in lines and polygons

But distances and parameterizations are warped:

Incorrect attribute interpolation

f1

Linearinterpolation

f1

f

f

F

f2

f2

a2

a0

a1

Linear (barycentric) attribute evaluation

(x1, y1, f1)

(x, y, f )

(x0, y0, f0)

(x2, y2, f2)

a2

a0

a1

Perspective-correct attribute evaluation

(x1, y1, w1, f1)

(x, y, f )

All w’s are wc’s

(x0, y0, w0, f0)

(x2, y2, w2, f2)

Requires a division for each fragment

Rasterization requires access to wc

struct { float x,y,z,w; float nx,ny,nz; float r,g,b,a;} vertex;

Application

Vertex assembly

Vertex operations

struct { float x,y,z,w; float r,g,b,a;} clipvertex;

Primitive assembly

Primitive operations

struct { winvertex v0,v1,v2 } triangle;

Rasterization

struct { float x,y,z,w_c; float r,g,b,a;} winvertex;

Fragment operations

Framebuffer

Display

OpenGL coordinate systems

Object coordinates

no

vo

Transform vo by MTransform no by M-1

Model-view transformation

Vertex operations

Eye coordinates(lighting calculations)

ne

ve

Transform ve by P

Projection transformation

vc

Primitive assembly

Clip coordinates(clip to unit cube)

Divide by wc

Homogenize

Normalized device coordinates

vd , wc

Primitive operations

Map to Window

Viewport transformation

vw , wc

Window coordinates

Sutherland-Hodgman clipping

Approach: clip against each plane in sequence

Simplified example clips a triangle to a square, 2-D frustum:

Near-plane clipping

Is required …

• To limit zw values to the range of the depth buffer
• To avoid division by wc= 0
• To avoid rendering objects behind the viewpoint
• But clipping assuming wc> 0 accomplishes this too
The “direction” of a projection

Yes, we spoke of a view direction in eye coordinates

• Specifically, down the –ze axis, +xe to the right

And yes, the plane of projection is perpendicular to the –ze axis by convention

But, once the projection has been specified, it is not valid to treat it as implying a true viewing direction (the orientation of the eye):

• Parallel projections have a meaningful direction that is distinct from the normal to the plane of projection, but this direction is not the view direction.
• Perspective projections have no meaningful direction at all. Once specified, they are fully characterized by a center of projection and a plane of projection. The normal to the plane of projection has no meaning.

Bottom line: once a projection has been specified, it implies nothing about the orientation of the viewer’s eye. Only the location of the eye’s optical center is specified (the center of projection).

Wide field-of-view display

Assume equal-size pixels

Problem:

• Center-field pixels are most important (foveal gaze)
• But wide-field pixels have much greater “resolution”
Ratio of perceived pixel sizes

Ratio of perceived size of center pixel to edge pixel

Field of view (degrees)

Piece-wise linear projection

Note: there is one view direction, but three planes of projection

Summary

Perspective projection can be understood two different ways:

• Warping of eye coordinates by the projection transformation
• Consistent with orthographic transformation
• Consistent with 3-D result
• Consistent with name “projection transformation”
• Division by -ze and discarding of wd
• Consistent with attribute evaluation

Perspective projection warps distances and attribute evaluation

• Must interpolate only “projected” values
• Requires division for attributes of each fragment

Projections do not specify the true orientation of the viewer’s eye

• Perspective projections don’t really have a direction
• Parallel projections do, but it’s not the viewing direction
Assignments

Reading assignment for Thursday’s class

• FvD 17.4
• OpenGL chapter 9
• Optional: Heckbert, P., A Survey of Texture Mapping,IEEE Computer Graphics, 6:11, pp. 56-67, 1986.

Project 2:

• Due tonight at midnight

Midterm

• Monday 7 pm to 9 pm, Gates B01