CENG 477 Introduction to Computer Graphics

Slides:



Advertisements
Similar presentations
1 Computer Graphics Chapter 8 3D Transformations.
Advertisements

CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t.
Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing
CS485/685 Computer Vision Prof. George Bebis
Viewing Doug James’ CG Slides, Rich Riesenfeld’s CG Slides, Shirley, Fundamentals of Computer Graphics, Chap 7 Wen-Chieh (Steve) Lin Institute of Multimedia.
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!
Viewing and Projections
Transformation & Projection Feng Yu Proseminar Computer Graphics :
Week 5 - Wednesday.  What did we talk about last time?  Project 2  Normal transforms  Euler angles  Quaternions.
MIT EECS 6.837, Durand and Cutler Graphics Pipeline: Projective Transformations.
CS559: Computer Graphics Lecture 9: Projection Li Zhang Spring 2008.
Graphics Graphics Korea University cgvr.korea.ac.kr 3D Viewing 고려대학교 컴퓨터 그래픽스 연구실.
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.
CAP4730: Computational Structures in Computer Graphics 3D Transformations.
10/3/02 (c) 2002 University of Wisconsin, CS 559 Last Time 2D Coordinate systems and transformations.
CS 4731: Computer Graphics Lecture 13: Projection Emmanuel Agu.
CS 450: COMPUTER GRAPHICS PROJECTIONS SPRING 2015 DR. MICHAEL J. REALE.
10/7/04© University of Wisconsin, CS559 Fall 2004 Last Time Transformations Homogeneous coordinates Directions Rotation Geometry 101 – Points, edges, triangles/polygons.
Basic 3D Concepts. Overview 1.Coordinate systems 2.Transformations 3.Projection 4.Rasterization.
University of North Carolina at Greensboro
2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection.
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)
Geometric Transformations
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Jinxiang Chai CSCE 441 Computer Graphics 3-D Viewing 0.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
Three-Dimensional Viewing
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.
Taxonomy of Projections FVFHP Figure Taxonomy of Projections.
CS552: Computer Graphics Lecture 11: Orthographic Projection.
1 PTT 105/3: Engineering Graphics. TAXONOMY OF PLANAR GEOMETRIC PROJECTIONS PTT 105/3: Engineering Graphics 2 Planar Geometric Projections Parallel Multiview.
Viewing and Projection. The topics Interior parameters Projection type Field of view Clipping Frustum… Exterior parameters Camera position Camera orientation.
CS 551 / 645: Introductory Computer Graphics Viewing Transforms.
Viewing. Classical Viewing Viewing requires three basic elements - One or more objects - A viewer with a projection surface - Projectors that go from.
Outline 3D Viewing Required readings: HB 10-1 to 10-10
Forward Projection Pipeline and Transformations CENG 477 Introduction to Computer Graphics.
Introduction to Computer Graphics
Visible Surface Detection
Viewing Viewing and viewing space (camera space)
Rendering Pipeline Fall, 2015.
Computer Graphics CC416 Week 14 3D Graphics.
- Introduction - Graphics Pipeline
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2016
University of North Carolina at Greensboro
CSE 167 [Win 17], Lecture 5: Viewing Ravi Ramamoorthi
Computer Graphics CC416 Week 15 3D Graphics.
PERSPECTIVE PROJECTION…...
Intro to 3D Graphics.
3D Viewing cgvr.korea.ac.kr.
Rendering Pipeline Aaron Bloomfield CS 445: Introduction to Graphics
CSCE 441 Computer Graphics 3-D Viewing
Viewing in 3D Chapter 6.
Modeling 101 For the moment assume that all geometry consists of points, lines and faces Line: A segment between two endpoints Face: A planar area bounded.
CS451Real-time Rendering Pipeline
Viewing/Projections I Week 3, Fri Jan 25
Three Dimensional Viewing
OpenGL 2D Viewing Pipeline
CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University View & Projection.
Computer Graphics (Spring 2003)
Chapter V Vertex Processing
Last Time Canonical view pipeline Projection Local Coordinate Space
Chap 3 Viewing Pipeline Reading:
Viewing (Projections)
Viewing (Projections)
THREE-DIMENSIONAL VIEWING
The Pinhole Camera Model
Presentation transcript:

CENG 477 Introduction to Computer Graphics Viewing Transformations

CENG 477 – Computer Graphics Introduction Until now, we learned how to position the objects in the 3D world space by modeling transformations With viewing transformations, we position the objects on a 2D image as seen by a camera with arbitrary position and orientation Composed of three parts: Camera (or eye) transformation Projection transformation Viewport transformation CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Introduction With viewing transformations, we are now transitioning from the backward rendering pipeline (aka. ray tracing) to forward rendering pipeline (aka. object-order, rasterization, z-buffer) Camera Camera Forward rendering Backward rendering CENG 477 – Computer Graphics

Camera Transformation Goal: Given an arbitrary camera position e and camera vectors uvw, determine the camera coordinates of points given by their world coordinates What are the coordinates of this cube with respect to the uvw CS? u v w e x y z (0,0,0) CENG 477 – Computer Graphics

Camera Transformation Transform everything such that uvw aligns with xyz u v w e x y z (0,0,0) u v w e x y z (0,0,0) CENG 477 – Computer Graphics

Camera Transformation Step 1: Translate e to the world origin (0, 0, 0) 𝑇= 1 0 0 − 𝑒 𝑥 0 1 0 − 𝑒 𝑦 0 0 1 − 𝑒 𝑧 0 0 0 1 x y z u v w e CENG 477 – Computer Graphics

Camera Transformation Step 2: Rotate uvw to align it with xyz: 𝑅= 𝑢 𝑥 𝑢 𝑦 𝑢 𝑧 0 𝑣 𝑥 𝑣 𝑦 𝑣 𝑧 0 𝑤 𝑥 𝑤 𝑦 𝑤 𝑧 0 0 0 0 1 x y z We already learned how to do this in modeling transformations! u v w e CENG 477 – Computer Graphics

Camera Transformation The composite camera transformation is: aka Viewing Transformation Matrix 𝑀 𝑐𝑎𝑚 = 𝑢 𝑥 𝑢 𝑦 𝑢 𝑧 0 𝑣 𝑥 𝑣 𝑦 𝑣 𝑧 0 𝑤 𝑥 𝑤 𝑦 𝑤 𝑧 0 0 0 0 1 1 0 0 − 𝑒 𝑥 0 1 0 − 𝑒 𝑦 0 0 1 − 𝑒 𝑧 0 0 0 1 𝑀 𝑐𝑎𝑚 = 𝑢 𝑥 𝑢 𝑦 𝑢 𝑧 −( 𝑢 𝑥 𝑒 𝑥 + 𝑢 𝑦 𝑒 𝑦 + 𝑢 𝑧 𝑒 𝑧 ) 𝑣 𝑥 𝑣 𝑦 𝑣 𝑧 −( 𝑣 𝑥 𝑒 𝑥 + 𝑣 𝑦 𝑒 𝑦 + 𝑣 𝑧 𝑒 𝑧 ) 𝑤 𝑥 𝑤 𝑦 𝑤 𝑧 −( 𝑤 𝑥 𝑒 𝑥 + 𝑤 𝑦 𝑒 𝑦 + 𝑤 𝑧 𝑒 𝑧 ) 0 0 0 1 CENG 477 – Computer Graphics

Camera Transformation When points are multiplied with this matrix, their resulting coordinates will be with respect to the uvw-e coordinate system (i.e. the camera coordinate system) Next, we need to apply a projection transformation CENG 477 – Computer Graphics

Projection Transformation Projection: 3D to 2D. Perspective or parallel. yview xview zview P2 P2 P2` P2` Convergence Point P1` P1 P1 P1`

Projection Transformation Classification of projections. Based on: Center of projection: infinity (parallel) or a point (perspective) Projection lines wrt. projection plane: orthogonal (orthographic), another angle (oblique) See https://youtu.be/zuOWmbAIOmI Projection plane Center of projection Projection plane Projection plane Center of projection Center of projection Perspective Orthographic Oblique

Orthographic Transformation In both types of projections, our goal is to transform a given viewing volume to the canonical viewing volume (CVV): y x z y (1, 1, 1) (-1, -1, -1) v (l, b, -n) (r, t, -f) z w (0, 0, 0) (0, 0, 0) u x Note that n and f are typically given as distances which are always positive and because we are looking towards the –z direction, the actual coordinates become –n and -f Think of it as compressing a box CENG 477 – Computer Graphics

Orthographic Transformation In both types of projections, our goal is to transform a given viewing volume to the canonical viewing volume (CVV): y x z y (1, 1, 1) (-1, -1, -1) (0, 0, 0) v (l, b, -n) (r, t, -f) z w (0, 0, 0) u x Also note the change in the z-direction. This makes objects further away from the camera to have larger z-values. In other words, CVV is a left-handed coordinate system. CENG 477 – Computer Graphics

Orthographic Projection We need to map the box with corners at (l, b, -n) and (r, t, -f) to the (-1, -1, -1) and (1, 1, 1) of CVV This is accomplished by the following matrix: 𝑀 𝑜𝑟𝑡ℎ = 2 𝑟 −𝑙 0 0 − 𝑟+𝑙 𝑟 −𝑙 0 2 𝑡 −𝑏 0 − 𝑡+𝑏 𝑡 −𝑏 0 0 − 2 𝑓−𝑛 − 𝑓+𝑛 𝑓 −𝑛 0 0 0 1 Make sure you understand how to derive this! CENG 477 – Computer Graphics

Orthographic Projection We need to map the box with corners at (l, b, -n) and (r, t, -f) to the (-1, -1, -1) and (1, 1, 1) of CVV This is accomplished by the following matrix: Hint for derivation: 𝑀 𝑜𝑟𝑡ℎ = 2 𝑟 −𝑙 0 0 − 𝑟+𝑙 𝑟 −𝑙 0 2 𝑡 −𝑏 0 − 𝑡+𝑏 𝑡 −𝑏 0 0 − 2 𝑓−𝑛 − 𝑓+𝑛 𝑓 −𝑛 0 0 0 1 CENG 477 – Computer Graphics

Perspective Projection Perspective projection models how we see the real world Objects appear smaller with distance script-tutorials.com CENG 477 – Computer Graphics

Perspective Projection We still have the same 6 parameters l r t b Camera Near distance (n) Far distance (f) CENG 477 – Computer Graphics

Perspective Projection To map to the canonical viewing volume (CVV), we take a two step approach: Step 1: Map perspective to orthographic viewing volume Step 2: Map orthographic to CVV x z y (1, 1, 1) (-1, -1, -1) (0, 0, 0) (l, b, -n) (r, t, -n) (l, b, -n) (r, t, -f) We already know how to perform the second step! Think of this as compressing a box where you have to apply more pressure towards the back CENG 477 – Computer Graphics

Perspective Projection The key observation is that more distant objects should shrink proportional to their distance to the camera Here is a side view (therefore x is constant): 𝑦 ′ 𝑦 = −𝑛 𝑧 𝑦 ′ = −𝑛 𝑧 𝑦 The same geometrical config. applies to x dimension as well: (x, t, -n) (x, y, z) (x, y’, -n) 𝑥 ′ 𝑥 = −𝑛 𝑧 𝑥 ′ = −𝑛 𝑧 𝑥 (x, 0, -f) (x, 0, 0) (x, 0, -n) What is y’? Let’s ignore the z dimension for the moment CENG 477 – Computer Graphics

Perspective Projection This can also be represented as a matrix multiplication thanks to homogeneous coordinates: Why does this work? 𝑀 𝑝2𝑜 = 𝑛 0 0 0 0 𝑛 0 0 0 0 𝐴 𝐵 0 0 −1 0 CENG 477 – Computer Graphics

Perspective Projection Let’s multiply a point [x, y, z, 1]T with this matrix: 𝑥 ′ 𝑦 ′ 𝑧 ′ 𝑤 ′ = 𝑛 0 0 0 0 𝑛 0 0 0 0 𝐴 𝐵 0 0 −1 0 𝑥 𝑦 𝑧 1 𝑥 ′ 𝑦 ′ 𝑧 ′ 𝑤 ′ = 𝑛𝑥 𝑛𝑦 𝐴𝑧+𝐵 −𝑧 Remember that in homogenous coordinates, scaling all components by the same factor does not change the point. So divide by the last comp. 𝑥 ′ 𝑦 ′ 𝑧 ′ 𝑤 ′ = 𝑛𝑥 𝑛𝑦 𝐴𝑧+𝐵 −𝑧 = −𝑛𝑥/𝑧 −𝑛𝑦/𝑧 −𝐴−𝐵/𝑧 1 CENG 477 – Computer Graphics

Perspective Projection For the z-axis, we have the following constrains: (–n) maps to (–n) (–f) maps to (–f) We can solve for A and B using these constrains (l, b, -n) (r, t, -n) (l, b, -n) (r, t, -f) CENG 477 – Computer Graphics

Perspective Projection Remember that we had: Now plug (-n) and (-f) and solve for the unknowns: 𝑧 ′ =−𝐴−𝐵/𝑧 −𝑛=−𝐴+𝐵/𝑛 A=𝑓+𝑛 𝐵=𝑓𝑛 −𝑓=−𝐴+𝐵/𝑓 CENG 477 – Computer Graphics

Perspective Projection The final perspective to orthographic matrix becomes: Note that this was Step 1 In step 2, we multiply this matrix with the orthographic to canonical viewing volume transformation matrix 𝑀 𝑝2𝑜 = 𝑛 0 0 0 0 𝑛 0 0 0 0 𝑓+𝑛 𝑓𝑛 0 0 −1 0 CENG 477 – Computer Graphics

Perspective Projection The final perspective projection transformation matrix is: 𝑀 𝑝𝑒𝑟 = 𝑀 𝑜𝑟𝑡ℎ 𝑀 𝑝2𝑜 𝑀 𝑝𝑒𝑟 = 2𝑛 𝑟 −𝑙 0 𝑟+𝑙 𝑟 −𝑙 0 0 2𝑛 𝑡 −𝑏 𝑡+𝑏 𝑡 −𝑏 0 0 0 − 𝑓+𝑛 𝑓−𝑛 − 2𝑓𝑛 𝑓 −𝑛 0 0 −1 0 CENG 477 – Computer Graphics

Orthographic Projection The final orthographic projection transformation matrix is: 𝑀 𝑜𝑟𝑡ℎ = 2 𝑟 −𝑙 0 0 − 𝑟+𝑙 𝑟 −𝑙 0 2 𝑡 −𝑏 0 − 𝑡+𝑏 𝑡 −𝑏 0 0 − 2 𝑓−𝑛 − 𝑓+𝑛 𝑓 −𝑛 0 0 0 1 CENG 477 – Computer Graphics

Viewport Transformation After perspective transformation, all objects inside the viewing volume are transformed into CVV Viewport transformation maps them to the screen (window) coordinates (0, 0) Viewport x z y (1, 1, 1) (-1, -1, -1) (0, 0, 0) ny nx (nx-1, ny-1) CENG 477 – Computer Graphics

Viewport Transformation x values in range [-1,1] are transformed to [-0.5, nx-0.5] y values in range [-1,1] are transformed to [-0.5, ny-0.5] z values in range [-1,1] are transformed to [0,1] for later usage 𝑀 𝑣𝑝 = 𝑛 𝑥 2 0 0 𝑛 𝑥 −1 2 0 𝑛 𝑦 2 0 𝑛 𝑦 −1 2 0 0 1 2 1 2 Note that we don’t need to preserve the w component anymore CENG 477 – Computer Graphics

Viewport Transformation x values in range [-1,1] are transformed to [-0.5, nx-0.5] y values in range [-1,1] are transformed to [-0.5, ny-0.5] z values in range [-1,1] are transformed to [0,1] for later usage: Z-buffer (aka depth buffer): quick and robust decision for who is in front of who //solves the visibility problem CENG 477 – Computer Graphics

Viewport Transformation x values in range [-1,1] are transformed to [-0.5, nx-0.5] y values in range [-1,1] are transformed to [-0.5, ny-0.5] z values in range [-1,1] are transformed to [0,1] for later usage: Z-buffer (aka depth buffer): quick and robust decision for who is in front of who //solves the visibility problem Z-buffer is based on the z-coordinates in the viewport ([0,1]), not in the world coordinates World coordinates are defined for 3 corners of a triangle; it is inefficient to fill the inside of the triangle in the world space because A big 3D triangle, after all the 3D to 2D transformations, may be behind an object in viewport so will not be visible in 2D at all; hence a fill in 3D is useless A long 3D triangle may be mapped to a small 2D triangle in the viewport Fast (hardware-level) rasterization algorithms to fill the inside of a 2D viewport triangle (compared to filling a triangle hanging in 3D) CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Z-Fighting Note that the z-values get compressed to [0, 1] range from the [-n:-f] range Observe how it looks for n = 10 and f = 50 CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Z-Fighting Note that the z-values get compressed to [0, 1] range from the [-n:-f] range Observe the same for n = 10 and f = 200 CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Z-Fighting The compression is more severe for with larger depth range This may cause a problem known as z-fighting: Objects with originally different z-values get mapped to the same final z-value (due to limited precision) making it impossible to distinguish which one is in front and which one is behind CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Z-Fighting The compression is more severe for with larger depth range This may cause a problem known as z-fighting: Problem is even worse if the input z-values are very close to begin with To avoid z-fighting, the depth range should be kept as small as possible for keeping the compressing less severe CENG 477 – Computer Graphics

CENG 477 – Computer Graphics Summary A point [xw, yw, zw]T in the world coordinate system can be transformed to its viewport coordinates by: If the point is defined in its local coordinate system and we are given modeling transformations we use: 𝑥 𝑣𝑝 𝑦 𝑣𝑝 𝑧 𝑣𝑝 = 𝑀 𝑣𝑝 𝑀 𝑝𝑒𝑟 𝑀 𝑐𝑎𝑚 𝑥 𝑤 𝑦 𝑤 𝑧 𝑤 1 𝑥 𝑣𝑝 𝑦 𝑣𝑝 𝑧 𝑣𝑝 = 𝑀 𝑣𝑝 𝑀 𝑝𝑒𝑟 𝑀 𝑐𝑎𝑚 𝑀 𝑚𝑜𝑑𝑒𝑙 𝑥 𝑙 𝑦 𝑙 𝑧 𝑙 1 CENG 477 – Computer Graphics