Objectives Derive the perspective projection matrices used for standard OpenGL projections Derive the perspective projection matrices used for standard.

Slides:



Advertisements
Similar presentations
Computer Graphics - Viewing -
Advertisements

1 Computer Graphics Chapter 8 3D Transformations.
1 View Shandong University Software College Instructor: Zhou Yuanfeng
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Projection Matrices modified by Ray Wisman Ed Angel Professor of Computer.
Projection Matrices CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Based on slides created by Edward Angel
Viewing and Projections
Projection Matrices Ed Angel
Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing
Viewing Doug James’ CG Slides, Rich Riesenfeld’s CG Slides, Shirley, Fundamentals of Computer Graphics, Chap 7 Wen-Chieh (Steve) Lin Institute of Multimedia.
4.1si31_2001 SI31 Advanced Computer Graphics AGR Lecture 4 Projection Clipping Viewport Transformation.
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Viewing and Projections Mon 22 Sep 2003 project 1 solution demo recap: projections.
1 Chapter 5 Viewing. 2 Perspective Projection 3 Parallel Projection.
Projection Projection - the transformation of points from a coordinate system in n dimensions to a coordinate system in m dimensions where m
CS 480/680 Computer Graphics Representation Dr. Frederick C Harris, Jr. Fall 2012.
Computer Graphics (fall 2009)
1 Projection Matrices. 2 Objectives Derive the projection matrices used for standard OpenGL projections Introduce oblique projections Introduce projection.
2 COEN Computer Graphics I Evening’s Goals n Discuss the mathematical transformations that are utilized for computer graphics projection viewing.
CS559: Computer Graphics Lecture 9: Projection Li Zhang Spring 2008.
1 E. Angel and D. Shreiner : Interactive Computer Graphics 6E © Addison-Wesley 2012 Classical Viewing Sai-Keung Wong ( 黃世強 ) Computer Science National.
Chapter 5 Viewing.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 67 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 67 Computer Graphics Three-Dimensional Graphics III.
Computer Graphics Bing-Yu Chen National Taiwan University.
Foundations of Computer Graphics (Fall 2012) CS 184, Lectures 13,14: Reviews Transforms, OpenGL
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 5.
Demetriou/Loizidou – ACSC330 – Chapter 5 Viewing Dr. Giorgos A. Demetriou Computer Science Frederick Institute of Technology.
CAP4730: Computational Structures in Computer Graphics 3D Transformations.
Geometric Objects and Transformation
Computer Graphics I, Fall 2010 Computer Viewing.
Viewing and Projection. 2 3 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009  Introduce the classical views  Compare and contrast image.
CS559: Computer Graphics Lecture 9: Rasterization Li Zhang Spring 2008.
OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.
CSE Real Time Rendering Week 5. Slides(Some) Courtesy – E. Angel and D. Shreiner.
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)
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
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.
1 Graphics CSCI 343, Fall 2015 Lecture 18 Viewing III--More Projection.
Viewing and Projection
CS5500 Computer Graphics April 23, Today’s Topic Details of the front-end of the 3D pipeline: –How to construct the viewing matrix? –How to construct.
1 Representation. 2 Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames.
Viewing and Projection. The topics Interior parameters Projection type Field of view Clipping Frustum… Exterior parameters Camera position Camera orientation.
Classical Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Viewing Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
CS5500 Computer Graphics March 20, Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Computer Viewing Isaac Gang University of Mary Hardin-Baylor.
Viewing 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
Computer Graphics - Chapter 5 Viewing
CSE 167 [Win 17], Lecture 5: Viewing Ravi Ramamoorthi
CSC461: Lecture 20 Parallel Projections in OpenGL
Unit 4 3D Viewing Pipeline Part - 2
Projections and Normalization
CSC461: Lecture 19 Computer Viewing
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Isaac Gang University of Mary Hardin-Baylor
Projections and Hidden Surface Removal
Introduction to Computer Graphics with WebGL
Chap 3 Viewing Pipeline Reading:
Introduction to Computer Graphics with WebGL
Interactive Computer Graphics Viewing
Viewing and Projection
Viewing and Projection
Presentation transcript:

Objectives Derive the perspective projection matrices used for standard OpenGL projections Derive the perspective projection matrices used for standard OpenGL projections Introduce shadows Introduce shadows CSC461: Lecture 21 Perspective Projections in OpenGL

Simple Perspective Consider a simple perspective with the COP at the origin, the near clipping plane at z = -1 (d=1) Consider a simple perspective with the COP at the origin, the near clipping plane at z = -1 (d=1) Simple projection matrix in homogeneous coordinates Simple projection matrix in homogeneous coordinates Note that this matrix is independent of the far clipping plane Note that this matrix is independent of the far clipping plane M =

Simple Perspective View Volume A 90 degree field of view determined by the planes A 90 degree field of view determined by the planes Intersect the projection plane at 45 degree Intersect the projection plane at 45 degree This givesx =  z, y =  z This givesx =  z, y =  z Near plane z = near (<0) Near plane z = near (<0) Far plane z = far (<0) Far plane z = far (<0) far > near far > near To find a projection matrix, we normalize it to default view volume To find a projection matrix, we normalize it to default view volume

Generalization Consider the matrix Consider the matrix where α and β to be specified  N is called perspective normalization matrix  For any point on object p=(x y z 1) T, applying N, the new point q =(x’ y’ z’ w’) T, where x’=x, y’=y, z ’= αz + β, w’=-z  A  After perspective division, the point (x, y, z, 1) goes to αβ x’’ = -x/z, y’’ = -y/z, z’’ = -( α + β /z) N =N =N =N =

Projection Matrix Apply an orthographic projection along the z-axis to N, which projects orthogonally to the desired point regardless of a and b Project point p to p’: Project point p to p’: Do perspective division: Do perspective division: M orth N = p’=M orth Np = p’= Conclusion: to obtain the perspective projection, to three steps: applying N, orthographic projection, and perspective division Conclusion: to obtain the perspective projection, to three steps: applying N, orthographic projection, and perspective division

Picking  and  If we pick 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  =  =

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

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 ’  preserves the ordering of depths 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 ’  preserves the ordering of depths Thus we hidden surface removal works if we first apply the normalization transformation Thus we 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 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

OpenGL Perspective glFrustum allows for an unsymmetric viewing frustum glFrustum allows for an unsymmetric viewing frustum gluPerspective does not gluPerspective does not

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

Shear and Scaling Shear the point ((x far +x near )/2, (y far +y near )/2) to (0,0,near)  Shear matrix: Shear the point ((x far +x near )/2, (y far +y near )/2) to (0,0,near)  Shear matrix: H(θ,ø)=H(cot -1 ((x far +x near )/(2far)), cot -1 ((y far +y near )/(2far))) cot -1 ((y far +y near )/(2far))) Results: x= (x far -x near )/(2far) Results: x=  (x far -x near )/(2far) y= (y far -y near )/(2far) y=  (y far -y near )/(2far) z=near, z=far Scale the sides of the frustum to x = y = Scale the sides of the frustum to x = y =  z without changing the near and the far plane  scaling matrix: S(2far/(x far -x near ), 2far/(y far -y near ), 1)

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

Projections and Shadows Default light source is assumed at the COP Default light source is assumed at the COP With default light source, all shadows are invisible (behind the visible objects) With default light source, all shadows are invisible (behind the visible objects) General lighting will be the topic of the next chapter. General lighting will be the topic of the next chapter. Some special cases related to projections are discussed here Some special cases related to projections are discussed here

Shadow Polygon Shadow falls on the ground y = 0, forming a shadow polygon Shadow falls on the ground y = 0, forming a shadow polygon Shadow polygon is the projection of the object onto the ground with the COP at the light source Shadow polygon is the projection of the object onto the ground with the COP at the light source To draw the shadow polygon To draw the shadow polygon Move the origin to the light source  translation T(-x l,-y l,-z l ) Move the origin to the light source  translation T(-x l,-y l,-z l ) Perspective projection with the projection plane y = 0  M= Perspective projection with the projection plane y = 0  M= Translate back  T(x l,y l,z l ) Translate back  T(x l,y l,z l )

OpenGL Code GLFloat m[16] = {…}; //set the dadow projection matrix glColor3fv(polygon_color)glBegin(GL_POLYGON)… …// draw polygon …glEnd(GL_POLYGON)glMatrixMode(GL_MODELVIEW);glPushMatrix(); //move back glTranslatef(xl,yl,zl); // project glMultMatrixf(m); // move light to origin glTranslatef(-xl,-yl,-zl);glColor3f(shadow_color);glBegin(GL_POLYGON); … //re-draw polygon glEnd);glPopMatrix()