CS 430536 Computer Graphics I 3 D Viewing

  • Slides: 42
Download presentation
CS 430/536 Computer Graphics I 3 D Viewing Pipeline Week 7, Lecture 13 David

CS 430/536 Computer Graphics I 3 D Viewing Pipeline Week 7, Lecture 13 David Breen, William Regli and Maxim Peysakhov Geometric and Intelligent Computing Laboratory Department of Computer Science Drexel University http: //gicl. cs. drexel. edu 1

Overview • • Projection Mathematics Canonical View Volume Parallel Projection Pipeline Perspective Projection Pipeline

Overview • • Projection Mathematics Canonical View Volume Parallel Projection Pipeline Perspective Projection Pipeline Lecture Credits: Most pictures are from Foley/Van. Dam; Additional and extensive thanks also goes to those credited on individual slides 2 Pics/Math courtesy of Dave Mount @ UMD-CP 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

Projection Mathematics • What is the set of transformations needed to map 3 D

Projection Mathematics • What is the set of transformations needed to map 3 D lines/planes onto a 2 D screen positioned in 3 D? • Basic procedure – 4 D homogeneous coordinates to – 3 D homogeneous coordinates for – every primitive in – the 3 D view volume 3

Projection Mathematics We present 4 x 4 matrices to be used for implementing projections

Projection Mathematics We present 4 x 4 matrices to be used for implementing projections • Perspective Projections – How much to scale objects as a function of distance? • Parallel Projections – (simplified case) Just chop out the z coordinate 4

The Perspective Projection Determining scale • Consider – Point P – Projected onto projection

The Perspective Projection Determining scale • Consider – Point P – Projected onto projection plane as point Pp • Idea: compute ratios via similar triangles 5 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

The Perspective Projection • In the x direction ratio is 6 1994 Foley/Van. Dam/Finer/Huges/Phillips

The Perspective Projection • In the x direction ratio is 6 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

The Perspective Projection • In the y direction ratio is 7 1994 Foley/Van. Dam/Finer/Huges/Phillips

The Perspective Projection • In the y direction ratio is 7 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

The Perspective Projection • Homogenous perspective projection matrix Assumes VPN is z axis. 8

The Perspective Projection • Homogenous perspective projection matrix Assumes VPN is z axis. 8 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

The Perspective Projection • Homogenous perspective projection 9 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

The Perspective Projection • Homogenous perspective projection 9 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

The Perspective Projection • Homogenous perspective projection to 3 D 10 1994 Foley/Van. Dam/Finer/Huges/Phillips

The Perspective Projection • Homogenous perspective projection to 3 D 10 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

The Orthographic Projection Assumes DOP is z axis. Just makes z axis 0 11

The Orthographic Projection Assumes DOP is z axis. Just makes z axis 0 11 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

Implementing Projections (Foley et al. ) … a sequence of matrix operations and a

Implementing Projections (Foley et al. ) … a sequence of matrix operations and a clipping procedure… 12 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

Implementing Projections (Foley et al. ) 1. 2. 3. 4. Extend 3 D coordinates

Implementing Projections (Foley et al. ) 1. 2. 3. 4. Extend 3 D coordinates to homogenous coords Apply normalizing transformation, Npar or Nper Divide by W to map back down to 3 D Clip in 3 D against canonical view volume • 5. 6. 7. 8. parallel or perspective view volume Extend 3 D coordinates back to homogenous Perform parallel projection using Mort or Perform perspective projection Mper Divide by W to map from homogenous to 2 D coordinates (division effects perspective projection) Translate and scale (in 2 D) to device coordinates 13

Canonical View Volume: Parallel Projection • Defined by 6 planes: – – – x=1

Canonical View Volume: Parallel Projection • Defined by 6 planes: – – – x=1 x = -1 y=1 y = -1 z=0 z = -1 • Easy to clip against 14 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

Canonical View Volume: Perspective Projection • Defined by 6 planes: – – – x=z

Canonical View Volume: Perspective Projection • Defined by 6 planes: – – – x=z x = -z y=z y = -z z = zmin z = -1 • Easy to clip against 15 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

Parallel Projection Pipeline Transforming an arbitrary view volume into the canonical one 1. 2.

Parallel Projection Pipeline Transforming an arbitrary view volume into the canonical one 1. 2. 3. 4. Translate VRP to the origin Rotate so VPN becomes z, VUP becomes y and u becomes x Shear to make direction of the projection become parallel to z Translate and scale into a canonical view volume 16

1. Translate VRP to the origin • Simple translation T(-VRP) Top Projection Off-Axis Projection

1. Translate VRP to the origin • Simple translation T(-VRP) Top Projection Off-Axis Projection 17 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

2. Rotate • • VPN rotated to z VUP rotated to y VRP, VPN

2. Rotate • • VPN rotated to z VUP rotated to y VRP, VPN & VUP in World Coordinates (x, y, z) 18 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

2. Rotate 19

2. Rotate 19

3. Shear • Computing direction of projection DOP PRP in VRC Coordinates (u, v,

3. Shear • Computing direction of projection DOP PRP in VRC Coordinates (u, v, n) 20 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

3. Shear (Cont. ) • For Shxy z’=z, x’=x+z • shx, y’=y+z • shy

3. Shear (Cont. ) • For Shxy z’=z, x’=x+z • shx, y’=y+z • shy 21 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

3. Shear (Cont) • For Shxy z’=z, x’=x+z • shx, y’=y+z • shy •

3. Shear (Cont) • For Shxy z’=z, x’=x+z • shx, y’=y+z • shy • Find Shxy such that: Old Foley et al. is wrong! DOP’ = [0, 0, DOPz, 0]T = Shxy • DOP 0 = DOPx + DOPz • shx , 0 = DOPy + DOPz • shy 22 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

3. Shear (Finally) • Given • We can compute the SHpar matrix 24

3. Shear (Finally) • Given • We can compute the SHpar matrix 24

3. Shear 25

3. Shear 25

4. Translate and Scale • Translate the center of the volume to the origin

4. Translate and Scale • Translate the center of the volume to the origin • Scaling to 2 x 2 x 1 Foley et al. is wrong! • Needed for 3 D clipping Top Projection Off-Axis Projection 26 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

Parallel Projection View Volume Transformation Npar = (Spar • (Tpar • (SHpar • (R

Parallel Projection View Volume Transformation Npar = (Spar • (Tpar • (SHpar • (R • T(-VRP))))) • Apply to all model vertices • P’ = Npar P 27 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

Parallel Projection Summary 28

Parallel Projection Summary 28

Perspective Projection Pipeline Transforming an arbitrary view volume into the canonical one 1. 2.

Perspective Projection Pipeline Transforming an arbitrary view volume into the canonical one 1. 2. 3. 4. 5. Translate VRP to the origin Rotate so VPN becomes z, VUP becomes y and u becomes x Translate COP to origin Shear so volume centerline becomes z axis Scale into a canonical view volume for clipping 29

1. Translate VRP to the origin • Simple translation T(-VRP) VRP, VPN & VUP

1. Translate VRP to the origin • Simple translation T(-VRP) VRP, VPN & VUP in World Coordinates (x, y, z) Top Projection Off-Axis Projection 30 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

2. Rotate • • Top Projection VPN rotated to z VUP rotated to y

2. Rotate • • Top Projection VPN rotated to z VUP rotated to y Off-Axis Projection Top Projection Off-Axis Projection 31 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

3. Translate • Simple translation T(-PRP) PRP in VRC Coordinates (u, v, n) Top

3. Translate • Simple translation T(-PRP) PRP in VRC Coordinates (u, v, n) Top Projection Off-Axis Projection 32 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

4. Shear • Goal is to transform the center line to the z axis

4. Shear • Goal is to transform the center line to the z axis • Same as parallel projection • Shear matrix is the same! Top Projection Off-Axis Projection 33 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

5. Scaling • We can define VRP after transformation as – VRP’= SHpar •

5. Scaling • We can define VRP after transformation as – VRP’= SHpar • T(-PRP) • [0, 0, 0, 1]T • vrp’z = -prpn since shear does not affect z coordinates • First, we scale differentially in x and y to set plane slopes to 1 and -1 • Second, we scale uniformly by Top Projection Off-Axis Projection 34 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

5. Scaling (Cont) • We can combine the transformations X, Y scaling 35 1994

5. Scaling (Cont) • We can combine the transformations X, Y scaling 35 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

5. Scaling (Cont) • We can combine the transformations X, Y scaling 36 1994

5. Scaling (Cont) • We can combine the transformations X, Y scaling 36 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

Important Projection Info • Back clipping plane is z = -1 • Front clipping

Important Projection Info • Back clipping plane is z = -1 • Front clipping plane is • Projection plane is 37

Perspective Projection Pipeline Nper = (Sper • (SHpar • (T(-PRP) • (R • T(-VRP)))))

Perspective Projection Pipeline Nper = (Sper • (SHpar • (T(-PRP) • (R • T(-VRP))))) • Apply to all model vertices • P’ = Nper P 39 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

Perspective Projection Summary 40

Perspective Projection Summary 40

Summary of 3 D Transforms • We know how to take any projection and

Summary of 3 D Transforms • We know how to take any projection and convert it into a canonical View Volume • 3 D edges can be clipped against it and projected onto screen 41 1994 Foley/Van. Dam/Finer/Huges/Phillips ICG

Implementing Projections Without 3 D Clipping 1. Extend 3 D coordinates to homogeneous coordinates

Implementing Projections Without 3 D Clipping 1. Extend 3 D coordinates to homogeneous coordinates 2. Apply normalizing transformation, Npar or Nper 3. Perform trivial reject test with view volume 4. Perform parallel projection or perform perspective projection 5. Clip against 2 D “world” (view plane) window 6. Translate and scale (in 2 D) to device coordinates (i. e. into viewport) 42

Transformed Window • Parallel Projection © (-1, -1) (1, 1) • Perspective Projection ©

Transformed Window • Parallel Projection © (-1, -1) (1, 1) • Perspective Projection © (-|zproj|, -|zproj|) (|zproj|, |zproj|) • Use these for world window parameters in viewport mapping and 2 D clipping 43

Programming assignment 4 • • Read SMF file Implement parallel projection Implement perspective projection

Programming assignment 4 • • Read SMF file Implement parallel projection Implement perspective projection Draw projected and clipped polygon edges 44