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

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

Computer Viewing and Projection. Overview. Computer Viewing. David Carr Fundamentals of Computer Graphics Spring 2004 Based on Slides by E.

Three-Dimensional Graphics III. Guoying Zhao 1 / 67

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

Introduction to Computer Graphics with WebGL

CS452/552; EE465/505. Intro to Lighting

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

Orthogonal Projection Matrices. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

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

Introduction to Computer Graphics with WebGL

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

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

Computer Viewing Computer Graphics I, Fall 2008

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

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

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

Fundamental Types of Viewing

Introduction to Computer Graphics 4. Viewing in 3D

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

Building Models. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Virtual Cameras & Their Matrices

On the Midterm Exam. Monday, 10/17 in class. Closed book and closed notes. One-side and one page cheat sheet is allowed. A calculator is allowed

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

CS 432 Interactive Computer Graphics

GEOMETRIC TRANSFORMATIONS AND VIEWING

CS354 Computer Graphics Viewing and Modeling

5.8.3 Oblique Projections

Viewing with Computers (OpenGL)

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

Viewing. Cliff Lindsay, Ph.D. WPI

CS452/552; EE465/505. Review & Examples

Viewing. Reading: Angel Ch.5

Three Main Themes of Computer Graphics

Overview. By end of the week:

CSE328 Fundamentals of Computer Graphics

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

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

Objectives. transformation. General Transformations. Affine Transformations. Notation. Pipeline Implementation. Introduce standard transformations

Lecture 4: Viewing. Topics:

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

CS452/552; EE465/505. Models & Viewing

3D Viewing Episode 2

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Computer Graphics (CS 543) Lecture 6a: Viewing & Camera Control. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

The Graphics Pipeline and OpenGL I: Transformations!

Viewing and Modeling

COMS 4160: Problems on Transformations and OpenGL

Three-Dimensional Viewing Hearn & Baker Chapter 7

Virtual Cameras and The Transformation Pipeline

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

CS 418: Interactive Computer Graphics. Projection

Visualisation Pipeline : The Virtual Camera

Viewing and Projection

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

Transformations. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Lecture 4. Viewing, Projection and Viewport Transformations

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

3D Viewing Episode 2

Transforms 3: Projection Christian Miller CS Fall 2011

Viewing and Projection

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

CS 4204 Computer Graphics

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

3.1 Viewing and Projection

Transformations. Rotation and Scaling

Models and The Viewing Pipeline. Jian Huang CS456

Viewing and Projection

COMP3421. Introduction to 3D Graphics

COMP3421. Introduction to 3D Graphics

To Do. Outline. Translation. Homogeneous Coordinates. Foundations of Computer Graphics. Representation of Points (4-Vectors) Start doing HW 1

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

THE VIEWING TRANSFORMATION

Computer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

The Graphics Pipeline and OpenGL I: Transformations!

CGT520 Transformations

Chapter 8 Three-Dimensional Viewing Operations

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

Last week. Machiraju/Zhang/Möller/Fuhrmann

Lecture 4: 3D viewing and projections

Lessons Learned from HW4. Shading. Objectives. Why we need shading. Shading. Scattering

TSBK03 Screen-Space Ambient Occlusion

Game Architecture. 2/19/16: Rasterization

OpenGL Transformations

CS452/552; EE465/505. Transformations

Computer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Chapter 5. Projections and Rendering

15. Clipping. Projection Transformation. Projection Matrix. Perspective Division

CS 543: Computer Graphics. Projection

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

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

COMP3421. Introduction to 3D Graphics

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

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

CHAPTER 1 Graphics Systems and Models 3

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

SUMMARY. CS380: Introduction to Computer Graphics Projection Chapter 10. Min H. Kim KAIST School of Computing 18/04/12. Smooth Interpolation

CS 112 The Rendering Pipeline. Slide 1

Rasterization Overview

Chap 7, 2008 Spring Yeong Gil Shin

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

Transcription:

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

Objectives Introduce the mathematics of projection Introduce OpenGL viewing functions Look at alternate viewing APIs 2

Computer Viewing There are three aspects of the viewing process, all of which should be / are implemented in the pipeline, - Positioning the camera Setting the model-view matrix - Selecting a lens Setting the projection matrix - Clipping Setting the view volume 3

The OpenGL Camera In OpenGL, initially the object and camera frames are the same - Default model-view matrix is an identity The camera is located at origin and points in the negative z direction OpenGL also specifies a default view volume that is a cube with sides of length 2 centered at the origin - Default projection matrix is an identity 4

Default Projection Default projection is orthographic 2 clipped out z= 5

Moving the Camera Frame If we want to visualize objects with both positive and negative z values we can either - Move the camera in the positive z direction Translate the camera frame - Move the objects in the negative z direction Translate the world frame Both of these views are equivalent and are determined by the model-view matrix - Want a translation (Translate(.,.,-d);) - d > 6

Moving Camera back from Origin default frames frames after translation by d d > 7

Moving Camera back from Origin default frames frames after translation by d d > World is actually being moved relative to camera frame. 8

Moving the Camera We can move the camera to any desired position by a sequence of rotations and translations Example: side view - Rotate the scene - Move it away from origin - Model-view matrix C = TR 9

OpenGL code Remember that last transformation specified is first to be applied // Using mat.h mat4 t = Translate(.,., -d); mat4 ry = RotateY(-9.); mat4 m = t*ry; This is code for moving world frame relative to camera frame. It is the inverse of the desired camera movement. 1

The LookAt Function The GLU library contained the function glulookat to form the required modelview matrix through a simple interface Note the need for setting an up direction - Should not be parallel to look-at direction Replaced by LookAt() in mat.h - Can concatenate with modeling transformations Example: isometric view of cube aligned with axes mat4 mv = LookAt(vec4 eye, vec4 at, vec4 up); 1 1

LookAt Function LookAt(eye, at, up) eye location of camera at look-at point up up vector 1 2

Other Viewing APIs The LookAt function is only one possible API for positioning the camera Others include - View reference point, view plane normal, view up (PHIGS, GKS-3D) - Yaw, pitch, roll - Elevation, azimuth, twist - Direction angles 1 3

Projections and Normalization The default projection in the eye (camera) frame is orthographic For points within the default view volume x p = x y p = y z p = Most graphics systems use view normalization - All other views are converted to the default view by transformations that determine the projection matrix - Allows use of the same pipeline for all views 1 4

Homogeneous Coordinate Representation x p = x y p = y z p = w p = 1 default orthographic projection p p = Mp M = 1 1 1 In practice, we can let M = I and set the z term to zero later 1 5

Simple Perspective Center of projection at the origin Projection plane z = d, d < 1 6

Perspective Equations Consider top and side views x z / d x p = z x / d y p = z y / d z p = d 1 7

1 8 Homogeneous Coordinate Form M = 1/ 1 1 1 d consider q = Mp where 1 z y x x y z z / d! " # # # # $ % & & & & q = p = x / (z / d) y / (z / d) d 1! " # # # # $ % & & & & =

Perspective Division However w 1, so we must divide by w to return from homogeneous coordinates This perspective division yields x p = x z / d y p = y z / d z p = d the desired perspective equations We will consider the corresponding clipping volume with mat.h functions that are equivalent to deprecated OpenGL functions 1 9

OpenGL Orthogonal Viewing Ortho(left,right,bottom,top,near,far) near and far measured from camera View volume specified in camera coordinates 2

OpenGL Perspective Frustum(left,right,bottom,top,near,far) Specified in camera coordinates 2 1

Using Field of View With Frustum it is often difficult to get the desired view Perspective(fovy, aspect, near, far) often provides a better interface front plane aspect = w/h 2 2

Projection Matrices CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science 2 3

Objectives Derive the projection matrices used for standard OpenGL projections Introduce oblique projections Introduce projection normalization 2 4

Normalization Rather than derive a different projection matrix for each type of projection, we can convert all projections to orthogonal projections with the default view volume This strategy allows us to use standard transformations in the pipeline and makes for efficient clipping 2 5

Pipeline View modelview transformation projection transformation 4D 3D perspective division nonsingular vertex shader output clipping against default cube projection 3D 2D 2 6

Notes We stay in four-dimensional homogeneous coordinates through both the modelview and projection transformations - Both these transformations are nonsingular - Default to identity matrices (orthogonal view) Normalization lets us clip against simple cube regardless of type of projection Delay final projection until end - Important for hidden-surface removal to retain depth information as long as possible 2 7

Orthographic Normalization Ortho(left,right,bottom,top,near,far) normalization find transformation to convert specified clipping volume to default left < right bottom < top near < far 2 8

Orthographic Matrix Two steps - Move center to origin T(-(left+right)/2, -(bottom+top)/2,(near+far)/2)) - Scale to have sides of length 2 S(2/(left-right),2/(top-bottom),2/(near-far)) P = ST = " $ $ $ $ $ $ $ $ $ # 2 right left 2 top bottom 2 near far right + left right left top + bottom top bottom far + near far near 1 % ' ' ' ' ' ' ' ' ' & 2 9

Final Projection Set z = Equivalent to the homogeneous coordinate transformation M orth = 1 1 1 Hence, general orthographic projection in 4D is P = M orth ST 3

Oblique Projections The OpenGL projection functions cannot produce general parallel projections such as However if we look at the example of the cube it appears that the cube has been sheared Oblique Projection = Shear + Orthographic Projection 3 1

General Shear top view side view 3 2

Shear Matrix xy shear (z values unchanged) H(θ,φ) = Projection matrix General case: 1 cot θ 1 cot φ 1 1 P = M orth H(θ,φ) P = M orth STH(θ,φ) 3 3

Equivalency 3 4

Effect on Clipping The projection matrix P = STH transforms the original clipping volume to the default clipping volume object top view z = 1 DOP clipping volume near plane far plane x = -1 z = -1 DOP x = 1 distorted object (projects correctly) 3 5

Simple Perspective Consider a simple perspective with the COP at the origin, the near clipping plane at z = -1, and a 9 degree field of view determined by the planes x = ±z, y = ±z 3 6

Perspective Matrices Simple projection matrix in homogeneous coordinates M = 1 1 1 1 x = x y = y z = z w = -z x = -x/z y = -y/z z = -1 Note that this matrix is independent of the far clipping plane 3 7

Generalization N = 1 1 α β 1 x = x y = y z = αz+β w = -z after perspective division, the point (x, y, z, 1) goes to x = -x/z y = -y/z z = -(α+β/z) which projects orthogonally to the desired point regardless of α and β 3 8

Picking α and β If we pick α = β = near + far far near 2near far near far z = -(α+β/z) the near plane is mapped to z = -1 the far plane is mapped to z =1 and the sides are mapped to x = ± 1, y = ± 1 Hence the new clipping volume is the default clipping volume 3 9

Normalization Transformation distorted object projects correctly original clipping volume original object new clipping volume 4

Normalization and Hidden-Surface Removal Although our selection of the form of the perspective matrices may appear somewhat arbitrary, it was chosen so that if z 1 > z 2 in the original clipping volume then the for the transformed points z 1 > z 2 Thus hidden surface removal works if we first apply the normalization transformation However, the formula z = -(α+β/z) implies that the distances are distorted by the normalization which can cause numerical problems especially if the near distance is small 4 1

OpenGL Perspective Frustum allows for an unsymmetric viewing frustum (although Perspective does not) Frustum(left,right,bottom,top,near,far) left < right bottom < top near < far near & far positive 4 2

OpenGL Perspective Perspective provides less flexible, but more intuitive perspective viewing Perspective(fov, aspect, near, far); Field of view in angles aspect: w/h near < far, both positive 4 3

OpenGL Perspective Matrix The normalization in Frustum requires an initial shear to form a right viewing pyramid, followed by a scaling to get the normalized perspective volume. Finally, the perspective matrix results in needing only a final orthographic transformation P = NSH our previously defined perspective matrix shear and scale 4 4

Why do we do it this way? Normalization allows for a single pipeline for both perspective and orthogonal viewing We stay in four dimensional homogeneous coordinates as long as possible to retain three-dimensional information needed for hidden-surface removal and shading We simplify clipping 4 5

Viewing OpenGL Code It s not too bad, thanks to Ed Angel In application model_view = LookAt(eye, at, up); projection = Ortho(left, right, bottom, top, near, far); or projection = Perspective( fov, aspect, near, far); In vertex shader gl_position = projection*model_view*vposition; 4 6

OpenGL code Remember that matrices are column major order in GLSL, so Transpose your matrices when sending them to the shaders! gluniformmatrix4fv(matrix_loc, 1, GL_TRUE, model_view); 4 7

Simple Mesh Format (SMF) Michael Garland http:// graphics.cs.uiuc.edu/~garland/ Triangle data List of 3D vertices List of references to vertex array define faces (triangles) Vertex indices begin at 1 48

Normal for Triangle plane n (p - p ) = n p 2 n = (p 2 - p ) (p 1 - p ) normalize n n/ n p p p 1 Note that right-hand rule determines outward face 4 9

Suggestions for HW5 Read in smf files & test with HW4 Transform centroid of bounding box to origin Calculate normal for each triangle Use normalized normal as color for triangle - Be sure to take absolute value Each triangle vertex will need its own color - This color is passed to the fragment shader Next implement LookAt feature Test with fixed eye point and orthographic projection 5

Suggestions for HW5 Make sure that your model is in the view volume defined by your ortho() function Recall that your view volume is defined in camera coordinates Send model-view and projection matrix to the vertex shader via uniform variable You should now be displaying an orthographic projection from an arbitrary camera location/orientation 5 1

Suggestions for HW5 Implement perspective projection - Think about the parameter values you use Define menu that allows user to pick projection type Make camera move with a keyboard() function User should be able to change the angle, height and radius of the camera location (in cylindrical coordinates) 5 2