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

Similar documents
Lecture 4. Viewing, Projection and Viewport Transformations

Perspective transformations

Graphics pipeline and transformations. Composition of transformations

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

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

CSE328 Fundamentals of Computer Graphics

CS 4204 Computer Graphics

Overview. By end of the week:

CSE528 Computer Graphics: Theory, Algorithms, and Applications

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

Computer Graphics. Chapter 10 Three-Dimensional Viewing

Rasterization Overview

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

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

Viewing with Computers (OpenGL)

OpenGL Transformations

3D Viewing Episode 2

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

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

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

Projection and viewing. Computer Graphics CSE 167 Lecture 4

Game Architecture. 2/19/16: Rasterization

Three-Dimensional Viewing Hearn & Baker Chapter 7

1 OpenGL - column vectors (column-major ordering)

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

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

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

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

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

Computer Graphics 7: Viewing in 3-D

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

The Graphics Pipeline and OpenGL I: Transformations!

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

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

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

Models and The Viewing Pipeline. Jian Huang CS456

Viewing. Reading: Angel Ch.5

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

3D Viewing. CS 4620 Lecture 8

COMP3421. Introduction to 3D Graphics

Prof. Feng Liu. Fall /19/2016

CS451Real-time Rendering Pipeline

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

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

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

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

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

3.1 Viewing and Projection

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

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

COMP3421. Introduction to 3D Graphics

Viewing COMPSCI 464. Image Credits: Encarta and

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

Viewing and Projection

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

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

CSE452 Computer Graphics

Computer Viewing Computer Graphics I, Fall 2008

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

Visibility: Z Buffering

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

Viewing and Projection

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

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

Advanced Computer Graphics (CS & SE )

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

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

Viewing and Projection

COMP3421. Introduction to 3D Graphics

CSCI 4620/8626. The 2D Viewing Pipeline

CS184 : Foundations of Computer Graphics Professor David Forsyth Final Examination

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

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

Fachhochschule Regensburg, Germany, February 15, 2017

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

Hidden surface removal. Computer Graphics

GEOMETRIC TRANSFORMATIONS AND VIEWING

3D Viewing Episode 2

CS 130 Final. Fall 2015

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

CS Computer Graphics: Hidden Surface Removal

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

CS 112 The Rendering Pipeline. Slide 1

The Graphics Pipeline and OpenGL I: Transformations!

CS4620/5620: Lecture 14 Pipeline

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

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

CS488. Implementation of projections. Luc RENAMBOT

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

Geometry: Outline. Projections. Orthographic Perspective

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

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

Three-Dimensional Graphics III. Guoying Zhao 1 / 67

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

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

2D and 3D Viewing Basics

OpenGL: Open Graphics Library. Introduction to OpenGL Part II. How do I render a geometric primitive? What is OpenGL

Recall: Indexing into Cube Map

Transcription:

Notes on Assignment 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 Extensions - 4 days before (Thu by midnight) not guaranteed Ask questions IN CLASS. Notes on Assignment Hierarchical Design + stacks Camera motion - will be covered today All matrices are 4x4-3d points + 1 homogeneous coordinate Use gl/glu/glut commands for debugging

OpenGL Pipeline Lecture 4 Viewing, Projection and Viewport s Model = position of objects View = position and aim camera p(x,y,z) 3D Object Coordinates Modeling 3D World Coordinates Viewing Projection Window-to-Viewport p (x,y ) List of s 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 2005, Denis Zorin Coordinate systems z x Eye coordinates x 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

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 Translate camera by (tx,tz) z zw w0 xw Viewing transformation is the inverse of the camera positioning transformation Viewing transformation should be rigid: rotation + translation tz tx x e z e x Steps to get the right transform: first, orient the camera correctly, then translate it 2005, Denis Zorin Initial Configuration Initial Configuration z zw z zw w0 w0 xw xw xe xe ze x ze x

Viewing = z x e Translate object by (-tx,-tz) z e tx tz z w w0 x x w x w = xw - tx z w = zw - tz 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 OpenGL Viewing glmatrixmode(gl_modelview); Look-at Positioning Convert eye point to the direction vector of camera glloadidentity(); position camera is aimed at glulookat(cx,cy,cx,lx,ly,lz,ux,uy,uz) Eye coords Eye ( Camera ) Coordinates Up Direction

Look-at Positioning Convert eye point to the direction vector of camera Assume up vector to be perpendicular to dir vec Eye coords 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 Look-at positioning Problem: given two pairs of perpendicular unit vectors, find the transformation mapping the first pair into the second 2005, Denis Zorin 2005, Denis Zorin Eye coords World coords Look-at positioning Determine rotation first, looking how coord vectors change:,,

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 2005, Denis Zorin Implementation Notes for the Viewing Text Positioning the camera in OpenGL 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 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 Look-at viewing transformation p(x,y,z) 3D Object Coordinates Modeling 3D World Coordinates Viewing 3D Camera Coordinates '' ' ( ' ' ' ( ' ( ' ) ) Projection Window-to-Viewport p (x,y ) 2D Screen Coordinates 2D Image Coordinates 2005, Denis Zorin

OpenGL Pipeline Projection s glmatrixmode(gl_projection); glloadidentity(); Orthographic Projection Perspective Projection Map viewing volume to cube [-1,1]x[-1,1]x[-1,1] Projection s Think of this as selecting the lens Describe the viewing volume How an object is projected onto the screen Which objects or portions of objects are get clipped Orthographic Projection viewing volume - rectangular parallelepiped(=box) 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 Viewing frustum Volume in space that will be visible in the image is the aspect ratio of the image width/height y z glortho(left, right, bottom, top, near, far); gluortho2d(left, right, bottom, top); 2005, Denis Zorin glfrustum(left, right, bottom, top, near, far); Perspective Projection Farther the object is from camera, the smaller it appears in image. ==> Realism 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) 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) Space to plane projection In eye coordinate system z y v Image plane projecting to the plane z = -1 3 steps: a.k.a canonical view volume '() '() 2005, Denis Zorin 2005, Denis Zorin orthogonal projection 3 steps: perspective transformation 2005, Denis Zorin Projection transformation Behind the Scenes 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 Space to plane projection In eye coordinate system '() z y Image plane v '() projecting to the plane z = -1 2005, Denis Zorin 2005, Denis Zorin

Projection transformation '() change so that we keep z: the homogeneous result corresponds to the last component increases monotonically with z -z -y viewing frustum eye position Cross section at x=0 z-axis 2005, Denis Zorin Projection transformation maps the frustum to an axis-aligned parallelepiped 1/ 1/ z Points (0,yi,zi,1) Plot of (zi,yi) already centered in (x,y), center in z-direction and scale: ' ( ' Multiply each point by projection transformation to get 2005, Denis Zorin

Points (0,yi,zi,1) Plot of (zi,yi) 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 Multiply each point by projection transformation to get Points (0, yi,1,-zi) mult each point by S Plot of (-1/zi, -yi/zi) already centered in (x,y), center in z-direction and scale: ' ( 2005, Denis Zorin = mult each point by T 1 0 0 0 0 1 0 ' 0 0 0 1.2667 0 0 0 1 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

Remember the Pipeline: Remember the Pipeline: homogenize then discard z component p x p y p z p z 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) 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) p(x,y,z) Modeling Viewing Projection Window-to-Viewport p (x,y ) 3D Object Coordinates 3D World Coordinates 3D Camera Coordinates 2D Screen Coordinates 2D Image Coordinates

OpenGL Pipeline map square [-1,1]x[-1,1] to image Viewport 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 Refers to size 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 Aspect Ratio Issues

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 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 One option: Visibility 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 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 2005, Denis Zorin

Z-buffering idea Z buffer 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 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 2005, Denis Zorin Z buffer Z buffer Assumptions: 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) 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 2005, Denis Zorin

Pros Z Buffer - brief analysis 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... );