1 of 80

1

Projection

Tong-Yee Lee

2 of 80

2

Projection

3 of 80

3

Projection

4 of 80

4

View frustrum

culling

5 of 80

Readings

  • Computer Graphics Using OpenGL by F.S Hill, J.R.
  • Chapter 7

5

6 of 80

From view to projection�i.e., perspective and parallel

6

From right hand to left hand

7 of 80

Perspective(透視投影)v.s. Orthographic (正投影) projection

7

From right hand to left hand

8 of 80

8

9 of 80

Orthographic (正投影) projection

9

From right hand to left hand

10 of 80

Parallel and Perspective Projection

10

11 of 80

11

Near clipping plane

12 of 80

Perspective view to Normalized Coordinates

12

13 of 80

13

14 of 80

14

Oblique parallel projection

15 of 80

15

16 of 80

16

Parallel

Volume

Rendering

17 of 80

17

18 of 80

18

19 of 80

Multi-view Orthographic

20 of 80

20

Zs is lost , so it can not be used for Visible Surface Removal!!!

21 of 80

21

Note that projection vector d (dx, dy,dz,0) is specified from -Z toward Z in the eye space coordinate

d=(0,0,1,0)

d (dx, dy,dz,0)

22 of 80

22

23 of 80

23

What OpenGL wants is:

After projection, the image

space (after division)

become …….

  1. Left hand system
  2. -1<=xs, ys, zs <=1

Regardless

of parallel

projection or

perspective

projection!!!

24 of 80

Parallel Projection in OpenGL glortho(l,r,b,t,n,f)

24

+X

-Z

r

l

(x, 0)

+X

-Z

+1

-1

Translate and Scale

d=(0,0,1,0)

25 of 80

25

negate Z

Parallel Projection Matrix in OpenGL

Image space in

right hand system

Image space in left hand system (OpenGL)

26 of 80

26

This row will not affect the projection!!!

Only affect the Zs value!

And substitute the following to solve A and B

27 of 80

27

Final Parallel Projection Matrix in OpenGL

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

Zs is not lost

Zs is lost

Zs is good for

Hidden Surface

Removal !!!

So, we want

this model!!

In parallel projection, w term also is 1.We do not need division!!

28 of 80

28

What OpenGL wants is:

After projection, the image

space (after division)

become …….

  1. Left hand system
  2. -1<=xs, ys, zs <=1

Regardless of parallel projection or perspective projection!!!

29 of 80

29

Object is distorted in screen

space but the projection result

is still same!!

30 of 80

30

31 of 80

31

(針孔成像模型)

鏡頭焦距 

32 of 80

32

33 of 80

33

34 of 80

34

35 of 80

35

36 of 80

36

37 of 80

37

38 of 80

38

39 of 80

39

Zs is lost again!!

OR

Remember

this!!

40 of 80

40

41 of 80

41

42 of 80

42

In the image (screen)

space coordinate

(left hand system)

(after division)

In the eye space coordinate

(right-hand system)

43 of 80

43

Object is distorted in screen space

but the projection result is still same!!

44 of 80

44

-

45 of 80

3D NDC to 2D Image (Near) Plane

Chapter 14

Resulting image �on the near plane

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer

46 of 80

46

Note

(1) X, Y, Z axis are

named u,v,w in the following

discussions!

fovx and fovy are assumed

to be equal

47 of 80

47

Note that the representation

of point transform is different

from the previous one in the

following discussions:

For example:

Old

New

48 of 80

48

49 of 80

49

Good when we choose a canonical

screen space volume or clipping volume

Clipping Space Coordinate

50 of 80

50

In clipping coordinate space, we perform clipping.

We can therefore save division if points are outside

the frustum of clipping coordinate space

We will teach clipping soon!

51 of 80

51

52 of 80

52

Something Interesting …Clipping

What does it imply?

Remember if a point is behind eye, we can not

see it!!. i.e., w > 0, means it is behind eye.

So, we can check the fourth item (before division).

If the fourth item is negative, this point is behind

the eye point.

53 of 80

53

We neglect scales at

X and Y first and we

Will compute them latter

54 of 80

54

the near plane (w = - n ) goes to the face w = -1 of the image space cube

, and the face defined by the far plane (w = - f ) goes to the face w = 1 of

the image space cube.

That’s

(0,0,-n)P = (0,0,-1)

(0,0,-f)P = (0,0,1)

Note that in image space

(after division)

55 of 80

55

56 of 80

56

We want to map them to (0,0,-1) and (0,0,1)

So,

57 of 80

57

We should also note that

(1) the above P has transformed any

point to image space (left hand system (n=-1, f = 1)).

So, as Zs is larger, it means it is far away from camera.

(2) Point in image space will not lost its Zs component!!

Zs is lost

58 of 80

58

59 of 80

59

So, after division, we get :

But, we want this term

to be 1.

60 of 80

Scale can help ……….

60

Before we apply projection, we scale X, Y …………..

61 of 80

61

Re-organize our Representation !!!!

Eye space

Clipping space

division

Image (screen) space

fovx and fovy

can be different!!

62 of 80

62

Furthermore ………………

gluFrustum (l, r, b, t, n, f)

when r = - l , b = -t , we will have

a symmetric frustrum

-Z

-X

eye

Z = - n

-r

r

63 of 80

63

Final Projection Matrix Used in OpenGL gluPerspective(angle,aspect,n,f)

  • We use angle and aspect ratio to find l, r, t, b by the following…..

-Z

+X

eye

Z = - n

l

r

64 of 80

64

65 of 80

65

Programmer must responsibly specify correct ratio

in viewport glViewport(x,y, w,h).

Otherwise, the result will be distorted.

66 of 80

66

67 of 80

67

For example: when zc = 0;

Eye (Xc,Yc,Zc,1) = (0,0,0,1)

P(Eye): z’c = -2fn/(f-n), w’c=0;

Inside –w’c <=z’c<=w’c

So, P(EYE) is outside, so, we avoid division by zero

68 of 80

68

Normalized Device Coordinate

To Window Coordinate

  • glviewport(lv,bv,w,h)
  • rv=lv+(w-1), tv=bv+(h-1)
  • Zs will be translated and scaled to be (0,1)

69 of 80

69

Viewport transformation

70 of 80

70

71 of 80

Mapping from Window Coordinate to Monitor Screen Coordinate

  • Usually done by your window system for you.
  • Screen Coordinate: (0,0) is at left-top corner and y is increasing downward the screen

71

(0,0)

(xmax,ymax)

Monitor Screen

Coordinate

(0,0)

(xmax,ymax)

Window

coordinate

72 of 80

glutInitWindowsize(w,h)�glutInitWindowposition(x,y)

72

(x,y)

w

h

(0,0)

Monitor

Screen

window

73 of 80

73

(0,0)

(xmax’,ymax’)

Monitor Screen

Coordinate

(xmax,ymax)

Window

coordinate

(x,y)

(0,0)

w

h

w

h

(x1,y1)

(x2,y2)

74 of 80

74

75 of 80

75

View Frustum Culling

76 of 80

Depth Buffer

76

77 of 80

Z-buffer

77

78 of 80

Z-buffer

78

For trivial setting Zn, Zf value such as Zn = 0, Zf = 10000000.

Then, each polygon’s Z-value of above equation is close to 1, so we need more depth resolution (i.e., more bits per pixel to represent Z-buffer value) of Z-buffer to make difference. Otherwise, the about the value of above equation is almost the same (i.e., close to 1, so we can not make difference).

79 of 80

Z-buffer

79

80 of 80

80

gluPerspective(60.0, 1.3, 1.0, 300000000.0);

gluPerspective(60.0, 1.3, 100000000.0, 300000000.0);

A good advice: first check the bounding box containing your scene and then make your near plane away from your eye and close to far plane as possibly as you could.