Virtual Cameras and The Transformation Pipeline

Similar documents
Rasterization Overview

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

The Graphics Pipeline and OpenGL I: Transformations!

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

Projection and viewing. Computer Graphics CSE 167 Lecture 4

Models and The Viewing Pipeline. Jian Huang CS456

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

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

CS559 Computer Graphics Fall 2015

Overview. By end of the week:

CSE328 Fundamentals of Computer Graphics

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

The Graphics Pipeline and OpenGL I: Transformations!

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Viewing with Computers (OpenGL)

Pipeline Operations. CS 4620 Lecture 14

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

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

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

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

Overview. By end of the week:

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

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

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

Lecture 4. Viewing, Projection and Viewport Transformations

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

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

CS 432 Interactive Computer Graphics

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

CS451Real-time Rendering Pipeline

The Importance of Matrices in the DirectX API. by adding support in the programming language for frequently used calculations.

CSC 305 The Graphics Pipeline-1

Viewing. Reading: Angel Ch.5

3D Viewing. CS 4620 Lecture 8

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

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

COMS 4160: Problems on Transformations and OpenGL

Game Architecture. 2/19/16: Rasterization

COMP3421. Introduction to 3D Graphics

1 OpenGL - column vectors (column-major ordering)

CS 4204 Computer Graphics

CGT520 Transformations

Computer Graphics. Lecture 04 3D Projection and Visualization. Edirlei Soares de Lima.

OpenGL Transformations

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

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

Chapter 5. Projections and Rendering

Lecture 5: Transforms II. Computer Graphics and Imaging UC Berkeley CS184/284A

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

Camera Model and Calibration

Three-Dimensional Viewing Hearn & Baker Chapter 7

Transforms 3: Projection Christian Miller CS Fall 2011

CS 418: Interactive Computer Graphics. Projection

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

Pipeline Operations. CS 4620 Lecture 10

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

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

Virtual Cameras & Their Matrices

Beginning Direct3D Game Programming: 6. First Steps to Animation. Division of Digital Contents, DongSeo University.

Prof. Feng Liu. Fall /19/2016

Geometry: Outline. Projections. Orthographic Perspective

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

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

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

Wire-Frame 3D Graphics Accelerator IP Core. C Library Specification

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

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

Geometric transformations in 3D and coordinate frames. Computer Graphics CSE 167 Lecture 3

GEOMETRIC TRANSFORMATIONS AND VIEWING

Computer Graphics. Ch 6. 3D Viewing

Computer Graphics Coursework 1

CS 130 Final. Fall 2015

CS 4620 Midterm, October 23, 2018 SOLUTION

COMP3421. Introduction to 3D Graphics

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

Transformation. Computer Graphics October. Dr Anton Gerdelan

Sign up for crits! Announcments

Lab 2-3D Transformations and Vertex Shaders

Viewing. Cliff Lindsay, Ph.D. WPI

CS464 Oct 3 rd Assignment 3 Due 10/6/2017 Due 10/8/2017 Implementation Outline

Advanced Computer Graphics Transformations. Matthias Teschner

Three Main Themes of Computer Graphics

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

Computer Graphics 7: Viewing in 3-D

CHAPTER 1 Graphics Systems and Models 3

Viewing COMPSCI 464. Image Credits: Encarta and

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

Friday, 11 January 13. Object Representation

MORE OPENGL. Pramook Khungurn CS 4621, Fall 2011

CS4620/5620: Lecture 14 Pipeline

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

Computer Graphics - Treasure Hunter

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

Today. Today. Introduction. Matrices. Matrices. Computergrafik. Transformations & matrices Introduction Matrices

A Conceptual and Practical Look into Spherical Curvilinear Projection By Danny Oros

CMSC427 Final Practice v2 Fall 2017

Projection Matrix Tricks. Eric Lengyel

Rendering Objects. Need to transform all geometry then

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

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Transcription:

Virtual Cameras and The Transformation Pipeline Anton Gerdelan gerdela@scss.tcd.ie with content from Rachel McDonnell 13 Oct 2014

Virtual Camera We want to navigate through our scene in 3d Solution = create a transformation pipeline Move all points relative to some arbitrary view point, such that the view point is the new (0,0,0) origin Also project our scene with a perspective rather than orthogonal view

Transformation Pipeline Coordinate Spaces * model matrix * view matrix * projection matrix perspective division (x,y,z) / w vertex shader output

Transformation Pipeline Coordinate Spaces * model matrix * view matrix??? * projection matrix perspective division (x,y,z) / w vertex shader output

Local Space When you create a triangle or Load a mesh from a file Has some (0,0,0) origin, local to that particular mesh Translate, rotate, scale to position in a virtual world Multiply points with a model matrix aka world matrix mat4 M = T * R * S; vec4 pos_wor = M * vec4 (pos_loc, 1.0);

World Space Objects positioned in scene or virtual world Has a world (0,0,0) origin Can get distances between objects Now we want to show the view from a camera, moving through the virtual world Multiply world space points by a view matrix to get to eye space mat4 V = R * T; // inverse of cam pos & angle mat4 V = lookat (vec3 pos, vec3 target, vec3 up); vec4 pos_eye = M * pos_wor;

What the View Matrix Does

View Matrix Right xyz Up xyz -Forward xyz -Position xyz Careful now!

lookat(vec3 eye, vec3 look, vec3 up) Typical maths library function Returns mat4 Sets camera position Point at target Careful with up unit vector Not ideal for full 3d rotation

lookat(vec3 eye, vec3 look, vec3 up) Rem: view matrix needs Right Forward Up Position (set of 3d vectors) Q1: How can we work out forward?

lookat(vec3 eye, vec3 look, vec3 up) vec3 f = normalise(look eye); Q2. How can we work out right from up and forward?

lookat() vec3 r = cross(f, up); // recalc up to be sure vec3 u = normalise (cross (r, f)); mat4 T = translate (-eye); mat4 R = plug-in r,u,-f return R * T; Q3. Why did I re-calculate up? Q4. What would happen if I did cross(up, f) instead? Q5. What must you do if camera pitches up/down?

Q1. What is the cross product of these vectors? [0.0, 0.0, 1.0] X [1.0, 0.0, 0.0] Q2. How do you normalise a 4d vector? [10.0, 0.0, 0.0, 0.0]

Rotation Method Limitations Calculating from fixed-axis X*Y*Z rotation matrices LookAt() is good for panning, not great for flight sims quaternions better suited to creating rotation matrix with full 3d rotation Euler axis & angle in 4 numbers then some multiplications to get a 4X4 rotation matrix Good for local pitch/yaw/roll Arbitrary Euler axis

Transformation Pipeline Coordinate Spaces * model matrix * view matrix * projection matrix perspective division (x,y,z) / w vertex shader output

Eye Space Objects positioned relative to view point and direction Has an eye origin (0, 0, 0) Our view area is still -1 to 1 on XYZ. Our view is still a parallel (orthogonal/orthographic) projection. Q. How can we manipulate the projection?

What We Have Now Q. How can we make our view cover more of the scene?

Orthographic Projection Matrix Zi + Zf Zi - Zf - Zi Q. What affine matrices does this look similar to?

How can we approximate a cone of view? Has to map to a 2d rectangular view, not a circle (well...we could do a circle) Has to have minimum and maximum cut-of distances Some sort of angle of view We had a cuboid before for orthographic Q. What 3d geometric shape is this?

Perspective Projection

Typical Perspective Function mat4 perspective ( float fovy, float aspect, float znear, float zfar ); Fovy is field of view y-axis angle from horizon to top convert to radians Aspect ratio is (float)width / (float)height of viewport Near and far are clip planes 0.1 and 1000.0 are typical

A Symmetric Perspective Matrix Q. An aspect of 2.0 means? Wrong aspect = distortion Depth bufer precision (ranges of z) has only so many bits per pixel. Smaller zfar / znear ratio = more precision As znear -> 0, zfar -> infinity??? 1.0 / tan (fovy * 0.5); Do not make znear = 0.0

FOV Beware comparisons of angle of view Older games etc. used horizontal angles of view ~90 degrees These also had fixed-aspect displays: 320x200 (2.5:4) 320x240, 640x480, etc. -> (3:4) = 1.3333... LookAt() etc. Use vertical angles 90 degrees horiz. / 1.333333 = 67.5 degrees vert.

Transformation Pipeline Coordinate Spaces * model matrix * view matrix * projection matrix perspective division (x,y,z) / w vertex shader output

Homogenous Clip Space Geometry outside near/far xyz clip planes is clipped after the VS Q. How will we map our frustum area onto a 2d drawing surface? Hint: The orthographic cuboid was easy.?

Perspective Division A. We will squish in the large back end until it is a -1 to 1 XYZ box. Q. How? Hint: Some of you did this in Assignment 0

Perspective Division Vertex shader output is a 4d variable gl_position = P * V * M * vec4 (vp, 1.0); gl_position = vec4 (x, y, z, w); After the VS, a built-in mechanism does position = vec3 (gl_position.xyz / gl_position.w); Q. What does the perspective matrix do to w?

Perspective Division

Transformation Pipeline Coordinate Spaces * model matrix * view matrix * projection matrix perspective division (x,y,z) / w vertex shader output

Normalised Device Space All coordinates are between -1 and 1 the unit cube This is very easy to scale by # pixels wide and high Project to 2d Front/back face select and cull if enabled Rasterise to pixels/fragments

Typical Vertex Shader w/ Camera #version 400 in vec3 vertex_point, vertex_normal; uniform mat4 P, V, M; out vec3 p_eye, n_eye; void main () { gl_position = P * V * M * vec4 (vertex_point, 1.0); p_eye = V * M * vec4 (vertex_point, 1.0); n_eye = V * M * vec4 (vertex_normal, 0.0); } Order of multiplication is fundamentally important Never compare variables from diferent coordinate spaces Use a postfix or prefix naming convention for variables useful for lighting

Normalised Device Space All coordinates are between -1 and 1 the unit cube This is very easy to scale by # pixels wide and high Project to 2d Front/back face select and cull if enabled Rasterise to pixels/fragments

Depth Testing (automatic step) and The Depth Bufer Edwin Catmull again PhD thesis 1974, U. Utah. Whenever we write a fragment it writes the colour to the framebufer's colour bufer (a big 2d image) But first...if depth testing is enabled It checks another 2d image called the depth bufer If its own depth is smaller/closer it overwrites both the depth and colour bufer pixels Q. What does this do? Can we disable the depth testing and try?

Depth Bufer Smaller value = farther away Bigger = closer In F.Shader use built-in gl_fragcoord.w to get this value and use as a colour

Reading List and Practical Tasks Shirley & Marschner Fundamentals Ch. 7 Viewing Akenine Moeller et. al Real-Time Rendering Ch. 2 and 4.6 Projections (very good) Know how to work out the pipeline by hand on paper for 1 vertex & M, V, and P Hint: add a print_matrix(m) function to check contents

rd 3 Assignment - Viewing Due next week! Start way ahead of time (easy to get into a transformations mess) If you finish early, get a head start on game project skills: Play Upgrade Load a mesh? Full 3d camera controls? make all the mistakes ask for advice now (discussion boards)