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.

Slides:



Advertisements
Similar presentations
Computer Graphics - Viewing -
Advertisements

GR2 Advanced Computer Graphics AGR
Defining the Viewing Coordinate System
Three Dimensional Viewing
Projection.
Three-Dimensional Viewing Sang Il Park Sejong University Lots of slides are stolen from Jehee Lee’s.
Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing
CS485/685 Computer Vision Prof. George Bebis
Viewing Transformations
Viewing Doug James’ CG Slides, Rich Riesenfeld’s CG Slides, Shirley, Fundamentals of Computer Graphics, Chap 7 Wen-Chieh (Steve) Lin Institute of Multimedia.
4.1si31_2001 SI31 Advanced Computer Graphics AGR Lecture 4 Projection Clipping Viewport Transformation.
1 Chapter 5 Viewing. 2 Perspective Projection 3 Parallel Projection.
Projection Projection - the transformation of points from a coordinate system in n dimensions to a coordinate system in m dimensions where m
Introduction to 3D viewing 3D is just like taking a photograph!
12.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 12 – 3D Graphics Transformation Pipeline: Projection and Clipping.
I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam September 23, D Viewing III 3D Viewing III.
I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam September 22, D Viewing III Kansas State University CIS 636 Fundamentals.
Viewing and Projections
C O M P U T E R G R A P H I C S Jian Chen January 15, D Viewing II 1/23 3D Viewing II By Andries van Dam.
Advanced Computer Graphics Three Dimensional Viewing
Part II (The Synthetic Camera)
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
Transformation & Projection Feng Yu Proseminar Computer Graphics :
1 2D Transformations 几何变换. 2 What is a transformation? A transformation is an operation that transforms or changes a shape (line, drawing etc.) There.
CS559: Computer Graphics Lecture 9: Projection Li Zhang Spring 2008.
Viewing Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Graphics Graphics Korea University cgvr.korea.ac.kr 3D Viewing 고려대학교 컴퓨터 그래픽스 연구실.
C O M P U T E R G R A P H I C S Jian Chen January 15, 2010 Viewing III 1/42 3D Viewing III By Andries van Dam.
CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica.
Computer Graphics Bing-Yu Chen National Taiwan University.
CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 5.
Computing & Information Sciences Kansas State University CIS 536/636 Introduction to Computer Graphics Lecture 3 of 41 William H. Hsu Department of Computing.
10/3/02 (c) 2002 University of Wisconsin, CS 559 Last Time 2D Coordinate systems and transformations.
CS 450: COMPUTER GRAPHICS PROJECTIONS SPRING 2015 DR. MICHAEL J. REALE.
I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam 3D Viewing I CIS 736 Computer Graphics Review of Basics 2 of 5: 3D Viewing.
OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.
University of North Carolina at Greensboro
Basic Perspective Projection Watt Section 5.2, some typos Define a focal distance, d, and shift the origin to be at that distance (note d is negative)
Jinxiang Chai CSCE 441 Computer Graphics 3-D Viewing 0.
Three-Dimensional Viewing
Three-Dimensional Viewing Hearn & Baker Chapter 7
Foundations of Computer Graphics (Spring 2012) CS 184, Lecture 5: Viewing
12/24/2015 A.Aruna/Assistant professor/IT/SNSCE 1.
©2005, Lee Iverson Lee Iverson UBC Dept. of ECE EECE 478 Viewing and Projection.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Classical Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Rendering Pipeline Fall, D Polygon Rendering Many applications use rendering of 3D polygons with direct illumination.
Classical Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Coordinate Systems Lecture 1 Fri, Sep 2, The Coordinate Systems The points we create are transformed through a series of coordinate systems before.
Viewing and Projection. The topics Interior parameters Projection type Field of view Clipping Frustum… Exterior parameters Camera position Camera orientation.
Viewing Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Viewing. Classical Viewing Viewing requires three basic elements - One or more objects - A viewer with a projection surface - Projectors that go from.
I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S CIS 736 Computer Graphics Lecture 5 of 42 Review of Basics 4 of 5: 3-D Viewing III and Intro.
Outline 3D Viewing Required readings: HB 10-1 to 10-10
Computer Graphics Projections.
PROJECTIONS PROJECTIONS 1. Transform 3D objects on to a 2D plane using projections 2 types of projections Perspective Parallel In parallel projection,
Three Dimensional Viewing
Visible Surface Detection
Viewing Viewing and viewing space (camera space)
Rendering Pipeline Fall, 2015.
Computer Graphics CC416 Week 14 3D Graphics.
3D Viewing cgvr.korea.ac.kr.
CSCE 441 Computer Graphics 3-D Viewing
CENG 477 Introduction to Computer Graphics
Three Dimensional Viewing
OpenGL 2D Viewing Pipeline
3D Graphics.
Viewing (Projections)
Viewing (Projections)
THREE-DIMENSIONAL VIEWING II
THREE-DIMENSIONAL VIEWING
Presentation transcript:

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

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

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.

4 Coordinate Systems Object coordinate systems. World coordinates. View Volume Screen coordinates. Raster Transform Project Clip Rasterize

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.

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.

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 of Projection. Centre of Projection at infinity Parallel Perspective

8 A Taxonomy of projections Planar geometric projections. ParallelPerspective Orthographic Oblique1 point 2 point 3 point Axonometric Isometric CavalierCabinet Elevations

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.

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

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)

12 Perspective projections ● Lines parallel to a principal axis converge at an axis vanishing point. ■ Perspective categorized according to the number of such points. ■ Corresponds to the number of axis cut by the projection plane. x y z z x y Projection plane x z y

13 1-point projection Projection plane cuts 1 axis only.

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

15 2-point perspective y z x Projection plane

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

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.

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}

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?

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”

21 Our Camera Model

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

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

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

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

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

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:

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

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

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

31 Orthographic Camera Model ● Width and height replaces viewing angles ■ Both width angle and height angle are effectively zero

32 Coordinate Systems Object coordinate systems. World coordinates. View Volume Screen coordinates. Raster Transform Project Clip Rasterize

33 Canonical View Volume

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

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

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

37 Camera Coordinate System ● Computing n ■ Opposite to look vector L, normalized

38 Camera Coordinate System ● Computing v ■ Projection of up vector U onto the camera plane, normalized +

39 Camera Coordinate System ● Computing u

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 + +

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

42 Step 1 ● First, translate the eye point P to the origin ■ Homogenous coordinates! Easy to compose transformation as matrix product

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:

44 Step 1 (cont.) ● Simplify our notation: ● Solve for the rotation matrix ■ M is ortho-normal, meaning Therefore,

45 After Step 1 ● Eye point at origin, looking down negative z axis

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

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.

48 Step 2 (cont.) ● Now, the far plane corners are at {±1, ±1, −1}

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:

50 Step 2 (cont.)

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

52 Putting Together

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

54 Line Clipping

55 Line Clipping

56 Object Clipping

57 Projecting ● Dropping z coordinate ■ Resulting points have range: −1 ≤ x ≤ 1, −1 ≤ y ≤ 1

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)

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