CS 418: Interactive Computer Graphics Projection
Eric Shaffer
Based on John Hart’s CS 418 Slides
CS 418: Interactive Computer Graphics Projection Eric Shaffer - - PowerPoint PPT Presentation
CS 418: Interactive Computer Graphics Projection Eric Shaffer Based on John Harts CS 418 Slides Hierarchical Solar System Model Without push/pop, You cant move the Earth scale to before you draw the moon: R e T e R m T m S m drawMoon R e
Based on John Hart’s CS 418 Slides
Without push/pop, You can’t move the Earth scale to before you draw the moon: ReTe RmTmSm drawMoon ReTe Se RmTmSm drawMoon The Se will change both the Tm and Sm
You can move the Earth scale to before you draw the moon: ReTe Push Se drawEarth Pop RmTmSm drawMoon
¤ More accurately, from four-dimensional homogenous coordinates to three dimensional homogenous coordinates
5
¤ converge at a center of projection ¤ are parallel
¤ but not necessarily angles
6
Oblique parallel projection Oblique perspective projection Linear projections can be categorized
Foreshortening is the visual effect
that causes an
appear shorter than it actually is because it is angled toward the viewer.
i.e. projections squash receding surfaces
Andrea Mantegna The Lamentation over the Dead Christ
1
¤ WebGL only performs an orthogonal projection
¤ Everything is projected to the z=0 plane in the normalized view volume ¤ But you can distort your geometry to achieve a perspective projection
¤ The projection occurs when the geometry is in clip space (NDC)
¤ and after homogeneous divide
¤ Even then, depth information is kept around to do hidden surface removal
¤ What form is this “depth information”?
Homogeneo us Divide Model Coords Model Xform World Coords Viewing Xform Still Clip Coords. Clipping Window Coordinates Window to Viewport Viewport Coordinates Clip Coords. Viewing Coords Perspective Distortion
¤ Foreshortens ¤ No change in size by depth ¤ Classic Orthographic Projection matrix simply zeros the z- coordinate
¤ mat4.ortho(out,left,right,bottom,top,near,far)
Viewing Coordinates Clip Coordinates
1 1 W2V View Model 1 é ù é ù é ù é ù ê ú ê ú ê ú ê ú ê ú ê ú ê ú ê ú ê ú ê ú ê ú ê ú ê ú ê ú ê ú ê ú ë û ë û ë û ë û
x y z View Volume
(left,top,-near) (right,bottom,-far)
2 𝑠 − 𝑚 − 𝑠 + 𝑚 𝑠 − 𝑚 2 𝑢 − 𝑐 − 𝑢 + 𝑐 𝑢 − 𝑐 −2 𝑔 − 𝑜 − 𝑔 + 𝑜 𝑔 − 𝑜 1
¤ near and far are distances
measured from camera ¤ where is the camera? ¤ l,r,b,t are coordinates of the bounding planes ¤ what does the matrix do?
¤ near and far are distances
measured from camera ¤ where is the camera? At the origin due to the view transformation ¤ l,r,b,t are coordinates of the bounding planes ¤ what does the matrix do? It scales and translates the specified box to fit into the NDC view volume….it decides what you see and what gets clipped
¤ Real world objects do not resize ¤ Change in size due to depth
¤ Objects ¡further ¡from ¡viewer ¡are ¡projected ¡smaller ¡than ¡the ¡same ¡sized ¡
¤ Looks ¡realistic
¤ Equal ¡distances ¡along ¡a ¡line ¡are ¡not ¡projected ¡into ¡equal ¡distances ¡ (nonuniform foreshortening) ¤ Angles ¡preserved ¡only ¡in ¡planes ¡parallel ¡to ¡the ¡projection ¡plane ¤ More ¡difficult ¡to ¡construct ¡by ¡hand ¡than ¡parallel ¡projections
¤ Real world objects do not resize ¤ Change in size due to depth
Albrecht Durer woodcut c. 1525, swiped from Marc Levoy’s CS48N notes c. 2007 More Durer, swiped from Fredo Durand’s Art of Depiction
?
screen
y zview yview d
vie cl w vi p w i e
y d y z
=
view view clip view view /
y y y d z z d = =
yclip Eye is at origin (0,0,0) Screen is distance d from the eye. Looking down negative z-axis. The two triangles are similar (two angles are obviously congruent) This means corresponding sides are in the same proportions
screen
x zview xview d xclip 𝑦-./0 = 𝑦2/34 −𝑨2/34/𝑒 Same process derives the projection for the x coordinate. What is zclip?
screen
x zview xview d xclip 1. This transformation is not invertible 2. It does preserve lines (except when?) 3. It is not an affine transformation (it does not preserve ratios of distances 4. For graphics we will want use a variant that preserves relative distances for hidden surface removal…we’ll see that later
¤ multiply all four coordinates by 1/w
¤ Denotes a “point” at infinity ¤ Represents a vector instead of a point ¤ Not affected by translation
1 / / / 1 x wx y wy z wz w x x w y y w z z w w é ù é ù ê ú ê ú ê ú ê ú º ê ú ê ú ê ú ê ú ë û ë û é ù é ù ê ú ê ú ê ú ê ú º ê ú ê ú ê ú ê ú ë û ë û 1 1 1 1 x a x y b y z c z é ù é ù é ù ê ú ê ú ê ú ê ú ê ú ê ú = ê ú ê ú ê ú ê ú ê ú ê ú ë û ë û ë û
d screen
y zview yview yclip
clip view view view clip view /
y y d z y y z d = - = -
view view view view view view view view view view view
/ 1 1 / 1 / 1/ 1 1 x z d x x y y y z d z z d z d d é ù ê ú
é ù é ù é ù ê ú ê ú ê ú ê ú ê ú ê ú ê ú ê ú = º ê ú
ê ú ê ú ê ú ê ú ê ú ê ú ê ú
ê ú ë û ë û ë û ê ú ë û
By allowing w to change we represent more kinds of transformations
screen
y zview yview d yclip d’ y'clip yclip = d yview/(-zview) y'clip = d’ yview/(-zview) = (d’/d) yclip Changing parameter d just changes scale of projection Using d Using d’
screen
y zview yview d yclip d’ y'clip screen To change degree of perspective distortion, need to change distance from eye to scene, …by moving scene closer or farther to eye, … along z axis in viewing coordinates
¤ Define a viewing volume ¤ Construct a normalization transformation
N = after perspective division, the point (x, y, z, 1) goes to
¤ The same as produced by the simple perspective projection
3 6
volume
¤ For two points p1 and p2, if z1 > z2 in the original clipping volume then the order for the transformed points z1’ > z2’ ¤ Thus hidden surface removal using depth comparison works if we first apply the normalization transformation ¤ However, the formula z’’ = -(a+b/z) implies that the distances are distorted by the normalization which can cause numerical problems especially if the near distance is small
using left, right, bottom, top, near, far
using fovy, aspect, near, far fovy à vertical viewing angle in radians aspect à aspect ratio of the viewport near à distance from center of projection to near clip plane far à distance from center of projection to far clip plane it computes a frustum with right=top x aspect top = near x tan(fovy) left = -right and bottom = -top
P = 2*near right −left right +left right −left 2*near top− bottom top+ bottom top− bottom − far + near far − near − 2* far *near far − near −1 " # $ $ $ $ $ $ $ $ $ % & ' ' ' ' ' ' ' ' ' P = near right near top
far - near
far - near
é ë ê ê ê ê ê ê ê ù û ú ú ú ú ú ú ú