SLIDE 1 Rendering Pipeline
Mmodel Mview*Mproj World space View space Screen space
P’canvas = Mproj Mview Mmodel * Pworld
http://www.songho.ca/opengl/gl_transform.html
SLIDE 2
Projections
Compute coordinates from World Space to Screen Space (to Canvas) v w u y z x
SLIDE 3
Orthographic Projection
Points are projected along rays that are perpendicular to canvas v w u y x z preserves size of object regardless of distance to canvas
SLIDE 4 Perspective Projection
Points are projected along rays that go through a given point of projection v w u y x z
- bjects closer to canvas appear larger
SLIDE 5 View Volume
Specify near (n) and far (f) planes to enable efficient object removal
- bjects outside the view volume are not processed
v w u n f view volume for orthographic projection y z x
SLIDE 6 View Volume
Specify near (n) and far (f) planes to enable efficient object removal
- bjects outside the view volume are not processed
view volume for perspective projection v w u n z y x f
SLIDE 7 Projection Matrix
Find a matrix that transforms from World Space to Screen Space (to Canvas) given coordinates Pv in the World, what are the coordinates Ps on the Canvas
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
Mproj =
u
Pv Ps y z x
v w
Pv Ps y x
Ps = Mproj * Pv
SLIDE 8
Orthographic Projection Matrix
Keep the (x, y) coordinates xs = xv ys = yv Transform z such that zv = n maps to zs = 0 zv = f maps to zs = 1 v w u Pv Ps
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
Mproj =
y x z
SLIDE 9
Orthographic Projection Matrix
Keep the (x, y) coordinates xs = xv ys = yv Transform z such that zv = n maps to zs = 0 zv = f maps to zs = 1 v w Pv Ps
1 1 1
Mproj =
u y x z
SLIDE 10
Orthographic Projection Matrix
Keep the (x, y) coordinates xs = xv ys = yv Transform z such that zv = n maps to zs = 0 zv = f maps to zs = 1 v w Pv Ps
1 1 1
Mproj =
u y x z Find A, B such that zs = A * zv + B and zv=n -> zs=0 zv=f -> zs=1
SLIDE 11
Orthographic Projection Matrix
Keep the (x, y) coordinates xs = xv ys = yv Transform z such that zv = n maps to zs = 0 zv = f maps to zs = 1 v w Pv Ps
1 1 A B 1
Mproj =
u Find A, B such that zs = A * zv + B and zv=n -> zs=0 0 = A*n + B A = 1 / (f – n) zv=f -> zs=1 1 = A*f + B B = -n / (f – n) x z y
SLIDE 12
Perspective Projection Matrix
Transform the (x, y) coordinates from World Space to Screen Space Transform z such that zv = n maps to zs = 0 zv = f maps to zs = 1 v w Pv u Ps y z x
SLIDE 13
Perspective Projection Matrix
Consider only the YZ-plane (looking down x-axis) and calculate ys based on yv v u Pv w Ps y z x Pv Ps y z n zv
ys n ––– = ––– ys = n*ys / zv yv zv
yv ys
SLIDE 14
Perspective Projection Matrix
Consider only the XZ-plane (looking down y-axis) and calculate xs based on xv v u Pv w Ps y z x Pv Ps x z n zv
xs n ––– = ––– xs = n*xs / zv xv zv
xs xv
SLIDE 15 Perspective Projection Matrix
v u Pv w Ps x z y
n*xv n*yv
xs = –– ys = –– zv zv
n n 1 xv yv zv 1
*
n*xv n*yv zv =
Use the homogeneous coordinate w to achieve division by zv
SLIDE 16 Perspective Projection
Transform z such that zv = n maps to zs = 0 zv = f maps to zs = 1
n n 1
Mproj =
Find A, B such that zs = (A*zv + B * w) / zv
= A + B / zv
and zv=n -> zs=0 zv=f -> zs=1
SLIDE 17 Perspective Projection
Transform z such that zv = n maps to zs = 0 zv = f maps to zs = 1
n n A B 1
Mproj =
Find A, B such that zs = (A*zv + B * w) / zv
= A + B / zv
and zv=n -> zs=0 0 = A + B / n A = f / (f - n) zv=f -> zs=1 1 = A + B / f B = -n*f / (f - n)
SLIDE 18 Rendering Pipeline
Mmodel Mview*Mproj World space View space Screen space
P’canvas = Mproj Mview Mmodel * Pworld
http://www.songho.ca/opengl/gl_transform.html
SLIDE 19 The Camera Model (2D)
v u e camera parameters: e – eye point coordinates v – the directions of the view u – up vector e – what is the position (ex,ey)
- f the camera in the world
v – what are the coordinates (vx,vy) of the viewing direction in the world u – a vector perpendicular to v v u e The camera parameters and the coordinates of the model are specifjed in world space
SLIDE 20
The Camera Model (2D)
v u e To render the model need to: represent it from world space to camera view space coordinates – Mview project it on the camera film – Mproj v u e x y x' y'
SLIDE 21
The Camera Model (2D)
World to View space transformation (Mview) – align camera axes with the world axes If we bring Camera to Center of World, coords for camera == coords for World What matrix Mview – will align the Camera with the Center of the World
SLIDE 22 The Camera Model (2D)
World to View space transformation (Mview) – align camera axes with the world axes If we bring Camera to Center of World, coords for camera == coords for World What matrix Mview – will bring the Camera with the Center of the World
1
1
1
T
SLIDE 23
The Camera Model (2D)
World to View space transformation (Mview) – align camera axes with the world axes If we align Camera withWorld axes, coords for camera == coords for World What matrix Mview – will align the Camera with the Center of the World
SLIDE 24 The Camera Model (2D)
World to View space transformation (Mview) – align camera axes with the world axes If we align Camera withWorld axes, coords for camera == coords for World What matrix Mview – will align the Camera with the Center of the World
vx vy ux uy 1
R
SLIDE 25
The Camera Model (2D)
World to View space transformation (Mview) – align camera axes with the world axes If we bring/align Camera to Center of World, coords for camera == coords for World What matrix Mview – will bring/align the Camera with the Center of the World
SLIDE 26
The Camera Model (2D)
T
World to View space transformation (Mview) – align camera axes with the world axes
SLIDE 27 The Camera Model (2D)
T
1
1
1
World to View space transformation (Mview) – align camera axes with the world axes
SLIDE 28 The Camera Model (2D)
T R
1
1
1
World to View space transformation (Mview) – align camera axes with the world axes
SLIDE 29 The Camera Model (2D)
T R
1
1
1 vx vy ux uy 1
World to View space transformation (Mview) – align camera axes with the world axes
SLIDE 30 The Camera Model (2D)
T R
1
1
1 vx vy ux uy 1
Mview = R*T
World to View space transformation (Mview) – align camera axes with the world axes
SLIDE 31 Rendering Pipeline
Mmodel Mview*Mproj World space View space Screen space
P’canvas = Mproj Mview Mmodel * Pworld
http://www.songho.ca/opengl/gl_transform.html
SLIDE 32
The Camera Model (3D)
camera parameters: e – eye point coordinates v – the directions of the view u – up vector The camera parameters and the coordinates of the 3Dmodels are specifjed in world space v u e w v u e w
SLIDE 33
The Camera Model (3D)
World to View space transformation (Mview) – align camera axes with the world axes v u e w v u e w
SLIDE 34
The Camera Model (3D)
T
World to View space transformation (Mview) – align camera axes with the world axes v u e w v u e w
SLIDE 35 The Camera Model (3D)
T
World to View space transformation (Mview) – align camera axes with the world axes v u e w v u e w
1
1
1
1
SLIDE 36 The Camera Model (3D)
T R
World to View space transformation (Mview) – align camera axes with the world axes v u e w v u e w v u e w
1
1
1
1
SLIDE 37 The Camera Model (3D)
T R
World to View space transformation (Mview) – align camera axes with the world axes v u e w v u e w v u e w
1
1
1
1 wx wy wz ux uy uz vx vy vz 1
SLIDE 38 The Camera Model (3D)
T R
World to View space transformation (Mview) – align camera axes with the world axes v u e w v u e w v u e w
1
1
1
1 wx wy wz ux uy uz vx vy vz 1
Mview = R*T
SLIDE 39
Specifying The Camera Model
Typically the camera is specified by e – eye point coordinates c – a point in the direction of the gaze u – (approximate) up vector From these need to calculate v – the direction of the view w – the tilt of the camera The calculations v – a vector from e to c w = u x v – here x is the vector cross product (not dot product) c v u e w
SLIDE 40
Transformations via Camera
v w u y x z to make bunny bigger, just scale it – canvas.scale(...)
SLIDE 41
Transformations via Camera
v w u y x z to make bunny bigger, just scale it – canvas.scale(...)
SLIDE 42
Transformations via Camera
v w u y x z OR to make bunny bigger bring camera closer
SLIDE 43
Transformations via Camera
v w u y x z to move bunny, just translate it – canvas.translate(...)
SLIDE 44
Transformations via Camera
v w u y x z OR to move the bunny, move the camera
SLIDE 45
Transformations via Camera
v w u y x z to rotate the bunny, just rotate it – canvas.rotate(...)
SLIDE 46
Transformations via Camera
v w u y x z to rotate the bunny, just rotate it – canvas.rotate(...)
SLIDE 47
Transformations via Camera
v w u y x z OR to rotate the bunny, rotate the camera
SLIDE 48
Cross Product
The cross product of two vectors yields a third vector perpendicular to the original a b c = a x b a b c = b x a
c = a x b cx = ay bz - az by cy = az bx - ax bz cz = ax by - ay bx ax ay az ax bx by bz bx
Not commutative
a x b ≠ b x a