CS 543: Computer Graphics. Projection

Similar documents
CS 4731/543: Computer Graphics Lecture 5 (Part I): Projection. Emmanuel Agu

Viewing. Cliff Lindsay, Ph.D. WPI

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

CS Computer Graphics: Transformations & The Synthetic Camera

Geometry: Outline. Projections. Orthographic Perspective

Projection: Mapping 3-D to 2-D. Orthographic Projection. The Canonical Camera Configuration. Perspective Projection

CS 428: Fall Introduction to. Viewing and projective transformations. Andrew Nealen, Rutgers, /23/2009 1

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

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

Lecture 4: Viewing. Topics:

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

CS Computer Graphics: Hidden Surface Removal

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

Viewing and Projection

COMP3421. Introduction to 3D Graphics

Viewing and Projection

Viewing/Projections III. Week 4, Wed Jan 31

CS 4204 Computer Graphics

COMP3421. Introduction to 3D Graphics

COMP3421. Introduction to 3D Graphics

Viewing and Projection

Viewing/Projection IV. Week 4, Fri Jan 29

Prof. Feng Liu. Fall /19/2016

Overview. Viewing and perspectives. Planar Geometric Projections. Classical Viewing. Classical views Computer viewing Perspective normalization

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

Viewing with Computers (OpenGL)

Getting Started. Overview (1): Getting Started (1): Getting Started (2): Getting Started (3): COSC 4431/5331 Computer Graphics.

Realtime 3D Computer Graphics & Virtual Reality. Viewing

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

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

3.1 Viewing and Projection

Models and The Viewing Pipeline. Jian Huang CS456

CS 543: Computer Graphics. 3D Transformations

OpenGL Transformations

Viewing COMPSCI 464. Image Credits: Encarta and

7. 3D Viewing. Projection: why is projection necessary? CS Dept, Univ of Kentucky

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

Transforms 3: Projection Christian Miller CS Fall 2011

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

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

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

CS Computer Graphics: Introduction to Ray Tracing

CS Computer Graphics: Introduction to Ray Tracing

Computer Graphics 7: Viewing in 3-D

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

Viewing/Projections IV. Week 4, Fri Feb 1

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

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

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

Three-Dimensional Graphics III. Guoying Zhao 1 / 67

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

Computer Graphics. Jeng-Sheng Yeh 葉正聖 Ming Chuan University (modified from Bing-Yu Chen s slides)

Computer Viewing Computer Graphics I, Fall 2008

CITSTUDENTS.IN VIEWING. Computer Graphics and Visualization. Classical and computer viewing. Viewing with a computer. Positioning of the camera

p =(x,y,d) y (0,0) d z Projection plane, z=d

Computer Graphics. Chapter 10 Three-Dimensional Viewing

Three-Dimensional Viewing Hearn & Baker Chapter 7

3D Viewing. With acknowledge to: Ed Angel. Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Illumination & Shading I

CS 543: Computer Graphics. Rasterization

Course no. DIS4566 National Chiao Tung Univ, Taiwan By: I-Chen Lin, Assistant Professor

CSE328 Fundamentals of Computer Graphics

3D Viewing. CMPT 361 Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller

Overview. By end of the week:

Chap 7, 2009 Spring Yeong Gil Shin

Transformation Pipeline

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Computer Viewing. CITS3003 Graphics & Animation. E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley

3-Dimensional Viewing

蔡侑庭 (Yu-Ting Tsai) National Chiao Tung University, Taiwan. Prof. Wen-Chieh Lin s CG Slides OpenGL 2.1 Specification

Fundamental Types of Viewing

Introduction to Computer Graphics 4. Viewing in 3D

Computer Graphics (CS 543) Lecture 9 (Part 2): Clipping. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

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

MORE OPENGL. Pramook Khungurn CS 4621, Fall 2011

GRAFIKA KOMPUTER. ~ M. Ali Fauzi

The Viewing Pipeline adaptation of Paul Bunn & Kerryn Hugo s notes

3D Viewing. Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller

Lecture 4. Viewing, Projection and Viewport Transformations

3D Graphics Pipeline II Clipping. Instructor Stephen J. Guy

Stereographics. Mike Bailey. Oregon State University. Oregon State University Computer Graphics mjb January 27, 2011

Stereographics. Mike Bailey. Stereovision is not new It s been in common use in the movies since the 1950s

Stereographics. Mike Bailey. Computer Graphics stereographics.pptx

Stereographics. Stereovision is not new It s been in common use in the movies since the 1950s. And, in stills, even longer than that.

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Lecture 4 of 41. Lab 1a: OpenGL Basics

Reminder: Affine Transformations. Viewing and Projection. Shear Transformations. Transformation Matrices in OpenGL. Specification via Ratios

5.8.3 Oblique Projections

CS Computer Graphics: Raster Graphics, Part 3

Institutionen för systemteknik

Lecture 5: Viewing. CSE Computer Graphics (Fall 2010)

Perspective transformations

Computer Graphics: Viewing in 3-D. Course Website:

Chapter 8 Three-Dimensional Viewing Operations

Viewing and Modeling

CS Computer Graphics: Illumination and Shading I

CS Computer Graphics: Illumination and Shading I

Viewing Transformations I Comp 535

CPSC 314, Midterm Exam. 8 March 2013

Viewing and Projection

Transcription:

CS 543: Computer Graphics Projection Robert W. Lindeman Associate Professor Interactive Media & Game Development Department of Computer Science Worcester Poltechnic Institute gogo@wpi.edu with lots of help from Prof. Emmanuel Agu :-)

3D Viewing and View Volume o Recall: 3D viewing set up R.W. Lindeman - WPI Dept. of Computer Science 2

Projection Transformation o View volume can have different shapes n Parallel, perspective, isometric o Different tpes of projection n Parallel orthographic), perspective, etc. o Important to control n Projection tpe: perspective or orthographic, etc. n Field of view and image aspect ratio n Near and far clipping planes R.W. Lindeman - WPI Dept. of Computer Science 3

Perspective Projection o Similar to real world o Characterized b object foreshortening n Objects appear larger if the are closer to camera o Need to define n Center of projection COP) n Projection view) plane camera projection plane o Projection n Connecting the object to the center of projection R.W. Lindeman - WPI Dept. of Computer Science 4

Wh is it Called Projection? View plane" R.W. Lindeman - WPI Dept. of Computer Science 5

Orthographic Parallel) Projection o No foreshortening effect n Distance from camera does not matter o The center of projection is at infinit o Projection calculation n Just choose equal z coordinates R.W. Lindeman - WPI Dept. of Computer Science 6

Field of View o Determine how much of the world is taken into the picture o Larger field of view = smaller objectprojection size field of view view angle) center of projection z θ z x R.W. Lindeman - WPI Dept. of Computer Science 7

Near and Far Clipping Planes o Onl objects between near and far planes are drawn o Near plane + far plane + field of view = View Frustum Near plane Far plane z x R.W. Lindeman - WPI Dept. of Computer Science 8

View Frustum o 3D counterpart of 2D-world clip window o Objects outside the frustum are clipped Near plane Far plane z x View Frustum R.W. Lindeman - WPI Dept. of Computer Science 9

Projection Transformation o In OpenGL n Set the matrix mode to GL_PROJECTION n For perspective projection, use gluperspective fov, aspect, near, far ); or glfrustum left, right, bottom, top, near, far ); n For orthographic projection, use glortho left, right, bottom, top, near, far ); R.W. Lindeman - WPI Dept. of Computer Science 10

gluperspective fov, aspect, near, far ) o Aspect ratio is used to calculate the window width fov w z θ z ee x h Aspect = w / h near far R.W. Lindeman - WPI Dept. of Computer Science 11

glfrustum left, right, bottom, top, near, far ) o Can use this function in place of gluperspective ) left top z x bottom right near far R.W. Lindeman - WPI Dept. of Computer Science 12

glortho left, right, bottom, top, near, far ) o For orthographic projection left top z x bottom right near far R.W. Lindeman - WPI Dept. of Computer Science 13

Example: Projection Transformation void displa ) { glclear GL_COLOR_BUFFER_BIT ); glmatrixmode GL_PROJECTION ); glloadidentit ); gluperspective FovY, Aspect, Near, Far ); glmatrixmode GL_MODELVIEW ); glloadidentit ); glulookat 0, 0, 1, 0, 0, 0, 0, 1, 0 ); mdispla ); // our displa routine } R.W. Lindeman - WPI Dept. of Computer Science 14

Projection Transformation o Projection n Map the object from 3D space to 2D screen z z x x Perspective: gluperspective ) Parallel: glortho ) R.W. Lindeman - WPI Dept. of Computer Science 15

Parallel Projection The Math) o After transforming the object to ee space, parallel projection is relativel eas: we could just set all Z to the same value n X p = x n Y p = n Z p = -d X p, Y p ) z x o We actuall want to remember Z wh? x,,z) R.W. Lindeman - WPI Dept. of Computer Science 16

Parallel Projection o OpenGL maps projects) everthing in the visible volume into a canonical view volume CVV) x max, max, far) 1, 1, -1) x min, min, near) glortho xmin, xmax, min, max, near, far ) -1, -1, 1) Canonical View Volume Projection: Need to build 4x4 matrix to do mapping from actual view volume to CVV R.W. Lindeman - WPI Dept. of Computer Science 17

Parallel Projection: glortho o Parallel projection can be broken down into two parts n Translation, which centers view volume at origin n Scaling, which reduces cuboid of arbitrar dimensions to canonical cube o Dimension 2, centered at origin R.W. Lindeman - WPI Dept. of Computer Science 18

Parallel Projection: glortho cont.) o Translation sequence moves midpoint of view volume to coincide with origin n e.g., midpoint of x = x max + x min )/2 o Thus, translation factors are -x max +x min )/2, - max + min )/2, -far+near)/2 o So, translation matrix M1: # 1 0 0 x max+ x min)/2& 0 1 0 max+ min)/2 0 0 1 z max+ z min)/2 $ 0 0 0 1 ' R.W. Lindeman - WPI Dept. of Computer Science 19

Parallel Projection: glortho cont.) o Scaling factor is ratio of cube dimension to Ortho view volume dimension o Scaling factors 2/x max -x min ), 2/ max - min ), 2/z max -z min ) o So, scaling matrix M2: # 2 & 0 0 0 x max x min 2 0 0 0 max min 2 0 0 zmax zmin 0 $ 0 0 0 1' R.W. Lindeman - WPI Dept. of Computer Science 20

Parallel Projection: glortho) cont.) o Concatenating M1xM2, we get transform matrix used b glortho # 2 & 0 0 0 x max x min 2 0 0 0 max min 2 0 0 zmax zmin 0 $ 0 0 0 1' X # 1 0 0 x max+ x min)/2& 0 1 0 max+ min)/2 0 0 1 z max+ z min)/2 $ 0 0 0 1 ' $ 2 /x max x min) 0 0 x max+ x min)/x max x min) ' & ) 0 2/ max min) 0 max+ min)/ max min) M2 M1 = & ) & 0 0 2/zmax zmin) zmax+ zmin)/zmax zmin) ) & ) 0 0 0 1 Refer to: Hill, 7.6.2 R.W. Lindeman - WPI Dept. of Computer Science 21

Perspective Projection: Classical o Side view 0,0,0) Projection plane x,,z ) d -z x,,z) Ee center of projection ) z z x Based on similar triangles: -z = d d = * -z R.W. Lindeman - WPI Dept. of Computer Science 22

Perspective Projection: Classical cont.) o So x*, *), the projection of point, x,, z) onto the near plane N, is given as n Similar triangles # x*, *) = N P x,n P & $ P z P z ' o Numerical example Q: Where on the viewplane does P = 1, 0.5, -1.5) lie for a near plane at N = 1? x*, *) = 1 x 1/1.5, 1 x 0.5/1.5) = 0.666, 0.333) R.W. Lindeman - WPI Dept. of Computer Science 23

Pseudo Depth Checking o Classical perspective projection drops z coordinates o But we need z to find closest object depth testing) o Keeping actual distance of P from ee is cumbersome and slow distance = P 2 x + P 2 2 + P z ) o Introduce pseudodepth: all we need is a measure of which objects are further if two points project to the same x, ) # x*, *,z *) = N P & x,n P, ap z + b P z P z P z ' o Choose a, b so that pseudodepth varies from 1 to 1 canonical cube) R.W. Lindeman - WPI Dept. of Computer Science 24 $

Pseudo Depth Checking cont.) o Solving: z* = ap z + b P z o For two conditions, z* = -1 when P z = -N and z* = 1 when P z = -F, we can set up two simultaneous equations o Solving for a and b, we get a = F + N) F N b = 2FN F N R.W. Lindeman - WPI Dept. of Computer Science 25

Homogenous Coordinates o Would like to express projection as 4x4 transform matrix o Previousl, homogeneous coordinates for the point P = P x, P, P z ) was P x, P, P z, 1) o Introduce arbitrar scaling factor, w, so that P = wp x, wp, wp z, w) Note: w is non-zero) o For example, the point P = 2, 4, 6) can be expressed as n 2, 4, 6, 1) n or 4, 8, 12, 2) where w=2 n or 6, 12, 18, 3) where w = 3 o So, to convert from homogeneous back to ordinar coordinates, divide all four terms b last component and discard 4 th term R.W. Lindeman - WPI Dept. of Computer Science 26

Perspective Projection o Same for x, so we have x = x * d / -z = * d / -z z = -d o Put in a matrix form # 1 0 0 0& # x& 0 1 0 0 0 0 1 0 z 0 0 1 $ d ) 1 ' $ 1' # x' & ' = z' $ w' # d x ) & z # d & $ z ' d $ 1 ' OpenGL assumes d = 1, i.e., the image plane is at z = -1 R.W. Lindeman - WPI Dept. of Computer Science 27

Perspective Projection cont.) o We are not done et! o Need to modif the projection matrix to include a and b x 1 0 0 0 x = 0 1 0 0 z 0 0 a b z w 0 0 1/-d) 0 1 z x o We have alread solved a and b Z = 1 z = -1 R.W. Lindeman - WPI Dept. of Computer Science 28

Perspective Projection cont.) o Not done et! OpenGL also normalizes the x and ranges of the view frustum to [-1, 1] translate and scale) o So, as in ortho, to arrive at final projection matrix n We translate b o xmax + xmin)/2 in x o -max + min)/2 in n And scale b o 2/xmax xmin) in x o 2/max min) in R.W. Lindeman - WPI Dept. of Computer Science 29

Perspective Projection cont.) o Final projection matrix glfrustum xmin, xmax, min, max, N, F ) n N = near plane, F = far plane # 2N x max x min 0 $ x max+ x min 0 0 x max x min 2N max+ min 0 max min max min F + N) 0 0 F N 0 0 1 0 2FN F N & ' R.W. Lindeman - WPI Dept. of Computer Science 30

Perspective Projection cont.) o After perspective projection, viewing frustum is also projected into a canonical view volume like in parallel projection) 1, 1, -1) z x -1, -1, 1) Canonical View Volume R.W. Lindeman - WPI Dept. of Computer Science 31