CSC 305 The Graphics Pipeline-1

Similar documents
3D Viewing. CS 4620 Lecture 8

CSE528 Computer Graphics: Theory, Algorithms, and Applications

CSE328 Fundamentals of Computer Graphics

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

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

Computer Graphics. Lecture 04 3D Projection and Visualization. Edirlei Soares de Lima.

Graphics 2009/2010, period 1. Lecture 6: perspective projection

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

CS 4204 Computer Graphics

Game Architecture. 2/19/16: Rasterization

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

09 - Designing Surfaces. CSCI-GA Computer Graphics - Fall 16 - Daniele Panozzo

Computer Graphics 7: Viewing in 3-D

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

Overview. By end of the week:

The Graphics Pipeline and OpenGL I: Transformations!

Viewing COMPSCI 464. Image Credits: Encarta and

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

Prof. Feng Liu. Fall /19/2016

UNIT 2 2D TRANSFORMATIONS

Three-Dimensional Viewing Hearn & Baker Chapter 7

Models and The Viewing Pipeline. Jian Huang CS456

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

Introduction to Computer Graphics 4. Viewing in 3D

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

GEOMETRIC TRANSFORMATIONS AND VIEWING

3D Geometry and Camera Calibration

Computer Science 426 Midterm 3/11/04, 1:30PM-2:50PM

Specifying Complex Scenes

Virtual Cameras and The Transformation Pipeline

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

Chapter 5. Projections and Rendering

Implementing a virtual camera. Graphics 2. Creating a view of the scene an outline. Virtual camera - definitions

Virtual Cameras & Their Matrices

Computer Vision cmput 428/615

Agenda. Rotations. Camera models. Camera calibration. Homographies

1 Projective Geometry

CSE452 Computer Graphics

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

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

Lecture 4. Viewing, Projection and Viewport Transformations

Camera Model and Calibration

CS 418: Interactive Computer Graphics. Projection

Viewing. Reading: Angel Ch.5

Midterm Exam Fundamentals of Computer Graphics (COMP 557) Thurs. Feb. 19, 2015 Professor Michael Langer

Computer Graphics Viewing

Linear and Affine Transformations Coordinate Systems

Rasterization Overview

CS4620/5620: Lecture 14 Pipeline

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

CS4620/5620. Professor: Kavita Bala. Cornell CS4620/5620 Fall 2012 Lecture Kavita Bala 1 (with previous instructors James/Marschner)

Computer Viewing. Prof. George Wolberg Dept. of Computer Science City College of New York

CS251 Spring 2014 Lecture 7

Basic Elements. Geometry is the study of the relationships among objects in an n-dimensional space

Today s class. Viewing transformation Menus Mandelbrot set and pixel drawing. Informationsteknologi

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

N-Views (1) Homographies and Projection

Viewing with Computers (OpenGL)

Interactive Computer Graphics. Hearn & Baker, chapter D transforms Hearn & Baker, chapter 5. Aliasing and Anti-Aliasing

3D graphics rendering pipeline (1) 3D graphics rendering pipeline (3) 3D graphics rendering pipeline (2) 8/29/11

2D and 3D Transformations AUI Course Denbigh Starkey

Geometric transformations assign a point to a point, so it is a point valued function of points. Geometric transformation may destroy the equation

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

CS Exam 1 Review Problems Fall 2017

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

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

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

CS464 Oct 3 rd Assignment 3 Due 10/6/2017 Due 10/8/2017 Implementation Outline

3D Coordinates & Transformations

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

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

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

The Graphics Pipeline and OpenGL I: Transformations!

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

Representing 2D Transformations as Matrices

COMP3421. Introduction to 3D Graphics

Chapter 8 Three-Dimensional Viewing Operations

CS184 : Foundations of Computer Graphics Professor David Forsyth Final Examination

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

DD2429 Computational Photography :00-19:00

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)

Pipeline Operations. CS 4620 Lecture 14

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

Graphics pipeline and transformations. Composition of transformations

Transformations Week 9, Lecture 18

Computer Graphics with OpenGL ES (J. Han) Chapter VII Rasterizer

Visualisation Pipeline : The Virtual Camera

What does OpenGL do?

Software Engineering. ò Look up Design Patterns. ò Code Refactoring. ò Code Documentation? ò One of the lessons to learn for good design:

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

COMP3421. Introduction to 3D Graphics

CS184 : Foundations of Computer Graphics Professor David Forsyth Final Examination (Total: 100 marks)

Coordinate Frames and Transforms

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

Perspective transformations

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

COMP30019 Graphics and Interaction Three-dimensional transformation geometry and perspective

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

Transforms. COMP 575/770 Spring 2013

Transcription:

C. O. P. d y! "#"" (-1, -1) (1, 1) x z CSC 305 The Graphics Pipeline-1 by Brian Wyvill The University of Victoria Graphics Group

Perspective Viewing Transformation l l l Tools for creating and manipulating a camera that produces pictures of a 3D scene Viewing transformations and projections Perform culling or back-face elimination University of Victoria Graphics Lab. CSC 305 2017 page 2

The Illusion of Depth Perception is an active organising process Many cues to depth! University of Victoria Graphics Lab. CSC 305 2017 page 3

Window to Viewport Transformation University of Victoria Graphics Lab. CSC 305 2017 page 4

University of Victoria Graphics Lab. CSC 305 2017 page 5

Viewing Transformations Sequence that takes a model from object space to the viewport (window) Shirley: Chapter 7. University of Victoria Graphics Lab. CSC 305 2017 page 6

Pixel Conventions Rectangular domain of the image: R = [ 0.5,n x 0.5]x[ 0.5,n y 0.5] University of Victoria Graphics Lab. CSC 305 2017 page 7

Canonical View Volume (chapter 7 Shirley see also chapter 5 on matrices) y z x Object to map lines in the canonical view volume to the screen. (x,y,z) in [-1, 1] 3 (as in interval [a,b]) For now assume that all line segments are in the view volume (clipping later!) The camera views the canonical view volume looking along the z axis University of Victoria Graphics Lab. CSC 305 2017 page 8

Mapping to the screen (ignore z distance along projection axis not affect x,y) Pixel Geometry (-½, ½) (½, ½) (-½, -½) y (0,0) (½, -½) -x z (-1, -1) Map lines to Screen along the Z axis in (+)ve direction. 2 Screen n x by n y pixels x = -1 à left side of screen x = +1 à right side of screen y = -1 à bottom of screen y = +1 à top of screen Maps square [-1, +1] 2 to non-square scales S x and S y will be defined. (1, 1) 2 (-½, n y -½) (-½, -½) Screen Geometry n x (n x -½, n y -½) n y (n x -½, -½) University of Victoria Graphics Lab. CSC 305 2017 page 9

As Before a Window to Viewport Transform (-1, -1) Canonical Canonical Map lines to Screen along the Z axis in (+)ve direction. 2 (1, 1) 2 (-½, n y -½) (-½, -½) Pixels Screen Geometry n x (n x -½, n y -½) n y (n x -½, -½) [ 1 x pixel ] y pixel = [ nx/2 0 (nx-1)/2 0 n y /2 (n y -1)/2 0 0 1 ] [ x caonical ] y canonical 1 For now simply ignore The z-values distorts by aspect ratio - Note that M vp is the above plus a line for z University of Victoria Graphics Lab. CSC 305 2017 page 10

Mvp Window to Viewport Matrix 4x4 to preserve z [ 1 x pixel ] y pixel = [ nx/2 0 (nx-1)/2 0 n y /2 (n y -1)/2 0 0 1 ] [ x caonical ] y canonical 1 " M vp = # n x n 0 0 x 1 2 2 0 n y n 0 y 1 2 2 0 0 1 0 0 0 0 1 % & University of Victoria Graphics Lab. CSC 305 2017 page 11

Orthographic View Volume (fixed axis view) Right Handed System Gaze (or camera view) along Z direction ( note n > f less negative) x to the right and y up The transform we want is just a scale and translate. It takes: transforms to transforms to y = b à y = -1, y = t à y = +1 x = l à x = -1, x = r à x = +1 z = n à z = 1, z = f à z = -1 University of Victoria Graphics Lab. CSC 305 2017 page 12

Orthographic Projection What happens if we don t have a canonical view volume? (l,b,n) a b (r,t,f) (l,b,n) = (lower, bottom, near) (r,t,f)= (right, top, front) Left plane à xà Right Plane Bottom plane à yà Top Plane Near plane à zà Far Plane Find matrix M s.t. M.a and M.b are in canonical view volume. e.g lines in Orthographic view volume above Bounded by axis aligned planes M orth M orth transforms from Orthographic View volume to canonical " M orth = # 2 r l 0 0 0 0 0 r + l r l 2 0 t + b t b t b 2 n + f n f n f 0 0 0 1 % & University of Victoria Graphics Lab. CSC 305 2017 page 13

Window to Viewport Transform Revisited: -1 + + 0 +, 0 0 1 0 u v min min 1 * ( ( ( ) - + + +, λ 0 0 x 0 λ 0 y 0* ( 0 ( 1( ) -1 + + 0 +, 0 0 1 0 x y 1 min min * ( ( ( ) -x* + y ( + ( +, 1( ) where M 0 = u x n x /2 0 0 (n λ x -1)/2 % max 0 n = x y /2 0 (n % y -1)/2 & 0 0 1 max 0, u x 2/(r-l) 0 0 v 0 min " max 0, 2/(t-b) = " λ x 0 0 y min # 0 0 2/(n-f) max 0 v y 1 0 0 -(l+r)/2 min 0 1 0 -(b+t)/2 min 0 0 1 -(n+f)/2 0 0 0 1 0 0 0 1 0 0 0 1 M 0 =M vp M orth is just Another Window to Viewport Transform University of Victoria Graphics Lab. CSC 305 2017 page 14

Scale then translate The transform from the orthographic view volume to the canonical view volume. n is less (-)ve than f x canonical 2/(r-l) 0 0 0 1 0 0 -(l+r)/2 x y canonical z canonical 1 = 0 2/(t-b) 0 0 0 0 2/(n-f) 0 0 0 0 1 0 1 0 -(b+t)/2 0 0 1 -(n+f)/2 0 0 0 1 y z 1 The earlier transform took canonical coords and put them on the Screen. Combining that with the above: 2/(r-l) 0 0 -(l+r)/2 0 2/(t-b) 0 -(b+t)/2 M orth = 0 0 2/(n-f) -(n+f)/2 0 0 0 1 University of Victoria Graphics Lab. CSC 305 2017 page 15

Orthographic Projection: Now we can find pixel coordinates from some user defined view volume coordinates: projection transform 2/(r-l) 0 0 -(l+r)/2 0 2/(t-b) 0 -(b+t)/2 M orth = 0 0 2/(n-f) -(n+f)/2 0 0 0 1 = M vp viewport transform n x /2 0 0 (n x -1)/2 0 n y /2 0 (n y -1)/2 0 0 1 0 0 0 0 1 x pixel y pixel z canonical 1 = M 0 M vp M orth x y z 1 Note that z will be in [-1,1] useful later for z-buffer University of Victoria Graphics Lab. CSC 305 2017 page 16

Orthographic Projection Algorithm compute M vp compute M orth M=M 0 =M vp M orth for each line segment in 3D (a i, b i ) do { p = Ma i q = Mb i drawline(x p, y p, x q, y q ) } University of Victoria Graphics Lab. CSC 305 2017 page 17

Arbitrary View Positions e = Eye Position g = gaze direction t = view up vector W V t Derive a coordinate system with origin e and uvw basis W= U= - g g t x W t x W U e g V= W x U View up vector points to the sky! Bi-sects the viewers head as in photography. University of Victoria Graphics Lab. CSC 305 2017 page 18

Arbitrary View Positions View volume coordinates: origin o and xyz axes. need to convert these to origin e and uvw axes. We can use:! # M vrot = # # # " u x u y u z v x v y v z w x w y w z & & & & % " M v = M vrot # 1 0 0 x e 0 1 0 y e 0 0 1 z e 0 0 0 1 % & University of Victoria Graphics Lab. CSC 305 2017 page 19

Why is Mv computed this way?! # M vrot = # # # " u x u y u z v x v y v z w x w y w z & & & & % Orthogonal Matrix Properties upper 3x3 rotates row vectors into the major axes applies to any rotation matrix or rotation translation (+normalization). cosθ -sinθ 0 sinθ cosθ 0 0 0 1 cosθ -sin 0 = 1 0 0 University of Victoria Graphics Lab. CSC 305 2017 page 20

University of Victoria Graphics Lab. CSC 305 2017 page 21

University of Victoria Graphics Lab. CSC 305 2017 page 22

University of Victoria Graphics Lab. CSC 305 2017 page 23

Rodrigues Forumula https://en.wikipedia.org/wiki/rodrigues%27_rotation_formula If v is a vector in R 3 and k is a unit vector describing an axis of rotation about which v rotates by an angle θ according to the right hand rule, the Rodrigues formula is : v rot = vcosθ + (k v)sinθ + k(k v)(1 cosθ) University of Victoria Graphics Lab. CSC 305 2017 page 24

Example v y w u z x eye (6, 7.5, 8 ) vup t(0, 1, 0) atpt (0, 0, 0) gaze g= (0,0,0) (6,7.5,8) sqrt(6*6+7.5*7.5+8*8) = 12.5 w = -g/ g = (6/12.5, 7.5/12.5, 8/12.5 )=(0.48, 0.6, 0.64) u=(t x w)/ t x W v=(w x u) University of Victoria Graphics Lab. CSC 305 2017 page 25

Calculate U-vector w= 1/12.5 (6, 7.5, 8) t =(0, 1, 0) u=(t x w)/ t x w = (1/12.5)det i j k 0 1 0 6 7.5 8 t x w = 1/12.5 ( 8, -0.0, -6.0)= (0.6, 0.0, -0.48) t x w t x w 1/12.5 ( 8, -0.0, -6.0) = = ( 0.8, 0.0, -0.6) 1/12.5 * sqrt(64+36) University of Victoria Graphics Lab. CSC 305 2017 page 26

Calculate V-vector v = w x u w = 1/12.5 (6, 7.5, 8) u = ( 0.8, 0.0, -0.6) (1/12.5* 1/12.5) det i j k 6 7.5 8 10 0-7.5 v = 1/(12.5 *12.5)( -56.25, 35, -75) v = 1/12.5(-4.5, 10, -6) v = (-0.36, 0.8, -0.48) University of Victoria Graphics Lab. CSC 305 2017 page 27

Calculate M vrot " M vrot = #! # M vrot = # # # " 0.8 0.0 0.6 0.0 0.36 0.8 0.48 0.0 0.48 0.6 0.64 0.0 0.0 0.0 0.0 1.0 M % & u x u y u z v x v y v z w x w y w z & & & & % for eye at ( 6, 7.5, 8 ) Add last column and row For homogeneous coords check the matrix: 0.8 0.0-0.6-0.36 0.8-0.48 0.48 0.6 0.64 0.8 0.0-0.6 = 1 0 0 similarly 2 nd row into y-axis 3 rd row into z-axis University of Victoria Graphics Lab. CSC 305 2017 page 28

Orthographic Projection Algorithm Arbitrary View Point compute M v compute M 0 " M v = M vrot # M = M 0 M v for each line segment in 3D (a i, b i ) do { p = Ma i q = Mb i drawline(x p, y p, x q, y q ) } 1 0 0 x e 0 1 0 y e 0 0 1 z e 0 0 0 1 % & University of Victoria Graphics Lab. CSC 305 2017 page 29

3 Point Perspective Objective is to simulate this method University of Victoria Graphics Lab. CSC 305 2017 page 30

v u -w University of Victoria Graphics Lab. CSC 305 2017 page 31

Geometry for the View Volume v (0.5,0.5) up u w ( n + 0.5, n + 0.5) x y University of Victoria Graphics Lab. CSC 305 2017 page 32

True Perspective in 2D size of an object proportional to 1/z y s = (d/z) y y (x,y) g!!#!!! " d! #! " y s View Plane x University of Victoria Graphics Lab. CSC 305 2017 page 33

University of Victoria Graphics Lab. CSC 305 2017 page 34

Perspective View Transformation n f n f The view frustrum is an inconvenient shape. Clipping Z depth calculation Hidden surface calculation University of Victoria Graphics Lab. CSC 305 2017 page 35

Perspective View Transformation We want to find a matrix that 1. does not change points on z=n plane n f 2. maps large rectangle at z=f to small rectangle at z=n 3. achieve division by z by using homogeneous to cartesian conversion i.e. homogenize University of Victoria Graphics Lab. CSC 305 2017 page 36

Perspective Matrix M p = M p 1 0 0 0 0 1 0 0 0 0 n+f n -f 0 0 1 n 0 for homogenous point (x,y,z,1) = (x/h, y/h, z/h, h) " x% y z # 1& = " x y z n + f n z # n f % & Transforms lines to lines and planes to planes. Line segments in the view volume are transformed to line segments in the canonical view volume. hom ogenize(/ w) )))) z w = n " # nx z ny z n + f nf z 1 % & University of Victoria Graphics Lab. CSC 305 2017 page 37

Perspective Projection Algorithm We can now use the mechanism we used before for orthographic projection Again Arbitrary View Point compute M v compute M 0 compute M p M=M 0 M v M p for each line segment in 3D (a i, b i ) do { p = Ma i } q = Mb i x p, y p drawline(, x q, y q h h h h ) University of Victoria Graphics Lab. CSC 305 2017 page 38

Z-behavior as a result of Perspective Projection Matrix z s = n + f fn/z n=10 f=100 Points (lines and planes) outside viewing volume should be clipped. z s Fewer bits of resolution are available to compare z values far from the eye. Z-buffer does linear interpolation in Z. z University of Victoria Graphics Lab. CSC 305 2017 page 39