cs 418 interactive computer graphics projection
play

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


  1. CS 418: Interactive Computer Graphics Projection Eric Shaffer Based on John Hart’s CS 418 Slides

  2. Hierarchical Solar System Model Without push/pop, You can’t move the Earth scale to before you draw the moon: R e T e R m T m S m drawMoon R e T e S e R m T m S m drawMoon The S e will change both the T m and S m

  3. Hieararchical Solar System Model You can move the Earth scale to before you draw the moon: R e T e Push S e drawEarth Pop R m T m S m drawMoon

  4. Projections ¤ In computer graphics, eventually we need to move from 3D space to 2D space ¤ More accurately, from four-dimensional homogenous coordinates to three dimensional homogenous coordinates ¤ A projection is a transformation that maps from a high- dimensional space into a lower-dimensional space. ¤ We will look at some common projections ¤ …and then we will discuss projection within WebGL

  5. Planar Geometric Projections ¤ Standard projections project onto a plane ¤ Projectors are lines that either ¤ converge at a center of projection ¤ are parallel ¤ Such projections preserve lines ¤ but not necessarily angles ¤ Non-planar projections are used in map construction 5

  6. Perspective ¡Projection 6

  7. Orthographic Projection

  8. Oblique Projections Oblique parallel projection Oblique perspective projection Linear projections can be categorized By whether the projectors are parallel • By whether the projectors are orthogonal to the view plane •

  9. Definition to Know: Foreshortening Foreshortening is the visual effect or optical illusion that causes an object or distance to 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

  10. WebGL Secrets Model Model World Viewing Viewing Perspective Coords Xform Coords Xform Coords Distortion Still Homogeneo Clip Clip Clipping us Divide Coords. Coords. Window Window Viewport to Coordinates Coordinates Viewport ¤ 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”? ¤ 1 0

  11. Orthographic View Projection Volume (left,top,-near) y Foreshortens ¤ -z z No change in size by depth ¤ x Classic Orthographic Projection matrix ¤ simply zeros the z- coordinate (right,bottom,-far) é ù é 1 ù é ù é ù Viewing Coordinates ê ú ê ú ê ú ê ú 1 ê ú ê ú ê ú ê ú Ortho W2V View Model ê ú ê ú ê ú ê ú 0 ê ú ê ú ê ú ê ú Clip Coordinates 1 ë û ë û ë û ë û ¤ mat4.ortho(out,left,right,bottom,top,near,far) 2 − 𝑠 + 𝑚 0 0 𝑠 − 𝑚 𝑠 − 𝑚 2 − 𝑢 + 𝑐 0 0 𝑢 − 𝑐 𝑢 − 𝑐 −2 − 𝑔 + 𝑜 0 0 𝑔 − 𝑜 𝑔 − 𝑜 0 0 0 1

  12. GLMatrix ortho matrix ortho(left,right,bottom,top,near,far) ¤ 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?

  13. GLMatrix ¡ortho matrix ortho(left,right,bottom,top,near,far) ¤ 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

  14. Perspective ¤ Brain depends on shape constancy ¤ Real world objects do not resize ¤ Change in size due to depth ¤ Closer objects larger ¤ Farther objects smaller

  15. Ames Distorting Room

  16. Hering Illusion

  17. Perspective ¡Projection ¤ Objects ¡further ¡from ¡viewer ¡are ¡projected ¡smaller ¡than ¡the ¡same ¡sized ¡ objects ¡closer ¡to ¡the ¡viewer ¡( diminution ) ¤ 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

  18. Perspective Distortion

  19. Simple Perspective Projection Albrecht Durer woodcut c. 1525, swiped from Marc Levoy’s CS48N notes c. 2007 ¤ Brain depends on shape constancy ¤ Real world objects do not resize ¤ Change in size due to depth ¤ Closer objects larger ¤ Farther objects smaller ¤ How large, how small? More Durer, swiped from Fredo Durand’s Art of Depiction ?

  20. Simple Perspective screen y y view y clip -z z view d Eye is at origin (0,0,0) y y cl i p Screen is distance d from the eye. vie w = - d z Looking down negative z-axis. vi e w The two triangles are similar y y view view = = (two angles are obviously congruent) y d clip - - z z view / d view This means corresponding sides are in the same proportions

  21. Simple Perspective screen x x view x clip -z z view d Same process derives the 𝑦 2/34 𝑦 -./0 = projection for the x −𝑨 2/34 /𝑒 coordinate. What is z clip ?

  22. Simple Perspective screen x x view x clip -z z view d 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

  23. Projections Using Homogeneous Coordinates é ù x é wx ù ¤ We can extend our use of homogenous ê ú ê ú y wy coordinates to handle projections ê ú ê ú º ê ú ê ú z wz ê ú ê ú ¤ Let the fourth homogeneous 1 w ë û ë û coordinate be any non-zero value w é ù x é x w / ù ê ú ê ú y y w / ê ú ê ú º ¤ To find the point it corresponds to: ê ú ê ú z z w / ¤ multiply all four coordinates by 1/ w ê ú ê ú w 1 ë û ë û ¤ When homogeneous coordinate is zero é ù x é 1 a ù é ù x ¤ Denotes a “point” at infinity ê ú ê ú ê ú ¤ Represents a vector instead of a point y 1 b y ê ú ê ú ê ú = ¤ Not affected by translation ê ú ê ú ê ú z 1 c z ê ú ê ú ê ú ¤ A point in 3D corresponds to what in the 0 1 0 ë û ë û ë û 4D homogenous space?

  24. Simple Perspective screen y y view y clip -z z view d By allowing w to change we represent more kinds of transformations é x ù view ê ú - y z / d é 1 ù é x ù é x ù y clip view view view view ê ú = - ê ú ê ú ê ú d z 1 y y ê y ú view ê ú ê view ú = ê view ú view º ê ú - ê ú ê ú ê ú z / d y 1 z z view view view view ê ú = - y ê ú ê ú ê ú clip - z view / d - - ê ú d 1/ d 0 1 z / d ë û ë û ë û view ê ú 1 ë û

  25. Parameter d screen y y view y clip y' clip -z z view d’ d y clip = d y view /(-z view ) Using d Using d’ y' clip = d’ y view /(-z view ) = (d’/d) y clip Changing parameter d just changes scale of projection

  26. Parameter d screen screen y y view y' clip y clip -z z view d’ d 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

  27. Perspective Projection in WebGL ¤ Just like with parallel viewing we will ¤ Define a viewing volume ¤ Construct a normalization transformation ¤ We turn a perspective projection into orthogonal projection ¤ This allows us to use the built-in orthogonal projection in WebGL

  28. Perspective Normalization Consider a simple perspective with the COP at the origin, the near clipping plane at z = -1, and a 90 degree field of view determined by the planes x = ± z , y = ± z

  29. Perspective Matrices Simple projection matrix in homogeneous coordinates é ù 1 0 0 0 ê ú 0 1 0 0 ê ú M = ê ú 0 0 1 0 ê ú - 0 0 1 0 ë û Note that this matrix is independent of the far clipping plane

Recommend


More recommend