Projection and viewing. Computer Graphics CSE 167 Lecture 4

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

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

Today. Rendering pipeline. Rendering pipeline. Object vs. Image order. Rendering engine Rendering engine (jtrt) Computergrafik. 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

CSE 167: Introduction to Computer Graphics Lecture #5: Visibility, OpenGL

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

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

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

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

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

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

Models and The Viewing Pipeline. Jian Huang CS456

CSE 167: Introduction to Computer Graphics Lecture #3: Coordinate Systems

Rasterization Overview

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

CSE 167: Introduction to Computer Graphics Lecture #5: Illumination Model

Lecture 4. Viewing, Projection and Viewport Transformations

CS 498 VR. Lecture 18-4/4/18. go.illinois.edu/vrlect18

Geometry: Outline. Projections. Orthographic Perspective

3D Viewing. CS 4620 Lecture 8

The Graphics Pipeline and OpenGL I: Transformations!

Topic #1: Rasterization (Scan Conversion)

Culling. Computer Graphics CSE 167 Lecture 12

Transforms 3: Projection Christian Miller CS Fall 2011

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

CSE528 Computer Graphics: Theory, Algorithms, and Applications

CSE328 Fundamentals of Computer Graphics

Virtual Cameras and The Transformation Pipeline

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

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

COMS 4160: Problems on Transformations and OpenGL

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

Viewing with Computers (OpenGL)

Projection Matrix Tricks. Eric Lengyel

Overview. By end of the week:

CS 381 Computer Graphics, Fall 2012 Midterm Exam Solutions. The Midterm Exam was given in class on Tuesday, October 16, 2012.

VISIBILITY & CULLING. Don t draw what you can t see. Thomas Larsson, Afshin Ameri DVA338, Spring 2018, MDH

Models and Architectures

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

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

CSE452 Computer Graphics

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

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

Viewing. Reading: Angel Ch.5

Game Architecture. 2/19/16: Rasterization

The Graphics Pipeline and OpenGL I: Transformations!

Perspective Projection and Texture Mapping

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

Clipping and Scan Conversion

CS4620/5620: Lecture 14 Pipeline

Pipeline Operations. CS 4620 Lecture 14

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

Introduction to Computer Graphics with WebGL

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

CS Computer Graphics: Hidden Surface Removal

Visibility: Z Buffering

CS451Real-time Rendering Pipeline

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

Hidden Surfaces II. Week 9, Mon Mar 15

Computer Graphics. Bing-Yu Chen National Taiwan University The University of Tokyo

Fondamenti di Grafica 3D The Rasterization Pipeline.

Projections and Hardware Rendering. Brian Curless CSE 557 Fall 2014

Three-Dimensional Viewing Hearn & Baker Chapter 7

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

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

Computing Visibility. Backface Culling for General Visibility. One More Trick with Planes. BSP Trees Ray Casting Depth Buffering Quiz

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Real-Time Shadows. Last Time? Today. Why are Shadows Important? Shadows as a Depth Cue. For Intuition about Scene Lighting

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

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

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

RASTERISED RENDERING

Painter s HSR Algorithm

CS 4204 Computer Graphics

CSE528 Computer Graphics: Theory, Algorithms, and Applications

CS 130 Exam I. Fall 2015

S U N G - E U I YO O N, K A I S T R E N D E R I N G F R E E LY A VA I L A B L E O N T H E I N T E R N E T

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

Computer Graphics 7: Viewing in 3-D

Computer Graphics Shadow Algorithms

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

Perspective transformations

Last Time. Why are Shadows Important? Today. Graphics Pipeline. Clipping. Rasterization. Why are Shadows Important?

Pipeline Operations. CS 4620 Lecture 10

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

Computer Graphics. Lecture 9 Hidden Surface Removal. Taku Komura

Computer Graphics. Lecture 9 Environment mapping, Mirroring

Friday, 11 January 13. Object Representation

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

9. Visible-Surface Detection Methods

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

1 OpenGL - column vectors (column-major ordering)

Procedural modeling and shadow mapping. Computer Graphics CSE 167 Lecture 15

Computer Graphics Viewing

COMP3421. Introduction to 3D Graphics

Hidden surface removal. Computer Graphics

For Intuition about Scene Lighting. Today. Limitations of Planar Shadows. Cast Shadows on Planar Surfaces. Shadow/View Duality.

Shadow Algorithms. CSE 781 Winter Han-Wei Shen

OpenGL Transformations

Real-Time Shadows. Last Time? Textures can Alias. Schedule. Questions? Quiz 1: Tuesday October 26 th, in class (1 week from today!

Transcription:

Projection and viewing Computer Graphics CSE 167 Lecture 4

CSE 167: Computer Graphics Review: transformation from the object (or model) coordinate frame to the camera (or eye) coordinate frame Projection Perspective projection Projective homogeneous coordinates Projective transformation Orthographic projection Viewing CSE 167, Winter 2018 2

Review: coordinate frames Object (or model) coordinate frame World coordinate frame Camera (or eye) coordinate frame Camera (or eye) coordinates Object (or model) coordinates World coordinates CSE 167, Winter 2018 3

Transformations Model Transformation M View Transformation V Object (or Model) Coordinate Frame World Coordinate Frame Camera (or Eye) Coordinate Frame Camera (or eye) coordinates World coordinates Object (or model) coordinates Transform from object (or model) coordinate frame to camera (or eye) coordinate frame using a 4x4 transformation modelview matrix CSE 167, Winter 2018 4

Next step: projection Projection of 3D objects in camera coordinate frame to 2D image CSE 167, Winter 2018 5

Perspective Projection Parallel lines are no longer parallel, converge in one point Based on slides courtesy of Jurgen Schulze Earliest example: La Trinitá (1427) by Masaccio CSE 167, Winter 2018 6

Perspective Projection Simplified model of pinhole camera or human eye Things farther away appear to be smaller Discovery attributed to Filippo Brunelleschi (Italian architect) in the early 1400 s CSE 167, Winter 2018 7

Perspective Projection Project along rays that converge in center of projection Center of projection 3D scene 2D image plane CSE 167, Winter 2018 8

Perspective Projection From law of ratios in similar triangles follows: y ' y1 y 1 y' d z1 z 1 d Similarly: x' x1d z 1 By definition: z' d Image plane Perspective projection requires division CSE 167, Winter 2018 9

Homogeneous coordinates revisited 3D point using inhomogeneous coordinates as 3 vector 3D point using affine homogeneous coordinates as 4 vector CSE 167, Winter 2018 10

Homogeneous coordinates 3D point using affine homogeneous coordinates as 4 vector 3D point using projective homogeneous coordinates as 4 vector (up to scale) CSE 167, Winter 2018 11

Homogeneous coordinates Projective homogeneous 3D point to affine homogeneous 3D point Dehomogenize 3D point CSE 167, Winter 2018 12

Homogeneous coordinates Homogeneous points are defined up to a nonzero scale CSE 167, Winter 2018 13

Homogeneous coordinates When W = 0, then it is a point at infinity Affine homogeneous coordinates are projective homogeneous coordinates where W = 1 When not differentiating between affine homogeneous coordinates and projective homogeneous coordinates, simply call them homogeneous coordinates CSE 167, Winter 2018 14

Perspective Projection x' y' z' d x1d z1 y1d z 1 Projection matrix Homogeneous division CSE 167, Winter 2018 15

Perspective Projection Projection matrix P Using projection matrix, homogeneous division seems more complicated than just multiplying all coordinates by d/z, so why do it? It will allow us to: Handle different types of projections in a unified way Define arbitrary view frustum CSE 167, Winter 2018 16

Camera (or eye) coordinate frame All objects in pyramid of vision are potentially imaged by the camera or seen by the eye Pyramid of vision Up +Y Backward +X +Z Right CSE 167, Winter 2018 17

View frustum Truncate pyramid of vision with near and far clipping planes Near and far planes are usually parallel to camera X Y plane Objects outside the view frustum are clipped Up +Y Backward +X +Z Right CSE 167, Winter 2018 18

Perspective projection transformation 3D projective transformation from the view frustum in the camera (or eye) coordinate frame to the canonical view volume in the normalized device coordinate frame Note: this is a left handed coordinate system View frustum in Canonical view volume in camera (or eye) coordinate frame normalized device coordinate frame CSE 167, Winter 2018 19

Perspective projection transformation General view frustum with 6 parameters Camera coordinates CSE 167, Winter 2018 20

Perspective projection transformation Symmetrical view volume y y=top FOV z Side view of frustum z= near Only 4 parameters Vertical field of view (FOV) Image aspect ratio (width/height) Near, far clipping planes z= far right left aspect ratio= top bottom right top tan(fov /2) top near CSE 167, Winter 2018 21

Perspective projection transformation Symmetrical view frustum with field of view, aspect ratio, near and far clip planes y y=top Camera coordinates FOV z Side view of frustum z= near z= far 1 0 0 0 aspect tan(fov /2) 1 0 0 0 P persp (FOV,aspect,near, far) tan(fov /2) near far 0 0 near far 0 0 1 0 2 near far near far CSE 167, Winter 2018 22

Perspective projection transformation Mapping of Z is nonlinear Depth resolution in not uniform The previous projection transformations preserve depth on near and far planes Very high precision at the near plane Very low precision at the far plane The distance between near and far should be as small as possible to minimize precision issues Do not set near = 0, far = infinity Setting near = 0 loses depth resolution CSE 167, Winter 2018 23

Orthographic projection transformation 3D projective transformation from the view frustum in the camera (or eye) coordinate frame to the canonical view volume in the normalized device coordinate frame Parallel projection Note: this is a left handed coordinate system View frustum in Canonical view volume in camera (or eye) coordinate frame normalized device coordinate frame CSE 167, Winter 2018 24

Orthographic projection transformation Orthographic projection transformation is much simpler than perspective projection transformation Used in many games CSE 167, Winter 2018 25

Transformations Model Transformation M View Transformation V Object (or Model) Coordinate Frame World Coordinate Frame Projection Transformation P Camera (or Eye) Coordinate Frame Normalized Device Coordinate Frame Transform from object (or model) coordinate frame to normalized device coordinate frame using a 4x4 transformation modelview projection matrix CSE 167, Winter 2018 26

Viewport Transformation After applying projection matrix, scene points are in normalized device coordinates Per definition within range [ 1..1] x [ 1..1] x [ 1..1] Next is projection from 3D to 2D (not reversible) Normalized viewing coordinates can be mapped to image coordinates y Range depends on viewport Scale and translation required: window viewport (x 1, y 1 ) Dx 0, x 1, y 0, y 1 x 1 x 0 2 0 0 x 0 x 1 0 y 1 y 0 2 0 y 0 y 1 0 0 1 2 12 0 0 0 1 2 2 (x 0, y 0 ) x CSE 167, Winter 2018 27

Transformations Object (or Model) Coordinate Frame Model Transformation M View Transformation V Projection Transformation P World Coordinate Frame Camera (or Eye) Coordinate Frame Object (or Model) coordinates World coordinates Camera (or Eye) coordinates Normalized device coordinates Window coordinates Viewport Transformation D Normalized Device Coordinate Frame Window Coordinate Frame CSE 167, Winter 2018 28

Visibility At each pixel, we need to determine which triangle is visible CSE 167, Winter 2018 29

Painter s Algorithm Paint from back to front Need to sort geometry according to depth Every new pixel always paints over previous pixel in frame buffer May need to split triangles if they intersect Intuitive, but outdated algorithm created when memory was expensive Needed for translucent geometry even today CSE 167, Winter 2018 30

Z Buffering Store z value for each pixel Depth test Initialize z buffer with farthest z value During rasterization, compare stored value to new value Update pixel only if new value is smaller setpixel(int x, int y, color c, float z) if(z<zbuffer(x,y)) then zbuffer(x,y) = z color(x,y) = c z buffer is dedicated memory reserved in GPU memory Depth test is performed by GPU very fast CSE 167, Winter 2018 31

Z Buffering in OpenGL In OpenGL applications: Ask for a depth buffer when you create your GLFW window glfwopenwindow(512, 512, 8, 8, 8, 0, 16, 0, GLFW_WINDOW) Place a call to glenable(gl_depth_test) in your program's initialization routine Ensure that your znear and zfar clipping planes are set correctly (glm::perspective(fovy, aspect, znear, zfar)) and in a way that provides adequate depth buffer precision Pass GL_DEPTH_BUFFER_BIT as a parameter to glclear CSE 167, Winter 2018 32

Z Buffer Fighting Problem: polygons which are close together do not get rendered correctly Errors change with camera perspective flicker Cause: different colored fragments from different polygons are being rasterized to same pixel and depth not clear which is in front of which Solutions: Move surfaces farther apart, so that fragments rasterize into different depth bins Bring near and far planes closer together Use a higher precision depth buffer Note that OpenGL often defaults to 16 bit even if your graphics card supports 24 bit or 32 bit depth buffers CSE 167, Winter 2018 33

Translucent Geometry Need to depth sort translucent geometry and render with Painter s Algorithm (back to front) Problem: incorrect blending with cyclically overlapping geometry Solutions: Back to front rendering of translucent geometry (Painter s Algorithm), after rendering opaque geometry Does not always work correctly: programmer has to weigh rendering correctness against computational effort Theoretically: need to store multiple depth and color values per pixel (not practical in real time graphics) CSE 167, Winter 2018 34