CSE528 Computer Graphics: Theory, Algorithms, and Applications

Similar documents
CSE328 Fundamentals of Computer Graphics

INTRODUCTION TO COMPUTER GRAPHICS. cs123. It looks like a matrix Sort of. Viewing III. Projection in Practice 1 / 52

INTRODUCTION TO COMPUTER GRAPHICS. It looks like a matrix Sort of. Viewing III. Projection in Practice. Bin Sheng 10/11/ / 52

Lecture 3 Sections 2.2, 4.4. Mon, Aug 31, 2009

Lecture 4. Viewing, Projection and Viewport Transformations

Notes on Assignment. Notes on Assignment. Notes on Assignment. Notes on Assignment

CSE452 Computer Graphics

CMSC427 Transformations II: Viewing. Credit: some slides from Dr. Zwicker

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

Today. Rendering pipeline. Rendering pipeline. Object vs. Image order. Rendering engine Rendering engine (jtrt) Computergrafik. Rendering pipeline

Three-Dimensional Viewing Hearn & Baker Chapter 7

CSC 305 The Graphics Pipeline-1

Models and The Viewing Pipeline. Jian Huang CS456

3D Polygon Rendering. Many applications use rendering of 3D polygons with direct illumination

Viewing. Reading: Angel Ch.5

CS 4204 Computer Graphics

THE VIEWING TRANSFORMATION

CSE 167: Introduction to Computer Graphics Lecture #4: Vertex Transformation

1 OpenGL - column vectors (column-major ordering)

Chap 3 Viewing Pipeline Reading: Angel s Interactive Computer Graphics, Sixth ed. Sections 4.1~4.7

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Rasterization Overview

CSE 167: Lecture #4: Vertex Transformation. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

3D Viewing. CS 4620 Lecture 8

Computer Graphics 7: Viewing in 3-D

Clipping and Scan Conversion

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

Graphics pipeline and transformations. Composition of transformations

Evening s Goals. Mathematical Transformations. Discuss the mathematical transformations that are utilized for computer graphics

Viewing with Computers (OpenGL)

Perspective transformations

CS230 : Computer Graphics Lecture 6: Viewing Transformations. Tamar Shinar Computer Science & Engineering UC Riverside

Math background. 2D Geometric Transformations. Implicit representations. Explicit representations. Read: CS 4620 Lecture 6

Chapter 8 Three-Dimensional Viewing Operations

Computer Graphics. P05 Viewing in 3D. Part 1. Aleksandra Pizurica Ghent University

2D/3D Geometric Transformations and Scene Graphs

3D Viewing. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 9

Clipping & Culling. Lecture 11 Spring Trivial Rejection Outcode Clipping Plane-at-a-time Clipping Backface Culling

COMP Computer Graphics and Image Processing. a6: Projections. In part 2 of our study of Viewing, we ll look at. COMP27112 Toby Howard

Vector Algebra Transformations. Lecture 4

CS602 Midterm Subjective Solved with Reference By WELL WISHER (Aqua Leo)

COMP3421. Introduction to 3D Graphics

Transformation Pipeline

Computer Graphics. Bing-Yu Chen National Taiwan University The University of Tokyo

Game Architecture. 2/19/16: Rasterization

Graphics Pipeline 2D Geometric Transformations

CS 325 Computer Graphics

Overview. By end of the week:

So we have been talking about 3D viewing, the transformations pertaining to 3D viewing. Today we will continue on it. (Refer Slide Time: 1:15)

Viewing and Projection

Announcements. Submitting Programs Upload source and executable(s) (Windows or Mac) to digital dropbox on Blackboard

3D Graphics for Game Programming (J. Han) Chapter II Vertex Processing

CS 112 The Rendering Pipeline. Slide 1

3.1 Viewing and Projection

COMP3421. Introduction to 3D Graphics

Overview of Projections: From a 3D world to a 2D screen.

Geometry: Outline. Projections. Orthographic Perspective

Viewing and Projection

Viewing. Part II (The Synthetic Camera) CS123 INTRODUCTION TO COMPUTER GRAPHICS. Andries van Dam 10/10/2017 1/31

GEOMETRIC TRANSFORMATIONS AND VIEWING

Computer Viewing. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

COMP3421. Introduction to 3D Graphics

3D Viewing Episode 2

Chap 7, 2008 Spring Yeong Gil Shin

Today. Today. Introduction. Matrices. Matrices. Computergrafik. Transformations & matrices Introduction Matrices

Geometric Transformations

Projection and viewing. Computer Graphics CSE 167 Lecture 4

For each question, indicate whether the statement is true or false by circling T or F, respectively.

Viewing and Projection

Figure 1. Lecture 1: Three Dimensional graphics: Projections and Transformations

SUMMARY. CS380: Introduction to Computer Graphics Projection Chapter 10. Min H. Kim KAIST School of Computing 18/04/12. Smooth Interpolation

Perspective Mappings. Contents

COMP3421. Vector geometry, Clipping

(Refer Slide Time: 00:04:20)

OpenGL Transformations

One or more objects A viewer with a projection surface Projectors that go from the object(s) to the projection surface

Motivation. What we ve seen so far. Demo (Projection Tutorial) Outline. Projections. Foundations of Computer Graphics

Projections. Brian Curless CSE 457 Spring Reading. Shrinking the pinhole. The pinhole camera. Required:

UNIT 2 2D TRANSFORMATIONS

3D Geometry and Camera Calibration

Advanced Computer Graphics Transformations. Matthias Teschner

Fundamental Types of Viewing

COMP 175 COMPUTER GRAPHICS. Ray Casting. COMP 175: Computer Graphics April 26, Erik Anderson 09 Ray Casting

Homework #1. Displays, Alpha Compositing, Image Processing, Affine Transformations, Hierarchical Modeling

15. Clipping. Projection Transformation. Projection Matrix. Perspective Division

Lecture 5: Transforms II. Computer Graphics and Imaging UC Berkeley CS184/284A

CSE 167: Introduction to Computer Graphics Lecture #5: Projection. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2017

Classical and Computer Viewing. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

To Do. Demo (Projection Tutorial) Motivation. What we ve seen so far. Outline. Foundations of Computer Graphics (Fall 2012) CS 184, Lecture 5: Viewing

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

Rendering If we have a precise computer representation of the 3D world, how realistic are the 2D images we can generate? What are the best way to mode

To Do. Motivation. Demo (Projection Tutorial) What we ve seen so far. Computer Graphics. Summary: The Whole Viewing Pipeline

MET71 COMPUTER AIDED DESIGN

Camera Model and Calibration

MODULE - 7. Subject: Computer Science. Module: Other 2D Transformations. Module No: CS/CGV/7

Viewing. Announcements. A Note About Transformations. Orthographic and Perspective Projection Implementation Vanishing Points

1 Transformations. Chapter 1. Transformations. Department of Computer Science and Engineering 1-1

Prof. Feng Liu. Fall /19/2016

CSE 690: GPGPU. Lecture 2: Understanding the Fabric - Intro to Graphics. Klaus Mueller Stony Brook University Computer Science Department

Specifying Complex Scenes

Transcription:

CSE528 Computer Graphics: Theory, Algorithms, and Applications Hong Qin Stony Brook University (SUNY at Stony Brook) Stony Brook, New York 11794-2424 Tel: (631)632-845; Fax: (631)632-8334 qin@cs.stonybrook.edu http://www.cs.stonybrook.edu/~qin

Geometric Projections From 3D to 2D Maps points from camera coordinate system to the screen (image plane of the virtual camera). Planar Geometric Projections Parallel Perspective Oblique Orthographic Image Plane Image Plane Center of Projection ST NY (COP) BR K

Basic Camera Attributes

Parallel Orthographic Projection Preserves X and Y coordinates. Preserves both distances and angles. Image Plane

Parallel Orthographic Projection 1 1 1 1 1 z y x z y x p p p x (x, y, z) z y x p = x y p = y z p = (x p, y p, ) z =

Perspective Projection Only preserves parallel lines that are parallel to the image plane. Line segments are shorten by distance. Image Plane Center of Projection (COP)

Perspective Projection y (x, y, z) (x p, y p, z p ) z = d z x

Perspective Projection z p = d x p = (x d) / z (x p, d) (x, z) z = d x z

Perspective Projection z p = d y p = (y d) / z z y (y p, d) (y, z) z = d

Specify a View Volume Reduce degrees of freedom to make the operations easier; four steps to specify a view volume 1. Position the camera (and therefore its view/image plane), the center of projection 2. Orient the camera to point at what you want to see, the view direction and the view-up direction 3. Define field of view: perspective: aspect ratio of image and angle of view: between wide angle, normal, and zoom parallel: width and height 4. Choose perspective or parallel projection

Specifying Arbitrary 3D Views Definition of view volume (the visible part of the virtual world) specified by camera s position and orientation Position (a point) Look and Up vectors Shape of view volume specified by horizontal and vertical view angles front and back clipping planes Coordinate Systems world coordinates standard right-handed xyz 3-space camera coordinates camera-space right-handed coordinate system (u, v, n); origin at Position and axes rotated by orientation; used for transforming arbitrary view into canonical view

Defining the Parallel View Volume glortho(xmin, xmax, ymin, ymax, near, far) y (x max, y max, -far) (x min, y min, -near) View Volume z x

View Volume (Parallel Projection) For example, Orthographic parallel projection: Truncated view volume Cuboid (not exactly a cube!) How about oblique projection??? y Near distance Far distance Look vector Width Height x Up vector z Position

Defining the Perspective View Volume y (x max, y max, -far) (x min, y min, -near) z x

Defining the Perspective View Volume gluperspective(fovy, aspect, near, far) y w h fov z x

View Volume (Perspective Projection) Perspective projection: Truncated pyramid View frustum How about oblique projection???

Coordinate Systems

3D Viewing (Computer Graphics Pipeline) We will need to revisit the concept and the techniques for defining 3D viewing coordinate system and specifying 3D view volume for graphics pipeline. We will need to convert 3D view volume (both parallel projection and perspective projection) to a canonical, normalized, device-independent coordinate system, before we can display the final picture in the specified viewport on the display device!

Coordinate Systems (Computer Graphics Pipeline) 1. Objects in model coordinates are transformed into 2. World coordinates, which are transformed into 3. View coordinates, which are transformed into 4. Normalized device coordinates, which are transformed into 5. Display coordinates, which correspond to pixel positions on the screen 6. Transformations from one coordinate system to another take place via coordinate transformations, which we have already discussed in previous lectures

Normalizing to the Device Independent View Volume Goal: transform arbitrary view coordinate system to the canonical view volume (device independent), maintaining relationship between view volume and the normalized, device independent coordinate system, then take picture for parallel view volume, transformation is affine : consisting of linear transformations (rotations and scales) and translation/shift in case of a perspective view volume, it also contains a non-affine perspective transformation that turns a frustum into a parallel view volume, a cuboid composite transformation to transform arbitrary view volume to the canonical view volume, named the normalizing transformation, is still a 4x4 homogeneous matrix that typically has an inverse easy to clip against this canonical view volume; clipping planes are axisaligned! projection using canonical view volume is even easier: just omit z- coordinates for oblique parallel projection, a shearing transform is part of composite transform, to de-oblique view volume FIRST!!!

Canonical View Volume This is the key for today s lecture Up Look z Up parallel projection sits at origin: Position = (,, ) looks along negative z-axis: Look vector = (,, 1) oriented upright: Up vector = (, 1, ) film plane extending from 1 to 1 in x and y

Specify Arbitrary 3D Viewing Coordinate System The original of coordinate system Three independent directions (mutually perpendicular with each other)

Viewing Coordinate System We have specified arbitrary view with viewing parameters Problem: map arbitrary view specification to 2D image of scene. This is hard, both for clipping and for projection Solution: reduce to a simpler problem and solve it step-by-step Note: Look vector along negative (not positive) z-axis is arbitrary but makes math easier!

Viewing in Three Dimension The key: Mathematics of projections and its matrix operations How to produce 2D image from view specification? It is relatively easy to specify Canonical view volume (3D parallel projection cuboid) Canonical view position (camera at the origin, looking along the negative z-axis) A step-by-step approach 1. get all parameters for view specification 2. transform from the specified view volume into canonical view volume (This is the key step) 3. using canonical view, clip, project, and rasterize scene to make 2D image

From World Coordinate System to View Coordinate System We now know the view specification: Position, Look vector, and Up vector Need to derive an affine transformation from these parameters to translate and rotate the canonical view into our arbitrary view the scaling of the image (i.e. the cross-section of the view volume) to make a square cross-section will happen at a later stage, as will the clipping operation Translation is easy to find: we want to translate the origin to the point Position; therefore, the translation matrix is T ( Position ) 1 1 1 Pos Pos Pos 1 x y z Rotation is much harder: how do we generate a rotation matrix from the viewing specifications to turn one system (x, y, z) into another system (u, v, n)?

Rotation Components We have already known how to conduct rotation operations with respects to arbitrary axis Also, we have already discussed the transformations between two coordinate systems earlier in our lectures Those techniques should be employed to define three mutually independent axes in 3D and take care of the transformation between the two coordinate systems

Rotation Matrix Want to build a rotation matrix to normalize the camera-space unit vector axes (u, v, n) into the world-space axes (x, y, z). rotation matrix M will turn (x, y, z) into (u, v, n) and has columns (u, v, n) viewing matrix conversely, M -1 =M T turns (u, v, n) into (x, y, z). M T has rows (u, v, n) normalization matrix Reduces the problem of finding the correct rotation matrix into finding the correct perpendicular unit vectors u, v, and n Using Position, Look vector, and Up vector, compute viewing rotation matrix M with columns u, v, and n, then use its inverse, the transpose M T, with row vectors u, v, n to get the normalization rotation matrix

Canonical View Volume Note: it s a cuboid, not a cube (transformation arithmetic and clipping are easier)

Canonical View Given a parallel view specification and vertices of a bunch of objects, we use the normalizing transformation, i.e., the inverse viewing transformation, to normalize the view volume to a cuboid at the origin, then clip, and then project those vertices by ignoring their z values How about Perspective Projection? Normalize the perspective view specification to a unit frustum at the origin looking down the z axis; then transform the perspective view volume into a parallel (cuboid) view volume, simplifying both clipping and projection

Steps for Normalizing View Volume (Parallel Projection) We need to decompose this process into multiple steps (each step is a simple matrix) Each step defined by a matrix transformation The product of these matrices defines the entire transformation in one large, composite matrix. The steps comprise: move the eye/camera to the origin transform the view so that (u, v, n) is aligned with (x, y, z) adjust the scales so that the view volume fits between 1 and 1 in x and y, the far clip plane lies at z = 1, the near plane at z =

Steps for Normalizing View Volume (Perspective Projection) The earlier processes are the SAME AS that of the parallel projection, but we need to add one more step: distort pyramid to cuboid to achieve perspective distortion to align the near clip plane with z =

Perspective Projection (Move the Eye to the Origin) We want to have a matrix to transform (Pos x, Pos y, Pos z ) to (,, ) Solution: it s just the inverse of the viewing translation transformation: (t x, t y, t z ) = ( Pos x, Pos y, Pos z ) We will take the matrix as follows, and we will multiply all vertices explicitly (and the camera implicitly) to preserve the relationship between camera and scene, i.e., for all vertices p This will move Position (the eye point ) to (,, ) T trans 1 1 p' T 1 trans p Pos Pos Pos 1 x y z

Axis Alignment Align orientation with respects to x,y,z world coordinate system Normalize proportions of the view volume

Orientation Alignment Rotate the view volume and align with the world coordinate system We notice that the view transformation matrix M with columns u, v, and n would rotate the x, y, z axes into the u, v, and n axes We now apply the inverse (transpose) of that rotation, M T, to the scene. That is, a matrix with rows u, v, and n will rotate the axes u, v, and n into the axes x, y, and z Define M rot to be this rotation matrix transpose Now every vertex in the scene (and the camera implicitly) is multiplied by the composite matrix M rot T trans We have translated and rotated, so that the Position is at the origin, and the (u, v, n) axes and the (x, y, z) axes are aligned

Axis Alignment

Scale the View Volume We have moved things more or less to the right position, but the size of the view volume needs to be normalized last affine transformation: scaling Need to be normalized to a square cross-section 2-by-2 units why is that preferable to the unit square? Adjust so that the corners of far clipping plane eventually lie at (+1, +1, 1) One mathematical operation works for both parallel and perspective view volumes Imagine vectors emanating from origin passing through corners of far clipping plane. For perspective view volume, these are edges of volume. For parallel, these lie inside view volume First step: force vectors into 45-degree angles with x and y axes Solution: We shall do this by scaling in x and y

View Volume Scaling y y z x z x

Scale Boundary Planes Scale independently in x and y: Want to scale in x to make angle 9 degrees cot Need to scale in x by 1 w w 2 tan 2 tan w 2,, 1 tan W 2 Similarly in y

Scaling Matrix The scale matrix we need looks like this: S xy cot 2 w cot 2 h 1 1 So our current composite transformation looks like this: S xy M rot T trans

Scaling Along z-axis Relative proportions of view volume planes are now correct, but the back clipping plane is probably lying at some z 1, and we want all points inside view volume to have z -1 Need to shrink the back plane to be at z = 1 The z distance from the eye to that point has not changed: it s still far (distance to the far clipping plane) If we scale in z only, proportions of volume will change; instead we scale uniformly: 1 S far far 1 far 1 far 1

At Present, We Are Here Far plane at z = 1. y (-1,1,-1) (-k,k,-k) z z = -1 x Near clip plane now at z = k (note k > )

Now We have Our near-final composite normalizing transformation for canonical perspective view volume: T trans takes the camera s Position and moves the camera to the world origin M rot takes the Look and Up vectors and orients the camera to look down the z axis S xy takes w, h and scales the clipping planes so that the corners are at (±1, ±1) S far takes the far clipping plane and scales it to lie on the z=-1 plane S far S xy M rot T trans

Perspective Transformation We have put the perspective view volume into the RIGHT canonical position, orientation and size Let s look at a particular point on the original near clipping plane lying on the Look vector: p Position near Look It gets moved to a new location p on the negative z-axis, say S far S xy M rot T trans p k p

Perspective Transformation What is the value of k? Trace through the steps. p first gets moved to just near Look This point is then rotated to (near)( e 3 ) The xy scaling has no effect, and the far scaling changes this to, so near far e 3 but far is 1, so -near/far is simply near k near far

Perspective Transformation Transform points in standard perspective view volume between k and 1 to standard parallel view volume z-buffer, used for visible surface calculation, needs z values to be [ 1], not [ 1 ]. Perspective transformation must also transform scene to positive range z 1 The matrix that does this: (Remember that < k < 1 ) Why not originally align camera to +z axis? 1 D 1 k 1 1 k k 1 Choice is perceptual, we think of looking through a display device into the scene that lies behind window 1

Finally, We Have Final transformation: p D persp S far S xy M rot T trans p Note that once the viewing parameters (Position, Up vector, Look vector, Height angle, Aspect ratio, Near, and Far) are known, the matrices can all be computed and multiplied together to get a single 4x4 matrix that is applied to all points of all objects to get them from world space to the standard parallel view volume. What are the rationales for homogeneous coordinates??? D, S, S, M, T persp far xy rot trans

Clipping (A Quick Review) Final steps are clipping and projecting onto the image plane to produce pictures Need to clip scene against sides of view volume However, we ve normalized our view volume into an axis-aligned cuboid that extends from 1 to 1 in x and y and from to 1 in z (-1, 1, 1) (-1, 1, ) (-1, -1, 1) Back clip plane transforms to the z=1 plane (1, 1, 1) Note that: This is the flipped (in z) version of the canonical view volume Clipping is easy! Test x and y components of vertices against +/-1. Test z components against and 1 z (1, -1, 1) y (-1, -1, ) x (1, 1, ) (1, -1, ) Front clip plane transforms to here

Clipping in 3D (Generalizations) Cohen-Sutherland regions Clip before perspective division

Clipping (A Quick Review) Vertices falling within these values are saved, and vertices falling outside get clipped; edges get clipped by knowing x,y or z value at an intersection plane. Substitute x, y, or z = 1 in the corresponding parametric line equations to solve for t x 1 t x t x1 t 1 (x 1, y 1, z 1 ) y 1 t y t y1 t=1 z 1 t z t z1 t= (x, y, z ) In 2D: (-1, -1) (x, y ) y (1, 1) x=1 x (x 1, y 1 ) 1 1 1 t 1 t x x 1 x 1 x x tx t x x 1 tx x 1 tx 1

Projecting to the Screen (Device Coordinates) Can make an image by taking each point and ignoring z to project it onto the xyplane A point (x,y,z) where 1 x, y 1, z 1 turns into the point (x, y ) in screen space (assuming viewport is the entire screen) with by - ignoring z x, y 124 x y 512( x 512( y 1) 1) If viewport is inside a Window Manager s window, then we need to scale down and translate to produce window coordinates Note: because it s a parallel projection we could have projected onto the front plane, the back plane, or any intermediate plane the final pixmap would have been the same

From World to Screen The entire problem can be reduced to a composite matrix multiplication of vertices, clipping, and a final matrix multiplication to produce screen coordinates. Final composite matrix (CTM) is composite of all modeling (instance) transformations (CMTM) accumulated during scene graph traversal from root to leaf, composited with the final composite normalizing transformation N applied to the root/world coordinate system: 1) N D persp S far S xy M rot T trans 2) CTM N CMTM 3) 4) P screen P CTM P 512( P 1) for every vertex P defined in its own coordinate system for all clipped P Recap: 1) You will be computing the normalizing transformation matrix N in Camtrans 2) In Sceneview, you will extend your Camera with the ability to traverse and compute composite modeling transformations (CMTMs) to produce a single CTM for each primitive in your scene Aren't homogeneous coordinates wonderfully powerful?