Graphics pipeline and transformations. Composition of transformations

Similar documents
Perspective transformations

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

Lecture 4. Viewing, Projection and Viewport Transformations

Viewing with Computers (OpenGL)

CSE328 Fundamentals of Computer Graphics

GEOMETRIC TRANSFORMATIONS AND VIEWING

3D Viewing Episode 2

CSE528 Computer Graphics: Theory, Algorithms, and Applications

3D Viewing Episode 2

OpenGL Transformations

Transforms 1 Christian Miller CS Fall 2011

CS 4204 Computer Graphics

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

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

Overview. By end of the week:

Rasterization Overview

3D Geometry and Camera Calibration

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

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

CSE452 Computer Graphics

COMP3421. Introduction to 3D Graphics

Fachhochschule Regensburg, Germany, February 15, 2017

Real Time Reflections Han-Wei Shen

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

INTRODUCTION TO COMPUTER GRAPHICS. It looks like a matrix Sort of. Viewing III. Projection in Practice. Bin Sheng 10/11/ / 52

Three-Dimensional Viewing Hearn & Baker Chapter 7

COMP3421. Introduction to 3D Graphics

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

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

2D/3D Geometric Transformations and Scene Graphs

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

Perspective Mappings. Contents

COMP 175 COMPUTER GRAPHICS. Lecture 07: Scene Graph. COMP 175: Computer Graphics March 10, Remco Chang 07 Scene Graph

Affine Transformations in 3D

CS 130 Final. Fall 2015

COMP3421. Introduction to 3D Graphics

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

This week. CENG 732 Computer Animation. Warping an Object. Warping an Object. 2D Grid Deformation. Warping an Object.

Computer Graphics 7: Viewing in 3-D

The Graphics Pipeline and OpenGL I: Transformations!

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

Transformations. Examples of transformations: shear. scaling

Transformations. Rotation and Scaling

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

CS 432 Interactive Computer Graphics

3D Viewing. CS 4620 Lecture 8

COMP3421. Week 2 - Transformations in 2D and Vector Geometry Revision

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

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

Vector Algebra Transformations. Lecture 4

CV: 3D sensing and calibration

Computer Graphics. Chapter 10 Three-Dimensional Viewing

Viewing. Reading: Angel Ch.5

Models and The Viewing Pipeline. Jian Huang CS456

CHAPTER 1 Graphics Systems and Models 3

Viewing transformations. 2004, Denis Zorin

COMP Computer Graphics and Image Processing. 5: Viewing 1: The camera. In part 1 of our study of Viewing, we ll look at ˆʹ U ˆ ʹ F ˆʹ S

Two possible ways to specify transformations. Each part of the object is transformed independently relative to the origin

TSBK03 Screen-Space Ambient Occlusion

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

Computer Viewing Computer Graphics I, Fall 2008

CS251 Spring 2014 Lecture 7

Visualisation Pipeline : The Virtual Camera

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

GRAFIKA KOMPUTER. ~ M. Ali Fauzi

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

Today. Parity. General Polygons? Non-Zero Winding Rule. Winding Numbers. CS559 Lecture 11 Polygons, Transformations

1 OpenGL - column vectors (column-major ordering)

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

Where We Are: Static Models

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

UNIT 2 2D TRANSFORMATIONS

3D Mathematics. Co-ordinate systems, 3D primitives and affine transformations

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

CS 112 The Rendering Pipeline. Slide 1

Surface Graphics. 200 polys 1,000 polys 15,000 polys. an empty foot. - a mesh of spline patches:

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

CS488. Implementation of projections. Luc RENAMBOT

Computer Graphics Seminar

Chapter 5. Transforming Shapes

3D Viewing Transformations

Figure 1. Lecture 1: Three Dimensional graphics: Projections and Transformations

Institutionen för systemteknik

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

Chapter 3: Modeling Transformation

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

Mathematics 308 Geometry. Chapter 9. Drawing three dimensional objects

Math background. 2D Geometric Transformations. Implicit representations. Explicit representations. Read: CS 4620 Lecture 6

3D Graphics Pipeline II Clipping. Instructor Stephen J. Guy

Perspective projection and Transformations

Computer Graphics Geometric Transformations

CS451Real-time Rendering Pipeline

Geometry: Outline. Projections. Orthographic Perspective

CSC 305 The Graphics Pipeline-1

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

HIERARCHICAL TRANSFORMATIONS A Practical Introduction

CS 465 Program 4: Modeller

The Graphics Pipeline and OpenGL I: Transformations!

Transcription:

Graphics pipeline and transformations Composition of transformations Order matters! ( rotation * translation translation * rotation) Composition of transformations = matrix multiplication: if T is a rotation and S is a scaling, then applying scaling first and rotation second is the same as applying transformation given by the matrix TS (note the order). Reversing the order does not work in most cases

Homogeneous coordinates regular D point to homogeneous: 0 @ p x p y A p z 0 B @ p x p y p z C A homogeneous point to regular D: 0 B @ p x p y p z p w C A 0 @ p x=p w p y =p w p z =p w A Translation and scaling Similar to D; translation by a vector t = [t x ;t y ;t z ] Nonuniform scaling in three directions 0 0 t x 0 0 t y 0 0 t z 0 0 0 s x 0 0 0 0 s y 0 0 0 0 s z 0 0 0 0

Rotations around coord axes angle µ, around X axis: around Y axis: 0 0 0 cos µ 0 sinµ 0 0 0 0 0 cosµ sin µ 0 0 sinµ cos µ 0 sin µ 0 cosµ 0 0 0 0 0 0 0 around Z axis: cos µ sin µ 0 0 sin µ cos µ 0 0 0 0 0 0 0 0 note where the minus is! General rotations Given an axis (a unit vector) and an angle, find the matrix p k v p p k v rotated p p? rotated p? µ p? Only the component perpendicular to axis changes

General rotations (rotated vectors are denoted with 0 ) project p on v: the rest of p is the other component: rotate perp. component: add back two components: p k = (p;v)v p? = p (p;v)v p 0? = p? cos µ +(a v p? )sinµ p 0 = p 0? + p k Combine everything, using v p? = v p to simplify: p 0 =cosµ p + ( cos µ)(p;v)v +sinµ(v p) General rotations How do we write all this using matrices? p 0 =cosµ p + ( cos µ)(p;v)v +sinµ(v p) vxvxpx + vxvypy + vxvzpz vxvx vxvy vxvz (p;v)v = v yv xp x + v yv yp y + v yv zp z = v yv x v yv y v yv z v zv xp x + v zv yp y + v zv zp z v zv x v zv y v zv z (v p) = v zp y + v y p z v zp x v xp z = 0 v z v y v z 0 v x p x p y v yp x + v xp y v y v x 0 p z px p y p z cos µ Final result, the matrix for a general rotation around a by angle : 0 0 v x v x v x v y v x v z 0 v z v y 0 0 +( cos µ) v y v x v y v y v y v z +sin µ v z 0 v x 0 0 v z v x v z v y v z v z v y v x 0 µ

Composition of transformations Order matters! ( rotation * translation translation * rotation) Composition of transformations = matrix multiplication: if T is a rotation and S is a scaling, then applying scaling first and rotation second is the same as applying transformation given by the matrix TS (note the order). Reversing the order does not work in most cases Transformation order When we write transformations using standard math notation, the closest transformation to the point is applied first: TRSp = T (R(Sp)) first, the object is scaled, then rotated, then translated This is the most common transformation order for an object (scale-rotate-translate)

Building the arm Start: unit square Step : scale to the correct size Building the arm step : translate to the correct position step : add another unit square step : scale the second box step : rotate the second box step : translate the second box

Hierarchical transformations Positioning each part of a complex object separately is difficult If we want to move whole complex objects consisting of many parts or complex parts of an object (for example, the arm of a robot) then we would have to modify transformations for each part solution: build objects hierarchically Hierarchical transformations Idea: group parts hierarchically, associate transforms with each group. whole robot = head + body + legs + arms leg = upper part + lower part head = neck + eyes +...

Hierarchical transformations Hierarchical representation of an object is a tree. The non-leaf nodes are groups of objects. The leaf nodes are primitives (e.g. polygons) Transformations are assigned to each node, and represent the relative transform of the group or primitive with respect to the parent group As the tree is traversed, the transformations are combined into one Hierarchical transformations robot S, T T head T nose head body right left right leg leg arm left arm nose eyes upper part lower part 8

Transformation stack To keep track of the current transformation, the transformation stack is maintained. Basic operations on the stack: push: create a copy of the matrix on the top and put it on the top pop: remove the matrix on the top multiply: multiply the top by the given matrix load: replace the top matrix with a given matrix Transformation stack example TO draw the robot, we use manipulations with the transform stack to get the correct transform for each part. For example, to draw the nose and the eyes: stack empty load S mult. T S S T 9

Transformation stack example push S T mult. T head S T T head S T S T S T push S T T head S T T head mult. T nose S T T head T nose S T T head Draw the nose S T S T Transformation stack example S T T head S T T head T eyes pop S T T head push S T T head mult. T eyes S T T head S T S T S T Draw the eyes pop S T T head pop Draw body etc... S T S T 0

Transformation stack example Sequence of operations in the (pseudo)code: load S ; mult T ; push; mult. T head ; push; mult T nose ; draw nose; pop; push; mult. T eyes ; draw eyes; pop; pop;... Animation The advantage of hierarchical transformations is that everything can be animated with little effort. General idea: before doing a mult. or load, compute transform as a function of time. time = 0; main loop { draw(time); increment time; } draw( time ) {... compute R arm (time) mult. R arm... }

Perspective transformations Transformation pipeline Modelview: model (position objects) + view (position the camera) Projection: map viewing volume to a standard cube Perspective division: project D to D Viewport: map the square [-,]x[-,] in normalized device coordinates to the screen

Coordinate systems z x x Eye coordinates z World coordinates World coordinates - fixed initial coord system; everything is defined with respect to it Eye coordinates - coordinate system attached to the camera; in this system camera looks down negative Z-axis Positioning the camera Modeling transformation: reshape the object, orient the object, position the object with respect to the world coordinate system Viewing transformation: transform world coordinates to eye coordinates Viewing transformation is the inverse of the camera positioning transformation Viewing transformation should be rigid: rotation + translation Steps to get the right transform: first, orient the camera correctly, then translate it

Positioning the camera Viewing transformation is the inverse of the camera positioning transformation: z world x world x eye z eye Camera positioning: translate by (t x ;t z ) Viewing transformation (world to eye): xeye = x world t z zeye = x world t x Look-at positioning Find the viewing transform given the eye (camera) position, point to look at, and the up vector Need to specify two transforms: rotation and translation. translation is easy natural rotation: define implicitly using a point at which we want to look and a vector indicating the vertical in the image (up vector) can easily convert the eye point to the direction vector of the camera axis; can assume up vector perpendicular to view vector

Look-at positioning Problem: given two pairs of perpendicular unit vectors, find the transformation mapping the first pair into the second u c v = l c jl cj Eye coords l World coords Look-at positioning Determine rotation first, looking how coord vectors change: R 0 0 = v R 0 = v u R 0 = u 0 0 R 0 0 0 0 = R = [v uu v] 0 0

Look-at positioning Recall the matrix for translation: 0 0 c x T = 0 0 c y 0 0 c z 0 0 0 Now we have the camera positioning matrix, TR To get the viewing transform, invert: (TR) = R T For rotation the inverse is the transpose! (v u)t R =[v uu v] T = u T v T Look-at viewing transformation T = 0 0 c x 0 0 c y 0 0 c z 0 0 0 V = R T = =[ex ey ez c] (v u) T (v u; c) u T (u; c) v T (v; c) [0; 0; 0]

Positioning the camera in OpenGL imagine that the camera is an object and write a sequence of rotations and translations positioning it change each transformation in the sequence to the opposite reverse the sequence Camera positioning is done in the code before modeling transformations OpenGL does not distinguish between viewing and modeling transformation and joins them into the modelview matrix Space to plane projection In eye coordinate system y c = 0 0 v = 0 0 0 z v Image plane c p Proj(p)= p x=p z p y =p z Proj(p) = 0 0 0 0 0 0 0 0 0 0 0 0 p x p y p z

Visibility Objects that are closer to the camera occlude the objects that are further away All objects are made of planar polygons A polygon typically projects to idea: project polygons in turn ; for each pixel, record distance to the projected polygon when writing pixels, replace the old color with the new one only if the new distance to camera for this pixel is less then the recorded one Z-buffering idea Problem: need to compare distances for each projected point Solution: convert all points to a coordinate system in which (x,y) are image plane coords and the distance to the image plane increases when the z coordinate increases In OpenGL, this is done by the projection matrix 8

Viewing frustum Volume in space that will be visible in the image r is the aspect ratio of the image width/height y z n f Projection transformation Maps the viewing frustum into a standard cube extending from - to in each coordinate (normalized device coordinates) steps: change the matrix of projection to keep z: result is a parallelepiped translate: parallelepiped centered at 0 scale in all directions: cube of of size centered at 0 9

Projection transformation 0 0 0 Proj(p) = 0 0 0 0 0 0 0 0 0 change so that we keep z: 0 0 0 0 0 0 0 0 0 0 0 0 p x p y p z p x p y p z = p x p y p z the homogeneous result corresponds to p x=p z p y =p z =p z the last component increases monotonically with z! Projection transformation 0 0 0 0 0 0 0 0 0 0 0 0 maps the frustum to an axis-aligned parallelepiped /f /n tan z r tan already centered in (x,y), center in z-direction and scale: 0 0 0 0 0 0 T = 0 0 µ f + n 0 0 0 r tan 0 0 0 0 S = tan 0 0 0 0 ³ n 0 f 0 0 0 0

Projection transformation Combined matrix, mapping frustum to a cube: P = ST 0 0 0 0 0 0 0 0 0 0 0 0 = r tan 0 0 0 0 tan 0 0 f + n 0 0 fn n f n f 0 0 0 To get normalized image plane coordinates (valid range [-,] both), just drop z in the result and convert from homogeneous to regular. To get pixel coordinates, translate by, and scale x and y (Viewport transformation) Transformation pipeline Modelview: model (position objects) + view (position the camera) Projection: map viewing volume to a standard cube Perspective division: project D to D Viewport: map the square [-,]x[-,] in normalized device coordinates to the screen