CS-184: Computer Graphics Lecture #8: Projection Prof. James - - PowerPoint PPT Presentation

cs 184 computer graphics
SMART_READER_LITE
LIVE PREVIEW

CS-184: Computer Graphics Lecture #8: Projection Prof. James - - PowerPoint PPT Presentation

1 CS-184: Computer Graphics Lecture #8: Projection Prof. James OBrien University of California, Berkeley V2016-F-08-1.0 2 Today Windowing and Viewing Transformations Windows and viewports Orthographic projection


slide-1
SLIDE 1

CS-184: Computer Graphics

Lecture #8: Projection

  • Prof. James O’Brien

University of California, Berkeley

V2016-F-08-1.0

1

2

Today

  • Windowing and Viewing Transformations
  • Windows and viewports
  • Orthographic projection
  • Perspective projection

2 08-Perspective.key - September 28, 2016

slide-2
SLIDE 2

3

Screen Space

  • Monitor has some number of pixels
  • e.g. 1024 x 768
  • Some sub-region used for given program
  • You call it a window
  • Let’s call it a viewport instead

[0,0] [1024,768] [60,350] [690,705] [0,0] [1024,768]

3

4

Screen Space

  • May not really be a “screen”
  • Image file
  • Printer
  • Other
  • Little pixel details
  • Sometimes odd
  • Upside down
  • Hexagonal

From Shirley textbook.

4 08-Perspective.key - September 28, 2016

slide-3
SLIDE 3

5

Screen Space

  • Viewport is somewhere on screen
  • You probably don’t care where
  • Window System likely manages this detail
  • Sometimes you care exactly where
  • Viewport has a size in pixels
  • Sometimes you care (images, text, etc.)
  • Sometimes you don’t (using high-level library)

5

Screen Space

6

Integer Pixel Addresses

i=3 j=5 10 × 10 Image Resolution

  • 0.5,-0.5

nx-0.5,ny-0.5

6 08-Perspective.key - September 28, 2016

slide-4
SLIDE 4

Screen Space

7

Float Pixel Coordinates

u= 0.35 = (i + 0.5)/nx

0,0 1,1

v= 0.55 = (j + 0.5)/ny

7

8

Canonical View Space

  • Canonical view region
  • 2D: [-1,-1] to [+1,+1]

From Shirley textbook.

  • 1,-1

+1,+1

x=0.0, y=0.0

8 08-Perspective.key - September 28, 2016

slide-5
SLIDE 5

9

Canonical View Space

  • Canonical view region
  • 2D: [-1,-1] to [+1,+1]

x y y (1,1) (-1,-1) x (nx-0.5, -0.5) (-0.5, ny-0.5) x y (1,-1) (-1,1) (nx/2,-ny/2) (-nx/2,ny/2) y x reflect-y translate scale

From Shirley textbook. (Image coordinates are up-side-down.)

  x0 y0 1   =   

nx 2 0 nx1 2

0 ny

2 ny1 2

0 0 1      x y 1  

Remove minus for up-side-up

9

10

Projection

  • Process of going from 3D to 2D
  • Studies throughout history (e.g. painters)
  • Different types of projection
  • Linear
  • Orthographic
  • Perspective
  • Nonlinear

Orthographic is special case of perspective... Many special cases in books just

  • ne of these two...

}

10 08-Perspective.key - September 28, 2016

slide-6
SLIDE 6

Perspective Projections

11

11

Ray Generation vs. Projection

Viewing in ray tracing

  • start with image point
  • compute ray that projects to that point
  • do this using geometry

Viewing by projection

  • start with 3D point
  • compute image point that it projects to
  • do this using transforms

Inverse processes

  • ray gen. computes the preimage of projection

12

12 08-Perspective.key - September 28, 2016

slide-7
SLIDE 7

13

Linear Projection

  • Projection onto a planar surface
  • Projection directions either
  • Converge to a point
  • Are parallel (converge at infinity)

13

14

Linear Projection

  • A 2D view

Orthographic Perspective

14 08-Perspective.key - September 28, 2016

slide-8
SLIDE 8

15

Linear Projection

Orthographic Perspective

15

16

Linear Projection

Orthographic Perspective

16 08-Perspective.key - September 28, 2016

slide-9
SLIDE 9

17

Orthographic Perspective

Note how different things can be seen Parallel lines “meet” at infinity

Linear Projection

  • A 2D view

17

18

Orthographic Projection

  • No foreshortening
  • Parallel lines stay parallel
  • Poor depth cues

18 08-Perspective.key - September 28, 2016

slide-10
SLIDE 10

Orthographic Projection

19

19

20

Canonical View Space

  • Canonical view region
  • 2D: [-1,-1] to [+1,+1]
  • Define arbitrary window and define objects
  • Transform window to canonical region
  • Do other things (we’ll see clipping latter)
  • Transform canonical to screen space
  • Draw it.

From Shirley textbook.

20 08-Perspective.key - September 28, 2016

slide-11
SLIDE 11

21

Canonical View Space

World Coordinates Canonical Screen Space

(Meters) (Pixels) Note distortion issues...

21

22

Canonical View Space

  • Canonical view region
  • 3D: [-1,-1,-1] to [+1,+1,+1]
  • Assume looking down -Z axis
  • Recall that “Z is in your face”

[1,1,1] [-1,-1,-1]

  • Z

22 08-Perspective.key - September 28, 2016

slide-12
SLIDE 12

23

Orthographic Projection

  • Convert arbitrary view volume to canonical

[1,1,1] [-1,-1,-1]

  • Z

23

24

Orthographic Projection

View vector Up vector Right = view X up Origin Center near,top,right far,bottom,left *Assume up is perpendicular to view.

24 08-Perspective.key - September 28, 2016

slide-13
SLIDE 13

25

Orthographic Projection

  • Step 1: translate center to origin

25

26

Orthographic Projection

  • Step 1: translate center to origin
  • Step 2: rotate view to -Z and up to +Y

26 08-Perspective.key - September 28, 2016

slide-14
SLIDE 14

27

Orthographic Projection

  • Step 1: translate center to origin
  • Step 2: rotate view to -Z and up to +Y
  • Step 3: center view volume

27

28

Orthographic Projection

  • Step 1: translate center to origin
  • Step 2: rotate view to -Z and up to +Y
  • Step 3: center view volume
  • Step 4: scale to canonical size

28 08-Perspective.key - September 28, 2016

slide-15
SLIDE 15

29

Orthographic Projection

  • Step 1: translate center to origin
  • Step 2: rotate view to -Z and up to +Y
  • Step 3: center view volume
  • Step 4: scale to canonical size

M = S·T2·R·T1 M = Mo·Mv

29

30

Perspective Projection

  • Foreshortening: further objects appear smaller
  • Some parallel line stay parallel, most don’t
  • Lines still look like lines
  • Z ordering preserved (where we care)

30 08-Perspective.key - September 28, 2016

slide-16
SLIDE 16

31

Perspective Projection

Pinhole a.k.a center of projection

Image from D. Forsyth

31

32

Perspective Projection

Foreshortening: distant objects appear smaller

Image from D. Forsyth

32 08-Perspective.key - September 28, 2016

slide-17
SLIDE 17

33

Perspective Projection

  • Vanishing points
  • Depend on the scene
  • Not intrinsic to camera

“One point perspective”

33

34

Perspective Projection

  • Vanishing points
  • Depend on the scene
  • Nor intrinsic to camera

“Two point perspective”

34 08-Perspective.key - September 28, 2016

slide-18
SLIDE 18

35

Perspective Projection

  • Vanishing points
  • Depend on the scene
  • Not intrinsic to camera

“Three point perspective”

35

36

Perspective Projection

u v n

View Frustum

36 08-Perspective.key - September 28, 2016

slide-19
SLIDE 19

37

Perspective Projection

View Up Distance to image plane i Y

  • Z

Top t Bottom b Near n Far f Center

37

38

Perspective Projection

  • Step 1: Translate center to origin

Y

  • Z

38 08-Perspective.key - September 28, 2016

slide-20
SLIDE 20

39

Perspective Projection

  • Step 1: Translate center to origin
  • Step 2: Rotate view to -Z, up to +Y

Y

  • Z

39

40

Perspective Projection

  • Step 1: Translate center to origin
  • Step 2: Rotate view to -Z, up to +Y
  • Step 3: Shear center-line to -Z axis

Y

  • Z

40 08-Perspective.key - September 28, 2016

slide-21
SLIDE 21

41

Perspective Projection

  • Step 1: Translate center to origin
  • Step 2: Rotate view to -Z, up to +Y
  • Step 3: Shear center-line to -Z axis
  • Step 4: Perspective
  • Z

! ! ! ! ! ! " # $ $ $ $ $ $ % & − + 1 1 1 i f i f i

41

42

Perspective Projection

  • Step 4: Perspective
  • Points at z=-i stay at z=-i
  • Points at z=-f stay at z=-f
  • Points at z=0 goto z=±∞
  • Points at z=-∞ goto z=-(i+f)
  • x and y values divided by -z/i
  • Straight lines stay straight
  • Depth ordering preserved in [-i,-f ]
  • Movement along lines distorted
  • Z

! ! ! ! ! ! " # $ $ $ $ $ $ % & − + 1 1 1 i f i f i

42 08-Perspective.key - September 28, 2016

slide-22
SLIDE 22

43

From Shirley textbook.

Perspective Projection

WRONG!

! ! ! ! ! ! " # $ $ $ $ $ $ % & − + 1 1 1 i f i f i

43

44

Perspective Projection

ˆ z

“Eye” plane Top Near Far S

  • m

e h

  • r

i z

  • n

t a l l i n e s View vector

44 08-Perspective.key - September 28, 2016

slide-23
SLIDE 23

45

Perspective Projection

ˆ z

Visualizing division of x and y but not z

45

46

Perspective Projection

ˆ z

Motion in x,y

46 08-Perspective.key - September 28, 2016

slide-24
SLIDE 24

47

Perspective Projection

ˆ z

Note that points on near plane fixed

47

48

Perspective Projection

ˆ z

Recall that points on far plane will stay there...

48 08-Perspective.key - September 28, 2016

slide-25
SLIDE 25

49

Perspective Projection

ˆ z

When we also divide z points must

remain on straight lines

49

50

Perspective Projection

ˆ z

Lines extend outside view volume

50 08-Perspective.key - September 28, 2016

slide-26
SLIDE 26

51

Perspective Projection

ˆ z

Motion in z

51

52

Perspective Projection

ˆ z

Motion in z

−∞

52 08-Perspective.key - September 28, 2016

slide-27
SLIDE 27

53

Perspective Projection

ˆ z

Motion in z

−∞

53

54

Perspective Projection

ˆ z

Total motion

54 08-Perspective.key - September 28, 2016

slide-28
SLIDE 28

55

Perspective Projection

  • Step 1: Translate center to orange
  • Step 2: Rotate view to -Z, up to +Y
  • Step 3: Shear center-line to -Z axis
  • Step 4: Perspective
  • Step 5: center view volume
  • Step 6: scale to canonical size
  • Z

55

56

Perspective Projection

  • Step 1: Translate center to orange
  • Step 2: Rotate view to -Z, up to +Y
  • Step 3: Shear center-line to -Z axis
  • Step 4: Perspective
  • Step 5: center view volume
  • Step 6: scale to canonical size
  • Z

M = Mo ·Mp ·Mv Mo Mp Mv

} } }

56 08-Perspective.key - September 28, 2016

slide-29
SLIDE 29

57

Perspective Projection

  • There are other ways to set up the projection matrix
  • View plane at z=0 zero
  • Looking down another axis
  • etc...
  • Functionally equivalent

57

58

r(t) = p+t d

Vanishing Points

  • Consider a ray:

d p

58 08-Perspective.key - September 28, 2016

slide-30
SLIDE 30

59

Vanishing Points

  • Ignore Z part of matrix
  • X and Y will give location in image plane
  • Assume image plane at z=-i

! ! ! ! " # $ $ $ $ % & − 1 1 1 ! ! ! " # $ $ $ % & ! ! ! " # $ $ $ % & − = ! ! ! " # $ $ $ % & z y x I I I

w y x

1 1 1

whatever

59

60

Vanishing Points

! ! ! " # $ $ $ % & − = ! ! ! " # $ $ $ % & ! ! ! " # $ $ $ % & − = ! ! ! " # $ $ $ % & z y x z y x I I I

w y x

1 1 1 ! " # $ % & − − = ! " # $ % & z y z x I I I I

w y w x

/ / / /

60 08-Perspective.key - September 28, 2016

slide-31
SLIDE 31

61

Vanishing Points

  • Assume

dz = −1

! ! ! ! " # $ $ $ $ % & + − + + − + = ! " # $ % & − − = ! " # $ % & t p td p t p td p z y z x I I I I

z y y z x x w y w x

/ / / / ! " # $ % & = ±∞ →

y x

d d t Lim 61

62

Vanishing Points

  • All lines in direction d converge to same point in the image

plane -- the vanishing point

  • Every point in plane is a v.p. for some set of lines
  • Lines parallel to image plane ( ) vanish at infinity

! " # $ % & = ±∞ →

y x

d d t Lim

dz = 0 What’s a horizon?

62 08-Perspective.key - September 28, 2016

slide-32
SLIDE 32

Perspective Tricks

63

63

Right Looks Wrong (Sometimes)

64

. .

From Correction of Geometric Perceptual Distortions in Pictures, Zorin and Barr SIGGRAPH 1995

64 08-Perspective.key - September 28, 2016

slide-33
SLIDE 33

Right Looks Wrong (Sometimes)

65 From WIRED Magazine

65

Strangeness

66 The Ambassadors by Hans Holbein the Younger

66 08-Perspective.key - September 28, 2016

slide-34
SLIDE 34

Strangeness

67 The Ambassadors by Hans Holbein the Younger

67

68

Ray Picking

  • Pick object by picking point on screen
  • Compute ray from pixel coordinates.

68 08-Perspective.key - September 28, 2016

slide-35
SLIDE 35

69

Ray Picking

  • Transform from World to Screen is:
  • Inverse:
  • What Z value?

! ! ! ! " # $ $ $ $ % & = ! ! ! ! " # $ $ $ $ % &

w z y x w z y x

W W W W I I I I M

! ! ! ! " # $ $ $ $ % & = ! ! ! ! " # $ $ $ $ % &

− w z y x w z y x

I I I I W W W W

1

M

69

70

r(t) = aw +t(bw −aw) bs = [sx,sy,−f] as = [sx,sy,−i]

Ray Picking

  • Recall that:
  • Points at z=-i stay at z=-i
  • Points at z=-f stay at z=-f

r(t) = p+t d

Depends on screen details, YMMV General idea should translate...

70 08-Perspective.key - September 28, 2016

slide-36
SLIDE 36

71

Depth Distortion

  • Recall depth distortion from perspective
  • Interpolating in screen space different than in world
  • Ok, for shading (mostly)
  • Bad for texture

Screen World Half way in screen space Half way in world space

71

Depth Distortion

72 42

P1 P2 P3 P4 S1 = P1/h1 S2 = P2/h2 S3 = P3/h3 S4 = P4/h4

72 08-Perspective.key - September 28, 2016

slide-37
SLIDE 37

Depth Distortion

73 42

P1 P2 P3 P4 S1 = P1/h1 S2 = P2/h2 S3 = P3/h3 S4 = P4/h4 X = X i Sibi Q = X i Piai

We know the , , and , but not the .

Si Pi bi ai

73

Depth Distortion

74 42

P1 P2 P3 P4 S1 = P1/h1 S2 = P2/h2 S3 = P3/h3 S4 = P4/h4 X = X i Sibi Q = X i Piai X = Q/h = @X i Piai 1 A / B @ X j hjaj 1 C A

74 08-Perspective.key - September 28, 2016

slide-38
SLIDE 38

X i Sibi = @X i Piai 1 A / B @ X j hjaj 1 C A

Depth Distortion

75 42

P1 P2 P3 P4 S1 = P1/h1 S2 = P2/h2 S3 = P3/h3 S4 = P4/h4 X = X i Sibi Q = X i Piai

75

X i Pibi/hi = @X i Piai 1 A / B @ X j hjaj 1 C A

Depth Distortion

76 42

P1 P2 P3 P4 S1 = P1/h1 S2 = P2/h2 S3 = P3/h3 S4 = P4/h4 X = X i Sibi Q = X i Piai

76 08-Perspective.key - September 28, 2016

slide-39
SLIDE 39

X i Pibi/hi = @X i Piai 1 A / B @ X j hjaj 1 C A

Depth Distortion

77 42

Independent of given vertex locations.

bi/hi = ai/ B @ X j hjaj 1 C A ∀i

77

Depth Distortion

78 42

Linear equations in the .

bi/hi = ai/ B @ X j hjaj 1 C A ∀i B @ X j hjaj 1 C A bi/hi − ai = 0 ∀i ai

78 08-Perspective.key - September 28, 2016

slide-40
SLIDE 40

Depth Distortion

79

B @ X j hjaj 1 C A bi/hi − ai = 0 ∀i ai X i ai = X i bi = 1

Not invertible so add some extra constraints. Linear equations in the .

79

Depth Distortion

80

For a line:

a1 = h2bi/(b1h2 + h1b2) a1 = h2h3b1/(h2h3b1 + h1h3b2 + h1h2b3)

For a triangle:

Obvious Permutations for other coefficients.

80 08-Perspective.key - September 28, 2016