Games Development 1 Camera Projection / Picking CO3301 Week 8.

Slides:



Advertisements
Similar presentations
Exploration of bump, parallax, relief and displacement mapping
Advertisements

Understanding the graphics pipeline Lecture 2 Original Slides by: Suresh Venkatasubramanian Updates by Joseph Kider.
Graphics Pipeline.
Projection Matrix Tricks Eric Lengyel Outline  Projection Matrix Internals  Infinite Projection Matrix  Depth Modification  Oblique Near Clipping.
HCI 530 : Seminar (HCI) Damian Schofield. HCI 530: Seminar (HCI) Transforms –Two Dimensional –Three Dimensional The Graphics Pipeline.
Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing
Lecture 3 – Transformation And Coordinate Systems
Game Engine Design ITCS 4010/5010 Spring 2006 Kalpathi Subramanian Department of Computer Science UNC Charlotte.
CHAPTER 7 Viewing and Transformations © 2008 Cengage Learning EMEA.
Introduction to 3D Graphics Lecture 3: General Camera Model Anthony Steed University College London.
Picking. What is picking? Selecting an object on the screen What does this require? –Get Mouse Location –Compute what objects are rendered at the position.
Transformations Aaron Bloomfield CS 445: Introduction to Graphics
COMP 175: Computer Graphics March 24, 2015
Viewing and Projections
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
CSE 381 – Advanced Game Programming Basic 3D Graphics
01/28/05© 2005 University of Wisconsin Last Time Improving Monte Carlo Efficiency.
Sky Rendering The actual physics is very complicated and costly to calculate. Several cheap approaches for very distant skies: –Constant backdrop –Skybox.
02/26/02 (c) 2002 University of Wisconsin, CS 559 Last Time Canonical view pipeline Orthographic projection –There was an error in the matrix for taking.
Computer Graphics Texture Mapping
Week 2 - Wednesday CS361.
Computer Graphics World, View and Projection Matrices CO2409 Computer Graphics Week 8.
Week 5 - Wednesday.  What did we talk about last time?  Project 2  Normal transforms  Euler angles  Quaternions.
CS559: Computer Graphics Lecture 9: Projection Li Zhang Spring 2008.
Advanced Computer Graphics Depth & Stencil Buffers / Rendering to Textures CO2409 Computer Graphics Week 19.
CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica.
Computer Graphics Bing-Yu Chen National Taiwan University.
CSC 461: Lecture 3 1 CSC461 Lecture 3: Models and Architectures  Objectives –Learn the basic design of a graphics system –Introduce pipeline architecture.
UW EXTENSION CERTIFICATE PROGRAM IN GAME DEVELOPMENT 2 ND QUARTER: ADVANCED GRAPHICS The Geometry Pipeline.
Foundations of Computer Graphics (Fall 2012) CS 184, Lectures 13,14: Reviews Transforms, OpenGL
Emerging Technologies for Games Alpha Sorting and “Soft” Particles CO3303 Week 15.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Computer Graphics The Rendering Pipeline - Review CO2409 Computer Graphics Week 15.
1Computer Graphics Lecture 4 - Models and Architectures John Shearer Culture Lab – space 2
CAP4730: Computational Structures in Computer Graphics 3D Transformations.
Advanced Computer Graphics Advanced Shaders CO2409 Computer Graphics Week 16.
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
SE 313 – Computer Graphics Lecture 8: Transformations and Projections Lecturer: Gazihan Alankuş 1.
CS 450: COMPUTER GRAPHICS PROJECTIONS SPRING 2015 DR. MICHAEL J. REALE.
Advanced Computer Graphics Shadow Techniques CO2409 Computer Graphics Week 20.
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.
Computer Graphics Rendering 2D Geometry CO2409 Computer Graphics Week 2.
Mark Nelson 3d projections Fall 2013
Computer Graphics Blending CO2409 Computer Graphics Week 14.
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)
Computer Graphics Camera Projection / Picking CO2409 Week 8 - Optional Advanced Material Not on Exam.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Foundations of Computer Graphics (Spring 2012) CS 184, Lecture 5: Viewing
©2005, Lee Iverson Lee Iverson UBC Dept. of ECE EECE 478 Viewing and Projection.
Chapter III Rasterization
Maths & Technologies for Games Graphics Optimisation - Batching CO3303 Week 5.
Taxonomy of Projections FVFHP Figure Taxonomy of Projections.
Computer Graphics Matrices
Viewing and Projection
Coordinate Systems Lecture 1 Fri, Sep 2, The Coordinate Systems The points we create are transformed through a series of coordinate systems before.
OpenGL and You I Cast, Therefore I Am. Ray Casting Idea is simple, implementation takes some work –Cast rays as if you were the camera –Determine intersection.
Viewing and Projection. The topics Interior parameters Projection type Field of view Clipping Frustum… Exterior parameters Camera position Camera orientation.
Introduction to Computer Graphics
- Introduction - Graphics Pipeline
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2016
CSE 167 [Win 17], Lecture 5: Viewing Ravi Ramamoorthi
3D Computer Graphics (3080/GV10) Week 5-6 Tutorial 3
CSCE 441 Computer Graphics 3-D Viewing
CSC461: Lecture 20 Parallel Projections in OpenGL
CENG 477 Introduction to Computer Graphics
The Graphics Rendering Pipeline
CS451Real-time Rendering Pipeline
Computer Graphics Lecture 20
Projection in 3-D Glenn G. Chappell
Chapter V Vertex Processing
Presentation transcript:

Games Development 1 Camera Projection / Picking CO3301 Week 8

Today’s Lecture 1.World / View Matrices Recap 2.Projection Maths 3.Pixel from World-Space Vertex 4.World Space Ray from Pixel Note: Formulae from this lecture are not examinable. However, discussion of the general process may be expected

Recap: Model Space An entity’s mesh is defined in its own local coordinate system - model space Each entity instance is positioned with a matrix –Transforming it from model space into world space This is the world matrix

Recap: World to Camera Space Next we consider how the entities are positioned and oriented relative to the camera Convert the models from world space into camera space –The scene as viewed from camera’s position This transformation is done with the view matrix

Camera to Viewport Space Finally project the camera space entities into 2D The 3D vertices are projected to camera position Assume the viewport is an actual rectangle in the scene Calculate where the rays hit the viewport = 2D geometry This is done (in part) with the projection matrix

Projection Details Cameras have internal settings: –Field of view ( fov ) –Clip distances – near and far ( z n, z f ) Near clip distance is from camera position to viewport –Where the geometry “slices” through the viewport Far clip distance is furthest that we can see fov is similar to selection of wide angle or zoom lens –fov can be different for width and height – fov x & fov y

Projecting a Vertex Consider projection of a 3D vertex (x, y, z) from camera space into 2D Call 2D viewport coords (x v, y v ) –y values not shown on diagram Calculate using similar triangles: x / z = x v / z n Similarly y / z = y v / z n So: x v = xz n / z & y v = yz n / z (1) Now have 2D coordinates, but still in world/camera space units

Actual Size of Viewport The 2D point (x v, y v ) calculated above is still measured in world units The viewport (part of the camera) has a physical presence in the world Calculate its physical dimensions to help convert this 2D point to pixel units Use camera settings to calculate viewport width & height: w v & h v tan(fov x /2) = (w v / 2) / z n so w v = 2z n tan(fov x / 2) (2) h v = 2z n tan(fov y / 2)

Converting to Viewport Space First convert 2D point to viewport space before calculating pixel coordinates In viewport space, on-screen coordinates range from –1 to 1 –Independent of viewport resolution Divide 2D coords from (1) by physical viewport dimensions (2) to get viewport space point (x n, y n ) x n = x v / (w v / 2) = 2x v / w v (3) y n = y v / (h v / 2) = 2y v / h v

Combining Steps Started with a 3D camera space point (x, y, z) Have showed three steps to get a resolution-independent 2D viewport space point (x n, y n ) Combining and simplifying the 3 steps gives: x n = x / (z tan(fov x / 2)) y n = y / (z tan(fov y / 2)) This is the perspective projection (division by tan ) and perspective divide (division by z ) In the rendering pipeline, the projection step is performed by the projection matrix –We haven’t previously looked at its operation

Perspective Projection Matrix This is a typical perspective projection matrix: –Other (e.g. non-perspective) types are possible Apply this to a camera space point (x, y, z) : –Note the 4 th ( w ) component becomes the original z value

After the Projection Matrix Note how the x and y coordinate are similar to the projection equations we manually derived Final step is to divide the x, y and z coordinates by the original camera-space z –The perspective divide mentioned earlier –The w component is used as it has the original z value Note that the d value (in the z component) is also divided, leaving it in the range 0 to 1 –This is the value used for the depth buffer –Explaining why our 2D vertices have 4 components: 2D x & y, depth buffer value (in z) and original camera space z (in w) In the rendering pipeline, the projection matrix is usually applied in the vertex shader Perspective divide occurs after shaders (in hardware)

Converting to Pixels Finally map the coordinates (x n, y n ) from range -1 to 1 to final pixel coordinates (x p, y p ) If the viewport width & height (in pixels) are w p & h p then x p = w p (x n + 1) / 2 y p = h p (1 - y n ) / 2 –Map to 0=>1 range then scale to viewport pixel dimensions –Second formula also flips the Y axis (viewport Y is down) This usually occurs in hardware

Picking Sometimes we need to manually perform the projection process: –To find the pixel for a particular 3D point –E.g. To draw text/sprites in same place as a 3D model –E.g. To find 2D coordinate of portal vertices Or perform the process in reverse: –Each 2D pixel corresponds to a ray in 3D space (refer to the projection diagram) –Finding and working with this ray is called picking –E.g. to find the 3D object under the mouse The algorithms for both follow – they are derived from the previous slides

1) Pixel from World-Space Vertex Start with world space vertex P –Ensure it has a 4 th component w = 1.0f Multiply this vertex by combined view / projection matrix to give projected 2D point Q If Q.w < 0 then the vertex is behind us, discard Otherwise do perspective divide: Q.x /= Q.w and Q.y /= Q.w Finally, scale to pixel coordinates X, Y: X = (Q.x + 1) * (ViewportWidth / 2) Y = (1 - Q.y) * (ViewportHeight / 2) Use to draw text/sprites in same place as 3D entity

2a) World-Space Point From Pixel Given pixel coordinates (X, Y), first convert to projected 2D point Q: Q.x = X / (ViewportWidth / 2) - 1 Q.y = 1 – Y / (ViewportHeight / 2) We will calculate a result world-space point that is exactly on the clip plane, so: Q.z = 0 (the closest depth buffer value) Q.w = Z n (the near clipping distance) Undo the perspective divide: Q.x *= Q.w, Q.y *= Q.w and Q.z *= Q.w Multiply this vertex by the inverse of the combined view / projection matrix to give final 3D point

2b) World-Space Ray From Pixel The calculation above generates a world space point exactly on the near clip plane –As near to the camera as possible More frequently want a ray –A line projecting from a point in a given direction Ray start point is either the calculated point, or the camera position Ray direction is (calculated point – camera position) Cast ray through the scene to find nearest target Can use space partitions to help with this task