Lecture 4. Viewing, Projection and Viewport Transformations

Similar documents
Notes on Assignment. Notes on Assignment. Notes on Assignment. Notes on Assignment

Perspective transformations

Graphics pipeline and transformations. Composition of transformations

CS 4204 Computer Graphics

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

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

CSE328 Fundamentals of Computer Graphics

CSE528 Computer Graphics: Theory, Algorithms, and Applications

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:

OpenGL Transformations

Rasterization Overview

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

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

3D Viewing Episode 2

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

Computer Graphics. Chapter 10 Three-Dimensional Viewing

3D Viewing. CS 4620 Lecture 8

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

Viewing with Computers (OpenGL)

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

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

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

Three-Dimensional Viewing Hearn & Baker Chapter 7

1 OpenGL - column vectors (column-major ordering)

Projection and viewing. Computer Graphics CSE 167 Lecture 4

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

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

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

Game Architecture. 2/19/16: Rasterization

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

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

Models and The Viewing Pipeline. Jian Huang CS456

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

Computer Graphics 7: Viewing in 3-D

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

Drawing in 3D (viewing, projection, and the rest of the pipeline)

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

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

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

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

Surface Graphics. 200 polys 1,000 polys 15,000 polys. an empty foot. - a mesh of spline patches:

Viewing. Reading: Angel Ch.5

Prof. Feng Liu. Fall /19/2016

Drawing in 3D (viewing, projection, and the rest of the pipeline)

COMP3421. Introduction to 3D Graphics

Drawing in 3D (viewing, projection, and the rest of the pipeline)

Viewing COMPSCI 464. Image Credits: Encarta and

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

Visibility: Z Buffering

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

CS4620/5620: Lecture 14 Pipeline

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

The Graphics Pipeline and OpenGL I: Transformations!

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

COMP3421. Introduction to 3D Graphics

3.1 Viewing and Projection

CS451Real-time Rendering Pipeline

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

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

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

Advanced Computer Graphics (CS & SE )

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

Hidden surface removal. Computer Graphics

Hidden Surface Removal

Viewing and Projection

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

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

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

3D computer graphics: geometric modeling of objects in the computer and rendering them

COMP3421. Introduction to 3D Graphics

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

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

Computer Viewing Computer Graphics I, Fall 2008

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

Fachhochschule Regensburg, Germany, February 15, 2017

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

CSE452 Computer Graphics

CS Computer Graphics: Hidden Surface Removal

Page 1. Area-Subdivision Algorithms z-buffer Algorithm List Priority Algorithms BSP (Binary Space Partitioning Tree) Scan-line Algorithms

Three-Dimensional Graphics III. Guoying Zhao 1 / 67

Geometry: Outline. Projections. Orthographic Perspective

CSCI 4620/8626. The 2D Viewing Pipeline

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

Class of Algorithms. Visible Surface Determination. Back Face Culling Test. Back Face Culling: Object Space v. Back Face Culling: Object Space.

Announcement. Project 1 has been posted online and in dropbox. Due: 11:59:59 pm, Friday, October 14

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

Viewing and Projection

CS488. Implementation of projections. Luc RENAMBOT

CS 130 Final. Fall 2015

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

2D and 3D Viewing Basics

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

Hidden Surfaces II. Week 9, Mon Mar 15

Pipeline Operations. CS 4620 Lecture 14

Viewing and Projection

9. Visible-Surface Detection Methods

CS184 : Foundations of Computer Graphics Professor David Forsyth Final Examination

Computer Graphics. Lecture 9 Hidden Surface Removal. Taku Komura

CSE328 Fundamentals of Computer Graphics: Concepts, Theory, Algorithms, and Applications

Transcription:

Notes on Assignment

Notes on Assignment Hw2 is dependent on hw1 so hw1 and hw2 will be graded together i.e. You have time to finish both by next monday 11:59p Email list issues - please cc: elif@cs.nyu.edu when sending messages to the mailing list

Notes on Assignment Objects on screen - made of primitives Primitives are points, lines, polygons - watch vertex ordering The main object you need is a box When the MODELVIEW matrix is changed it applies to all vertices of the object that is drawn next

Notes on Assignment Hierarchical Design + stacks All matrices are 4x4-3d points + 1 homogeneous coordinate Use gl/glu/glut commands for debugging Camera motion which is needed for hw2- will be covered today Additional questions?

Lecture 4 Viewing, Projection and Viewport Transformations

List of Transformations 3D Object Coordinates Modeling Transformation 3D World Coordinates Viewing Transformation Projection Transformation Window-to-Viewport Transformation E.T. 06 p(x,y,z) p (x,y ) 3D Camera Coordinates 2D Screen Coordinates 2D Image Coordinates Done last week Make the monitor a free moving video camera perspective, parallel screen coords to viewport resolution

E.T. 06 OpenGL Transformation Pipeline Model = position of objects View = position and aim camera

Coordinate systems z x x Eye coordinates z World coordinates World coordinates - fixed initial coord system; everything is defined with respect to it Eye coordinates - coordinate system attached to the camera; in this system camera looks down negative Z-axis 2005, Denis Zorin

Positioning the camera Modeling transformation: reshape the object, orient the object, position the object with respect to the world coordinate system Viewing transformation: transform world coordinates to eye coordinates Viewing transformation is the inverse of the camera positioning transformation Viewing transformation should be rigid: rotation + translation Steps to get the right transform: first, orient the camera correctly, then translate it 2005, Denis Zorin

Positioning the camera Modeling transformation: reshape the object, orient the object, position the object with respect to the world coordinate system Viewing transformation: transform world coordinates to eye coordinates Viewing transformation is the inverse of the camera positioning transformation Viewing transformation should be rigid: rotation + translation Steps to get the right transform: first, orient the camera correctly, then translate it 2005, Denis Zorin

Initial Configuration z zw w0 xw xe ze x

E.T. 06 Translate camera by (tx,tz) z zw w0 tz tx z e x e x xw

E.T. 06 Initial Configuration z zw w0 xw xe ze x

E.T. 06 Viewing Transformation = Translate object by (-tx,-tz) z x e tx tz z w w0 x w z e x x w = xw - tx z w = zw - tz

Positioning the camera Modeling transformation: reshape the object, orient the object, position the object with respect to the world coordinate system Viewing transformation: transform world coordinates to eye coordinates Viewing transformation is the inverse of the camera positioning transformation Viewing transformation should be rigid: rotation + translation Steps to get the right transform: first, orient the camera correctly, then translate it 2005, Denis Zorin

OpenGL Viewing Transformation -- Set in display function glmatrixmode(gl_modelview); glloadidentity(); default is modelview and equals identity default = (0,0,-1) position camera is aimed at glulookat(cx,cy,cx,lx,ly,lz,ux,uy,uz) E.T. 06 Eye ( Camera ) Coordinates default = (0,0,0) Up Direction default = (0,1,0)

Look-at positioning Find the viewing transform given the eye (camera) position, point to look at, and the up vector Need to specify two transforms: rotation and translation. translation is easy natural rotation: define implicitly using a point at which we want to look and a vector indicating the vertical in the image (up vector) can easily convert the eye point to the direction vector of the camera axis; can assume up vector perpendicular to view vector 2005, Denis Zorin

Look-at Positioning Convert eye point to the direction vector of camera # Eye coords E.T. 06 $ " # " # "

Look-at Positioning Convert eye point to the direction vector of camera Assume up vector to be perpendicular to dir vec # Eye coords E.T. 06 $ " # " # "

Look-at Positioning Convert eye point to the direction vector of camera Assume up vector to be perpendicular to dir vec This gives you a pair of perpendicular vectors # Eye coords E.T. 06 $ " # " # "

Look-at positioning Problem: given two pairs of perpendicular unit vectors, find the transformation mapping the first pair into the second # $ " # " # Eye coords " World coords 2005, Denis Zorin

Look-at positioning Determine rotation first, looking how coord vectors change: # # # " " $ # " " " $ # " # " " $ # # " " " " # $ # # $" #,#, "% 2005, Denis Zorin

Look-at positioning Recall the matrix for translation: $ # % " " % " % " " % # " # & $ Now we have the camera positioning matrix, $ To get the viewing transform, invert: &$' # $ For rotation the inverse is the transpose # &" #'$ # $" # # "% $ # " # $ $ " $ 2005, Denis Zorin

Look-at viewing transformation " # " # # " # " # " " # # " " # # # # " $ % & $# # " # # "% $ % " # && '' $ && ( ') ( "' ' $ &' ( "' & $ && ( "' $#) #) #% " $ % & 2005, Denis Zorin

Implementation Notes for the Viewing Positioning the camera in OpenGL Text Transformation imagine that the camera is an object and write a sequence of rotations and translations positioning it change each transformation in the sequence to the opposite (inverse) reverse the sequence Camera positioning is done in the code before modeling transformations OpenGL does not distinguish between viewing and modeling transformation and joins them into the modelview matrix 2005, Denis Zorin

E.T. 06 p(x,y,z) 3D Object Coordinates Modeling Transformation 3D World Coordinates Viewing Transformation 3D Camera Coordinates Projection Transformation Window-to-Viewport Transformation p (x,y ) 2D Screen Coordinates 2D Image Coordinates

E.T. 06 OpenGL Transformation Pipeline Map viewing volume to cube [-1,1]x[-1,1]x[-1,1] (a.k.a. canonical view volume)

E.T. 06 Projection Transformations Think of this as selecting the lens (i.e. wide-angle, telephoto, fisheye, etc) Describe the viewing volume How an object is projected onto the screen Which objects or portions of objects are get clipped

Projection Transformations -Set in reshape func ( since relevant to screen ) glmatrixmode(gl_projection); glloadidentity(); Orthographic Projection Perspective Projection E.T. 06 box pyramid/frustum

E.T. 06 Orthographic Projection viewing volume - rectangular parallelepiped(=box) preserves parallelism translating camera doesn t change size but may change visibility no foreshortening - less realistic default in opengl - cube centered at (0,0,0), side = 2 but useful in architecture and cad where actual angles and sizes important

Orthographic Projection up glortho(left, right, bottom, top, near, far); gluortho2d(left, right, bottom, top); E.T. 06 project 2D image to 2D screen(e.g. text)

Orthogonal Projection 2 Steps: Translate to center the parallelepiped at 0. 1 0 0 r+l 2 0 1 0 t+b 2 0 0 1 f+n 2 0 0 0 1 Scale in all directions s.t. it ends up as a cube of size 2 centered at 0. ST = 2 r l 0 0 r+l r l 0 2 t b 0 t+b t b 2 0 0 f n 0 0 0 1 2 r l 0 0 0 2 0 t b 0 0 2 0 0 f n 1 0 0 0 1 f+n f n

E.T. 06 Perspective Projection Farther the object is from camera, the smaller it appears in image. ==> Realism Parallelism not preserved Translating camera may change size of objects Not good for measurements. Achieved by specifying the volume as a frustum (truncated pyramid, with apex at camera)

Viewing Frustum Volume in space that will be visible in the image not necessarily symmetric glfrustum(left, right, bottom, top, near, far ); note: near>far

E.T. 06 Perspective Projection gluperspective(fovy,aspect,near,far); (in degrees) symmetric in x and y

Projection transformation Behind the Scenes Maps the viewing frustum into a standard cube extending from -1 to 1 in each coordinate (normalized device coordinates) 3 steps: canonical view volume 2005, Denis Zorin

Projection transformation Behind the Scenes 3 steps: perspective transformation orthogonal projection 2005, Denis Zorin change the matrix of projection to keep z: result is a parallelepiped translate: parallelepiped centered at 0 scale in all directions: cube of of size 2 centered at 0 2005, Denis Zorin

Space to plane projection In eye coordinate system z y v Image plane # " " " " " # $ " " " " # projecting to the plane z = -1 # $ $ % & ' ( # ) " # $ # # # " $ # # # # $ $%&'(#) % " # " " " " # " " " " # " " " # " # & % $ " # # " # # # # & $ 2005, Denis Zorin

Space to plane projection In eye coordinate system z y v Image plane # " " " " " # $ " " " " # projecting to the plane z = -1 # $ $ % & ' ( # ) " # $ # # # " $ # # # # $ $%&'(#) % " # " " " " # " " " " # " " " # " # & % $ " # # " # # # # & $ 2005, Denis Zorin

Projection transformation $ $ " " " $%&'() # " " " " % " " change % # " " " & # # & so that we keep z: " " " " # " " " " " " " " " " " " $ % & " # " # $ % & # " # " # the homogeneous result corresponds to $ % & # " # "" # " # $ & the last component increases monotonically with z 2005, Denis Zorin

Projection transformation " # " " " " " " " " " " " " $ % & maps the frustum to an axis-aligned parallelepiped 1/" 1/ #$% & z # #$% & already centered in (x,y), center in z-direction and scale: $ ' " # 2005, Denis Zorin " " " " " " " " & " ( " " " " $ % & % ' " # # #$% " " " " #$% " " & " " # $ " " " " " " " $ % &

Projection transformation Combined matrix, mapping frustum to a cube: & ' %$ " # " " " " " " " " " " " " $ % & ' " # # #$% " " " " #$% " " " ( " " & " " " " " " $ % & To get normalized image plane coordinates (valid range [-1,1] both), just drop z in the result and convert from homogeneous to regular. To get pixel coordinates, translate Perspective by 1, Division and scale x and y (Viewport transformation) 2005, Denis Zorin

E.T. 06 -z eye position z-axis viewing frustum -y Cross section at x=0

E.T. 06 Points (0,yi,zi,1) Plot of (zi,yi) Multiply each point by projection transformation to get

E.T. 06 Points (0,yi,zi,1) Plot of (zi,yi) Multiply each point by projection transformation to get Points (0, yi,1,-zi) Plot of (-1/zi, -yi/zi)

E.T. 06 already centered in (x,y), center in z-direction and scale: $ ' " # 2005, Denis Zorin " " " " " " " " & " ( " " " " $ % & = # #$% " " " 1 0 0 0 0 1 " 0 % ' #$% 0 " " 0 & 0 " 1.2667 " # $ " " # " 0 0 0 1 " " " " " $ % & mult each point by T

E.T. 06 S = 1 r tan(α/2) 0 0 0 1 0 tan(α/2) 0 0 2 0 0 0 ( 1 f 1 n ) 0 0 0 1 = 2 0 0 0 0 2 0 0 0 0 15 0 0 0 0 1 mult each point by S

Remember the Pipeline:

Clipping Removal or modification of primitives based on whether they fall within a viewing volume. Done against Canonical View Volume. Why? Parameter free. Only values you need to know for clipping volume are -1 and 1 Aligned with coordinate axes - inside outside trivial (and efficient - no need for dot products)

Additional Clipping Can define up to 6 other clipping planes Then points will pass iff intersection of viewing volume and all half spaces define clipping planes as Ax+By+Cz+D =0 (A B C D) M -1 (x y z 1) T >= 0 glclipplane(gl_clip_planei) glenable(gl_clip_planei) This is done in eye coordinates

Remember the Pipeline: p x p y p z p z homogenize then discard z component p x /p z p y /p z p z /p z 1 p x/p z p y /p z 1 = normalized image plane coordinates ([-1,1] in x and y)

E.T. 06 p(x,y,z) 3D Object Coordinates Modeling Transformation 3D World Coordinates Viewing Transformation 3D Camera Coordinates Projection Transformation 2D Screen Coordinates Window-to-Viewport Transformation p (x,y ) 2D Image Coordinates

E.T. 06 OpenGL Transformation Pipeline map square [-1,1]x[-1,1] to image

E.T. 06 Viewport Transformation Set in reshape ( screen dependent ) Allows scales/stretches of image Refers to size and location of image you see on screen Defines the rectangular region of the window where the image is drawn OpenGL: glviewport(x, y, width, height); Default - entire window: (0,0, w,h) Lower left corner

Viewport Transformation Idea is to transform [-1,1]x[-1,1] to [0,w]x[0,h] Behind the scenes Translate by (1,1) Scale x by w and y by x y -1 1 w

Viewport Transformation Aspect Ratio Issues

E.T. 06 Visibility Objects close to the camera occlude those that are further away. Should be the case in the final image that we draw Default - latest drawn object covers older ones

Visibility One option: Object-Space Approach For all pairs of polygons compare against each other choose from display/no display/partial display For each polygon compare against n-1 others

Another option: Visibility Sort objects in the scene from farthest to closest : Painters Algorithm not practical adding/removing objects in the scene in the front? back? not very efficient need to compute distances from eye draw pixels that will be covered sorting - usually BSP Trees

Visibility Objects that are closer to the camera occlude the objects that are further away All objects are made of planar polygons A polygon typically projects 1 to 1 idea: project polygons in turn ; for each pixel, record distance to the projected polygon when writing pixels, replace the old color with the new one only if the new distance to camera for this pixel is less then the recorded one hidden surface removal 2005, Denis Zorin

2005, Denis Zorin Z-buffering idea Problem: need to compare distances for each projected point Solution: convert all points to a coordinate system in which (x,y) are image plane coords and the distance to the image plane increases when the z coordinate increases decreases In OpenGL, this is done by the projection matrix Red text refers to the negative z case

Z buffer Assumptions: can have other comparison funcs here defined by gldepthfunc 2005, Denis Zorin each pixel has storage for a z-value, in addition to RGB all objects are scanconvertible (typically are polygons, lines or points) Algorithm: initilize zbuf to maximal value for each object for each pixel (i,j) obtained by scan conversion if znew(i,j) < zbuf(i,j) if znew(i,j) > zbuf(i,j) zbuf(i,j) = znew(i,j) ; write pixel(i,j)

Z buffer What are z values? Z values are obtained by applying the projection transform, that is, mapping the viewing volume frustum to the standard cube. Z value increases with th distance to the camera. Remember the discarded z values Z values for each pixel are computed for each pixel covered by a polygon during using perspective linear interpolation division? of z values at vertices. Typical Z buffer size: 24 bits (same as RGB combined). 2005, Denis Zorin

Z buffer What are z values? Z values are obtained by applying the projection transform, that is, mapping the viewing volume frustum to the standard cube. Z value increases with th distance to the camera. decreases Z values for each pixel are computed for each pixel covered by a polygon using linear interpolation of z values at vertices. Typical Z buffer size: 24 bits (same as RGB combined). 2005, Denis Zorin

Z Buffer - brief analysis Pros simple to implement(hw/sw) loops over polygons compatible with pipeline architectures Cons Large amount of memory Often waste of rendering resources for obscured objects

Z Buffer - OpenGL Notes Depth Buffer glutinitdisplaymode(glut_depth... ); glenable(gl_depth_test); glclear( GL_DEPTH_BUFFER_BIT... );