Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chap 3 Viewing Pipeline Reading:

Similar presentations


Presentation on theme: "Chap 3 Viewing Pipeline Reading:"— Presentation transcript:

1 Chap 3 Viewing Pipeline Reading:
Angel’s “Interactive Computer Graphics”, Sixth ed. Sections 4.1~4.7 Chap 3 View Pipeline, Comp. Graphics (U) 1

2 Outline View parameters setting Projection in OpenGL
Simple perspective/parallel projection Perspective-projection matrix View volume clipping Chap 3, View Pipeline (CG-U) 2

3 Viewing Pipeline Review…..
projection View transform View-Volume Clipping in homogeneous space Window-viewport mapping Chap 3, View Pipeline (CG-U) 3

4 A Practical Viewing System Review…..
Users specify Parameters for view coordinate system A camera position C a viewing direction vector N an upvector V. View volume information Projection type A view plane distance d (= near clipping plane distance), and a far clipping plane distance f. A view window on the view plane Chap 3, View Pipeline (CG-U) 4

5 Viewing Parameters Review…..
View coordinate system -n World coordinate system Here, without near and far clipping planes Chap 3, View Pipeline (CG-U) 5

6 OpenGL Setting for viewing system -1
In OpenGL, gluLookAt() function alters the model-view matrix gluLookAt(eyex,eyey,eyez,atx,aty,atz,upx,upy,upz) By default a camera at the origin of the word frame pointing in the -z direction the model-view matrix is initially an identity matrix. Chap 3, View Pipeline (CG-U) 6

7 OpenGL Setting for viewing system -2
Look-at function Eyepoint eye, specified in the world frame, determines VRP At point at, specified in the world frame Up vector up gluLookAt(eyex,eyey,eyez,atx,aty,atz,upx,upy,upz) Defines the model-view matrix glMatrixMode(GL_MODELVIEW) glLoadIdentity(); Chap 3, View Pipeline (CG-U) 7

8 OpenGL Setting for viewing system -3
Derive (u,v,n) defined in world coor. sys. n = eye - at Negative of viewing direction N v: view up vector up if up is perpendicular to n u = v x n up may not be perpendicular to n v = up - its projection in direction of n, or First do u = up x n, then v=n x u Chap 3, View Pipeline (CG-U) 8

9 OpenGL Setting for viewing system -4
Chap 3, View Pipeline (CG-U) 9

10 OpenGL Specifying projection information
Properties of camera – focal length of lens or the size of the film plane, i.e., angle of view. Projection parameters Projection type View frustum View plane distance Window or angle of view Front and back clipping plane distances near (>0), far (>0) Chap 3, View Pipeline (CG-U) 10

11 Viewing Pipeline - 1 Review….. View transform
Tview world coord. sys. -> view coord. sys. For simpler and faster clipping and projection Chap 3, View Pipeline (CG-U) 11

12 Viewing Pipeline - 2 Review….. View transform
View transform matrix Tview [ xv, yv, zv, 1] = Tview [xw, yw, zw, 1]T Tview can be written as Tview = B T , where T(-C) translates the world coordinate origin to C. B rotates any vector expressed in the world coordinate system into the view coordinate system by mapping (u,v,n) to (e1,e2,e3). Chap 3, View Pipeline (CG-U) 12

13 Viewing Pipeline - 3 View transform
Chap 3, View Pipeline (CG-U) 13

14 Viewing Pipeline - 4 View transform
Chap 3, View Pipeline (CG-U) 14

15 Viewing Pipeline - 5 Review….. View projection
view coord. sys. -> screen coord. sys. Convert view volume to normalized view volume and then do orthogonal projection Why and How? -1 Mapping view volume to normalized view volume. Easy view-volume clipping and projection, and Standard sized window. -1 Chap 3, View Pipeline (CG-U) 15

16 Projection normalization -1
Eye coordinate system: right-handed system Viewing direction: -z Normalized device coord.: left-handed system Viewing direction: +z Chap 3, View Pipeline (CG-U) 16

17 Projection normalization -2
= Orthogonal projection of the distorted object Perspective projection Chap 3, View Pipeline (CG-U) 17

18 Projection normalization -3
Converts all projections into orthogonal projection by distorting the objects such that the orthogonal projection of the distorted objects is the same as the desired projection of the original objects. Converting view volume to normalized view volume, followed by the orthogonal projection Reasons Easy for view volume clipping Normalization let us clip against a simple cube regardless of type of projection Chap 3, View Pipeline (CG-U) 18

19 Projection normalization -4
Reasons Easy for view volume/back-face culling The nonsingular homogeneous transformation retains meaningful depth value along the projectors that is necessary for HSR. Rather than derive a different projection matrix for each type of projection, we can convert all projections to orthogonal projections with the default view volume, allowing us to use standard transformations in the pipeline Chap 3, View Pipeline (CG-U) 19

20 Projection normalization -5
Reasons This strategy allows us to use standard transformations in the pipeline and makes for efficient clipping Delay final “projection” until end Important for hidden-surface removal to retain depth information as long as possible Chap 3, View Pipeline (CG-U) 20

21 Projection normalization -6
Perspective projection is broken into two parts Perspective transformation + perspective division (back to 3D) Converts the view volume to a normalized view volume, called canonical view volume Objects are distorted in a manner that yields the desired projection through the second step. Orthogonal projection of the distorted objects Need to make sure Correct projection Meaningful depth Chap 3, View Pipeline (CG-U) 21

22 Projection normalization -7
Perspective transformation = Perspective projection = Perspective transform + perspective division + orthographic projection Orthogonal projection of the distorted object Chap 3, View Pipeline (CG-U) 22

23 Simple perspective projection (w/o view volume) -1
In 3D: d is the distance from eye to view plane Nonlinear!! No matrix form!! -d -d -d -d Chap 3, View Pipeline (CG-U) 23

24 Simple perspective projection (w/o view volume) -2
Preserves lines, but it is nonlinear, not affine No meaningful depth is preserved Can actually decompose the perspective projection into perspective projection (in 3D) = perspective transform (linear, in homo. coord.) + perspective division + orthographic proj. [Here, depth is still not preserved!!!] Chap 3, View Pipeline (CG-U) 24

25 Simple perspective projection (w/o view volume) -3
Perspective transform M : in homo. coord. Perspective division (de-homogenization) Chap 3, View Pipeline (CG-U) 25

26 What we are going to do? First derive the perspective transform matrix for a right view volume Show that it does the same projection as the original perspective projection It converts the right view volume to a normalized view volume It preserves a meaningful depth Extend the result to general perspective view volumes Chap 3, View Pipeline (CG-U) 26

27 Perspective normalization transformation -1
For a right view volume specified by Eyepoint: (0, 0, 0), view plane at z=-n Planes: x=±z, y=±z, z=-n, z=-f (f>n) (symmetric, 45o) View window (-n, -n,- n), (n, n, -n) Assuming near plane distance n = view plane distance d Consider the nonsingular matrix α, β unspecified (but nonzero), used to transfer the near and far clipping planes to z=-1 and z=1 z=-f (n,n,-n) (-n,-n,-n) z=-n Chap 3, View Pipeline (CG-U) 27

28 Perspective normalization transformation -2
Apply N’ to point p=[x y z 1]T, we obtain p’=[x’ y’ z’ w’]T : After dividing by w’, we have Consider only (x”, y”), this is the same as the simple perspective projection!! (Note that n=d) And z’’ has a meaningful depth!!!! Chap 3, View Pipeline (CG-U) 28

29 Perspective normalization transformation -3
Orthographic projection of distorted objects = Perspective projection of original objects ! If we apply an orthographic projection along z-axis to N’, we obtain a simple perspective-projection matrix. Don’t care so is z value!!! view plane at z=-d Chap 3, View Pipeline (CG-U) 29

30 Perspective normalization transformation -4
Apply the above projection to p, we have This is exactly the result of a simple perspective projection for view plane at z=-n So, Perspective projection = perspective transformation N’ + orthographic projection Morth Chap 3, View Pipeline (CG-U) 30

31 Perspective normalization transformation -5
N’ is nonsingular and does the following x= ±z is transformed to planes x”= ±n (by putting x= ±z in x”=-nx/z) y= ±z is transformed to planes y”= ±n (by putting y= ±z in y”=-ny/z) z=-n and z=-f are transformed by N’ to the planes that are perpendicular to z-axis, and Chap 3, View Pipeline (CG-U) 31

32 Perspective normalization transformation -6
If we select the transformed clipping planes become, respectively, This choice Preserves the depth order Normalizes the z-values within near and far planes to [-1,1] Chap 3, View Pipeline (CG-U) 32

33 Perspective normalization transformation -7
Chap 3, View Pipeline (CG-U) 33

34 Perspective normalization transformation -8
+ Chap 3, View Pipeline (CG-U) 34

35 Perspective normalization transformation -9
+ + Chap 3, View Pipeline (CG-U) 35

36 Perspective normalization transformation -10
The mapping is nonlinear but preserves the ordering of depths, i.e., if z1 > z2 in the original view volume, then z1”< z2” : Chap 3, View Pipeline (CG-U) 36

37 Perspective normalization transformation -11
Eye coordinate system: right-handed system Viewing direction: -z Normalized device coord.: left-handed system Viewing direction: +z See OpenGL projection matrix at Chap 3, View Pipeline (CG-U) 37

38 Perspective normalization transformation -12
z= -f z2 +z z1 z= 1 z= -n z2’’ z1’’ +x +x z= -1 +z -z Z1 > Z2 Z1’’ < Z2’’

39 Perspective normalization transformation -13
Hidden surface removal works if we first apply the normalization transformation However, the formula implies that the distances are distorted by the normalization which can cause numerical problems especially if the near distance is small Chap 3, View Pipeline (CG-U) 39

40 Perspective normalization transformation -14
Chap 3, View Pipeline (CG-U) 40

41 Perspective normalization transformation -15
Properties of perspective transformation N Preserves lines and flatness. Preserves in-between-ness If a point inside an object, the transformed point will be inside the transformed object. Preserves depth order with its pseudo-depth. Warps objects such that the orthographic projection of the warped object = perspective projection of the original one. Warps the view volume to the canonical view volume Chap 3, View Pipeline (CG-U) 41

42 Perspective normalization transformation -16
N transforms the right view volume to the canonical view volume (after perspective division), and an orthographic projection in the transformed volume yields the same image as does the perspective projection (Consider only x, y-value). N is called perspective transformation matrix. -z +z Chap 3, View Pipeline (CG-U) 42

43 Perspective normalization transformation -17
For an asymmetric, not right view volume (whose face planes are not x=±z, y=±z), we need to do a shear transformation H and a scaling S before applying N. Chap 3, View Pipeline (CG-U) 43

44 Perspective normalization transformation -18
The shear transformation H shears the point to by Since z<0, (l+r)/(2n) must be < 0 when (l+r)<0 to make a move to the right. (l+r)/(2n) must be >0 when (l+r)>0 to make a left move. Chap 3, View Pipeline (CG-U) 44

45 Perspective normalization transformation -19
Review of shear transformation shear the point to Chap 3, View Pipeline (CG-U) 45

46 Perspective normalization transformation -20
Chap 3, View Pipeline (CG-U) 46

47 Perspective normalization transformation -21
The scaling transformation S Scale the sheared view volume defined by to a symmetric-right view volume without changing the near and far planes. Scaling matrix (derived using 4 corners of the window on the near plane) Positive scaling factors!! Chap 3, View Pipeline (CG-U) 47

48 Perspective normalization transformation -22
Scale factor: divide by (r-l)/2, then multiply by n Chap 3, View Pipeline (CG-U) 48

49 Perspective normalization transformation -23
Projection matrix is Precisely the projection matrix that OpenGL creates when gluFrustum() is executed. Chap 3, View Pipeline (CG-U) 49

50 Perspective normalization transformation -24
Chap 3, View Pipeline (CG-U) 50

51 Another derivation of N -1 from pseudo-depth
Simple perspective transformation A pseudo-depth is desired Has a meaningful depth function with the same denominator as x and y, and hence apply the same transformation matrix. so try No depth !! Chap 3, View Pipeline (CG-U) 51

52 Another derivation of N -2 from pseudo-depth
For the transformation We choose and such that the pseudo-depth varies between -1 and 1. Depth=-1 for z=-n, Depth=1 for z=-f Chap 3, View Pipeline (CG-U) 52

53 OpenGL Canonical view volume
A cube whose center is at the origin of the window coordinate and whose faces are given by 6 planes: x=1, -1, y=1, -1, z=1, -1. Canonical view volume is the default in OpenGL (result of glFrustum() and glOrtho()), or obtained by glMatrixMode(GL_projection); glLoadIdentity(); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); z=-1.0 is the near plane z= 1.0 is the far plane Chap 3, View Pipeline (CG-U) 53

54 OpenGL Perspective projection -1
For general symmetric view volume gluPerspective(fovy, aspect, near, far) Produces a projection matrix that converts the symmetric view volume to the symmetric-right one by a scaling transformation S, and to a canonical view volume by a N. Produces P = NS Chap 3, View Pipeline (CG-U) 54

55 OpenGL Perspective projection -2
view plane aspect = w/h Chap 3, View Pipeline (CG-U) 55

56 OpenGL Perspective projection -3
For asymmetric volume glFrustum(l, r, b, t, n, f) Produces a projection matrix that converts the asymmetric view volume to the symmetric-right one by a shear transformation H followed by a scaling transformation S, and to a canonical view volume by a N Produces P = NSH Chap 3, View Pipeline (CG-U) 56

57 Orthogonal projections -1
What is the projection matrix? Move the center of the specified view volume to the center of the canonical view volume by Scale the sides by Chap 3, View Pipeline (CG-U) 57

58 Orthogonal projections -2
Projection matrix Chap 3, View Pipeline (CG-U) 58

59 OpenGL Orthogonal projections -1
OpenGL provides only orthographic projection glOrtho(xmin, xmax, ymin, ymax, near, far) Parameters are identical to those of glFrustum() zmax zmax Zmax = -far zmin = -near zmin zmin Chap 3, View Pipeline (CG-U) 59

60 OpenGL Orthogonal projections -2
Converting general view volume defined by glOrtho(xmin, xmax, ymin, ymax, near, far); Produces a projection matrix that transforms the view volume to the canonical view volume. Vertices inside (outside) the original view volume are transformed by the projection matrix to the vertices inside (outside) the canonical view volume. ,-1) (-1,-1, Chap 3, View Pipeline (CG-U) 60

61 OpenGL Projection normalization
Clip coordinates (homogeneous): has depth Normalized device coord. (3D): has depth Window coordinates (2D): has no depth Projection in OpenGL Part 1: results in a projection matrix. Followed a perspective division to convert vertices to normalized device coordinates. Part 2: do nothing, neglect z. Converts to window coordinates. Chap 3, View Pipeline (CG-U) 61

62 Projection normalization Oblique projection
Not available in OpenGL. Characterized by the angle between the projector and the view plane. Assuming that Near and far planes parallel to the view plane Other faces parallel to the projector’s direction. Chap 3, View Pipeline (CG-U) 62

63 Oblique projection Projection matrix -1
Consider the top and side view Shearing Chap 3, View Pipeline (CG-U) 63

64 Oblique projection Projection matrix -2
Shearing Chap 3, View Pipeline (CG-U) 64

65 Oblique projection Projection matrix -3
For view volume with unit length and origin as center P can be broken into two matrices Morth is orthographic projection, H() is a shear matrix Chap 3, View Pipeline (CG-U) 65

66 Oblique projection Projection matrix -4
Morth Chap 3, View Pipeline (CG-U) 66

67 Oblique projection Projection matrix -5
For general oblique projection A shear of the object by H(θ,Φ) A translation and a scaling (convert the sheared view volume to the canonical view volume) An orthographic projection Projection matrix Chap 3, View Pipeline (CG-U) 67

68 View volume clipping -1 Clip against canonical view volume?
It is parameter free, uses only -1 and 1. Planes are aligned with coordinate axes. Why in homogeneous space? Clipping in HS isn’t completely necessary, but it makes the clipping clean, fast, and simple, at almost no cost. Done after perspective division Signs of x (or y, z) and w are lost. Can tell only if x and w have the same or opposite signs. Chap 3, View Pipeline (CG-U) 68

69 View volume clipping -2 Situations that necessitate clipping in HS involve Particular transformation of objects or the construction of rational surfaces such that the point has a negative w, even the point is in front of the eye. Clipping in 3D is correct only when w>0 In HS: two clip regions A (w>0) & B ( w<0) Negate points with w<0 and clip all against A. Chap 3, View Pipeline (CG-U) 69

70 View volume clipping -2 Uses Cyrus-Beck clipper (a topic in Chap. 4)
Chap 3, View Pipeline (CG-U) 70

71 Viewing Pipeline Summary
projection View transform View-Volume Clipping in homogeneous space Window-viewport mapping Chap 3, View Pipeline (CG-U) 71


Download ppt "Chap 3 Viewing Pipeline Reading:"

Similar presentations


Ads by Google