59
3D Viewing (From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in St. Louis

3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

Embed Size (px)

Citation preview

Page 1: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

3D Viewing(From 3D to 2D)

Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in St. Louis

Page 2: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

2

Outline

● 3D Viewing● Perspective projection● Computing Projection● Our Virtual Camera Model● Camera parameters● Compute viewing transformation● Clipping against the canonical volume● Projecting to viewport

Page 3: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

3

3D viewing

● Inherently more complex than 2D case.■ Extra dimension (!)■ Many display devices are only 2D.

● Need to use a projection to transform 3D object or scene to 2D display device.

● Need to clip against a 3D view volume.■ Six planes.■ View volume probably truncated pyramid.

Page 4: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

4

Coordinate SystemsObject coordinate systems.

World coordinates.

View Volume

Screen coordinates.

Raster

Transform

Project

Clip

Rasterize

Page 5: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

5

Projections

● Transforms points in a coordinate system of dimension n into points in one of less than n.

● The projection is defined by straight lines called projectors.● Projectors emanate from a centre of projection, pass through

every point in the object and intersect a projection surface to form the 2D projection.

Page 6: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

6

Projections

● In graphics we only deal with planar projections – where the projection surface is a plane.

■ Most cameras employ a planar film plane.■ But… the retina is not a plane.

● Only deal with geometric projections – the projectors are straight lines.

■ Many projections used in cartography are either non-geometric or non-planar.

● Exception – Image-based rendering.

Page 7: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

7

Projections

● Henceforth refer to planar geometric projections as just: projections.● Two classes of projections :

■ Perspective.■ Parallel.

A

B

A

B

A

B

A

B

Centre ofProjection.

Centre of Projectionat infinity

Parallel

Perspective

Page 8: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

8

A Taxonomy of projections

Planar geometric projections.

Parallel Perspective

Orthographic Oblique 1 point

2 point

3 point

Axonometric

Isometric

CavalierCabinet

Elevations

Page 9: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

9

Perspective projections

● Defined by projection plane and centre of projection.● Visual effect is termed perspective foreshortening.

■ The size of the projection of an object varies inversely with distance from the centre of projection.

■ Similar to a camera - Looks realistic !● Not useful for metric information.

■ Parallel lines do not in general project as parallel.■ Angles only preserved on faces parallel to the projection plane.■ Distances not preserved.

Page 10: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

10

Perspective

The first ever painting (Trinity with the Virgin, St. John and Donors) done in perspective by Masaccio, in 1427.

The first ever painting (Trinity with the Virgin, St. John and Donors) done in perspective by Masaccio, in 1427.

Page 11: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

11

Perspective projections

• A set of lines not parallel to the projection plane converge at a vanishing point.– Can be thought of in 3D as

the projection of a point at infinity.

– Homogeneous coordinate is 0 (x,y,0)

Page 12: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

13

1-point projection

Projection plane cuts 1 axis only.

Page 13: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

14

1-point perspective

A painting (The Piazza of St. Mark, Venice) done by Canaletto in 1735-45 in one-point perspective.

Page 14: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

15

2-point perspective

y

z x

Projection plane

Page 15: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

16

2-point perspective

Painting in two point perspective by Edward Hopper The Mansard Roof 1923 (240 Kb); Watercolor on paper, 13 3/4 x 19 inches; The Brooklyn Museum, New York

Page 16: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

17

3-point perspective

Adds little beyond 2-point perspective.

y

z x

Projection plane

A painting (City Night, 1926) by Georgia O'Keefe, that is approximately in three-point perspective.

Page 17: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

18

Computing Projection

● How to perform projection in the computer? Or, given a point in 3D, where do I draw it on the 2D computer screen?

● World Coordinate Screen Coordinate● {xw, yw, zw} {xs, ys}

Page 18: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

19

Virtual Camera

● Programmer’s reference model for specifying 3D view projection parameters to the computer

● General parameters– position of camera– orientation– field of view (wide angle, normal…)– Focal distance (Will be omitted in our simplified camera model)

– Tilt of view/film plane (for oblique views) (Will be omitted in our simplified camera model)

– depth of field (near distance, far distance)– perspective or parallel projection?

Page 19: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

20

View Volume

● Contains everything visible from the view point– Cone-shaped

● Possible shapes of the cone’s cross-section:– Circular: approximates how eyes work

○ Does not fit rectangular viewports○ Expensive math when performing clipping against cone’s surface

– Rectangular: fits windows viewport, easy to clip○ Called the “Frustum”

Page 20: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

21

Our Camera Model

Page 21: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

22

Position

● From where the camera is looking■ Like a photographer choosing the vantage point to shoot a

photo

● Any 3D point■ The (OpenGL) world’s coordinate system: right hand rule

○ Align right hand fingers with +X axis○ Curl fingers towards +Y axis○ Your thumb points towards +Z axis

P

Page 22: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

23

Orientation – Up Vector

● How the camera is rotated around the look vector■ If you are holding the camera horizontally or vertically, or

in between.

● Any 3D vector U = {ux, uy, uz}■ Up-right direction is determined by the projection of U on

the plane normal to L

Page 23: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

24

Default Position

● (OpenGL) Camera at origin, looking down –Z axis, and in upright pose

Page 24: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

25

Viewing Angle

● Describes the field of view■ Like choosing a specific type of lens, e.g., a wide-angle

lens or telephoto lens

● Width and height angles

Page 25: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

26

Viewing Angle (cont.)

● Determines amount of perspective distortion■ Small angles result in near-parallel projectors, hence little

distortion. Example: telephoto lens■ Large angles result in widely varying projectors with large

distortion. Example: wide-angle lens

Page 26: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

27

Viewing Angle (cont.)

● Aspect Ratio■ Ratio of width over height of the screen

○ 1:1 (square)○ 4:3 (NTSC)○ 16:9 (HDTV)○ 2.35:1 (Widescreen Films)

● Represent viewing angles as aspect ratio and height angle■ Compute width angle:

Page 27: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

28

Clipping Planes

● Restricts visible volume between near and far clipping planes■ Objects outside the frustum are not drawn■ Objects intersecting the frustum are clipped

● Defined as distances dn , df from camera along look vector

Page 28: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

29

Clipping Planes (cont.)

● Why do we need near plane■ Avoid drawing things too close to camera

○ They will appear with large distortion, and may block view

■ Avoid drawing things behind the camera○ They will appear upside-down and inside-out

● Why do we need far plane■ Avoid drawing things too far away

○ They will complicate the scene○ They appear small on the screen anyway○ Saving rendering time

Page 29: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

30

Perspective Camera Model

● View frustum: a truncated pyramid region that the camera can “see”

● 2D view of 3D frustum can be created by projecting onto a film plane

Page 30: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

31

Orthographic Camera Model

● Width and height replaces viewing angles■ Both width angle and height angle are effectively zero

Page 31: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

32

Coordinate SystemsObject coordinate systems.

World coordinates.

View Volume

Screen coordinates.

Raster

Transform

Project

Clip

Rasterize

Page 32: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

33

Canonical View Volume

Page 33: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

34

Canonical View Volume

● Canonical view volume makes things easy:■ Easy clipping: Clip against the coordinates range

−1 ≤ x ≤ 1, −1 ≤ y ≤ 1, 0 ≤ z ≤ 1

■ Easy projecting: drop the z coordinate! (because viewing plane is the xy plane, and projectors are parallel to z axis)

{xc, yc, zc} {xc, yc}

Coordinates in the Projected 2D coordinates

canonical volume

Page 34: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

35

Viewing Transform

● For any viewing volume: transform it into the canonical volume!■ The transformation brings the blue box into the red box■ The same transformation brings world coordinates

{xw,yw,zw} into canonical coordinates within the canonical volume {xc,yc,zc}

■ Clip and project

Page 35: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

36

Camera Coordinate System

● Three orthogonal axes setting up the camera’s world■ – u (right) v (straight-up) n (negative look)

○ Unit vectors forming an orthonormal basis

■ Observing the right-hand rule

Page 36: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

37

Camera Coordinate System

● Computing n■ Opposite to look vector L, normalized

Page 37: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

38

Camera Coordinate System

● Computing v■ Projection of up vector U onto the camera plane,

normalized

+

Page 38: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

39

Camera Coordinate System

● Computing u

Page 39: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

40

CCS - Summary

● Three axes, computed from look vector L and up vector U:

● They are unit vectors● u,v,n follow the right-hand rule

+

+

Page 40: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

41

Computing Viewing Transformation

● Two steps■ Step 1: aligning camera coordinate system P,u,v,n with

world coordinate system O,x,y,z■ Step 2: scale and stretch the viewing volume to the cuboid

Page 41: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

42

Step 1

● First, translate the eye point P to the origin■ Homogenous coordinates! Easy to compose transformation

as matrix product

Page 42: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

43

Step 1 (cont.)

● Rotate the three axes u,v,n to x,y,z■ First, set up the equation to solve for the rotation matrix R:

we know that vectors u,v,n are rotated to three canonical vectors, and the original stays put.

■ In matrix form:

Page 43: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

44

Step 1 (cont.)

● Simplify our notation:

● Solve for the rotation matrix■ M is ortho-normal, meaning Therefore,

Page 44: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

45

After Step 1

● Eye point at origin, looking down negative z axis

Page 45: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

46

Step 2

● Scale the viewing volume to the correct size■ Here is a look down the Y axis■ First, force width/height angle to be right angles

(width=height)○ Scaling in x,y coordinates

Use the Matlab demo

Page 46: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

47

Step 2 (cont.)

● Scale the viewing volume to the correct size■ Next, push the far plane to the xy plane at z=-1■ Scaling in all three coordinates■ Thus far plan has the right size but still its Z needs adjustment.

Page 47: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

48

Step 2 (cont.)

● Now, the far plane corners are at {±1, ±1, −1}

Page 48: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

49

Step 2 (cont.)

● Perspective transformation■ Stretching the truncated pyramid to the cuboid

○ Stretch in XY plane: Non-uniform stretching based on z○ Change Z range:

Page 49: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

50

Step 2 (cont.)

Page 50: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

51

Step 2 (cont.)

● Perspective transformation■ Stretching the truncated pyramid to the cuboid

○ Stretch in XY plane: Non-uniform stretching based on z○ Change Z range:

Note that far plan is at z=-1 so it will not be scaled, only its Z is adjusted

Page 51: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

52

Putting Together

Page 52: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

53

Clipping

● After transformation into the canonical volume, each object will be clipped against 6 cuboid faces.■ Point clipping: checking coordinates range

−1 ≤ x ≤ 1, −1 ≤ y ≤ 1, 0 ≤ z ≤ 1■ Edge clipping: computing line/plane intersections

■ Triangle clipping: Need to consider face/face intersections

Page 53: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

54

Line Clipping

Page 54: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

55

Line Clipping

Page 55: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

56

Object Clipping

Page 56: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

57

Projecting

● Dropping z coordinate■ Resulting points have range:

−1 ≤ x ≤ 1, −1 ≤ y ≤ 1

Page 57: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

58

Viewport Transform

● Get viewport (pixel) coordinates■ Viewport coordinate {0,0} is at top-left corner■ If the viewport is a pixels wide and b pixels high, the pixel

coordinates for a projected point {x,y} is

Thus (-1,1) (0,0) while (1,-1)(a,b)

Page 58: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in

59

Summary

● To compute projection■ Set up camera parameters■ Compute viewing transformation■ Clipping against the canonical volume■ Projecting to viewport

Page 59: 3D Viewing ( From 3D to 2D) Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in