1 / 41

Intro to 3D Graphics

Intro to 3D Graphics. Revisiting the Display Pipeline. Object space World space Camera space Image space Screen space. Homogeneous Coordinates. 3D Vectors use a 4 th , homogeneous coordinate Usually 1, if not, divide through (4,3,2,1) = (8,6,4,2)

Download Presentation

Intro to 3D Graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Intro to 3D Graphics

  2. Revisiting the Display Pipeline • Object space • World space • Camera space • Image space • Screen space

  3. Homogeneous Coordinates • 3D Vectors use a 4th, homogeneous coordinate • Usually 1, if not, divide through(4,3,2,1) = (8,6,4,2) • All transformations kept in the form of 4x4 matrices. This keeps the matrices invertible, and all transforms are matrix multiplications.

  4. Building Polygon Matrices • New problem in 3D: Which side of the polygon is the front? • Relative order of vertices in matrix matters • Vertices should appear in counter-clockwise order for right handed systems and clockwise order for left handed systems • Now normal vector will denote the “front”

  5. Analogous Transformation Matrices • The do-everything transform matrix: a b c p Top 9- rotations d e f q p,q,r – perspective g I j r h,k,l - translation h k l s s – overall scaling

  6. Scaling a 0 0 0 0 e 0 0 0 0 j 0 0 0 0 1 a in x-dir e in y-dir j in z-dir Negative values reflect

  7. Translation 1 0 0 0 0 1 0 0 0 0 1 0 h k l 1 shift h in x-dir k in y-dir l in z-dir

  8. Rotations 1 0 0 0 0 cosӨ sinӨ 0 0 -sinӨ cosӨ 0 0 0 0 1 cosӨ sinӨ 0 0 -sinӨ cosӨ 0 0 0 0 1 0 0 0 0 1 About x About z

  9. Rotations cosӨ 0 -sinӨ 0 0 1 0 0 sin Ө 0 cos Ө 0 0 0 0 1 About y-axis Note changes in sines!Necessary for preserving handed-ness

  10. Overall Scaling • Scale factor is last coordinate in last row • s < 1 expands, s >1 contracts • Must “divide through” by s to get last coordinate 1.

  11. Camera/Observer/Eye • Camera position (3D point) • Need perspective of viewer • View direction • Up vector • View direction: • COI: Center of interest • View direction is COI – Eye position

  12. Field of View • Camera position • View Direction & Orientation • Near clipping distance • Far clipping distance • Define: View Frustum: 6-sided volume of world space displayable (truncated pyramid)

  13. View Frustum

  14. Remember Your Trig • SOH CAH TOA • Sin = Opposite / Hypotenuse • Cos = Adjacent / Hypotenuse • Tan = Opposite / Adjacent Hyp Opp Ө Adj

  15. Image Transformation • Right-handed system • Our camera at (-10,0,0) looking down z-axis. • Need to calculate view frustum and project it onto the view window • Change (x,y,z) camera coordinates to (x’,y’) image coordinates

  16. Calculating view distance • Pick an angle for viewing (90 degrees) d = (w/2) / tan(Ө/2) w/2 tangent of 45 degrees = 1 d = w/2, or camera size in unity! d Ө

  17. Calculating x’ Use similar triangle ratios: d is to x’ as t is to x: x’ = dx/t y’ = dy/t t x d x’

  18. Calculating x’ Use similar triangle ratios: d is to x’ as z is to x: x’ = dx/z y’ = dy/z z x d x’ Can approximate by dividing everything by z value.

  19. Perspective Transforms are not Affine! • Vanishing points

  20. Types of Rendering • Rendering = Drawing & filling in polygons • Ray Tracing: Models rays of light • Reverse: Eyes to World • Expensive • Movies (Ice Age) • Polygon Modeling • All Shapes are modeled as polygons • Rounded shapes require more polygons

  21. Polygon Rendering • Triangles (sometimes deal with strips) • Vertices – often exist on multiple triangles • Each triangle needs a normal • Unit vector • Points “out” perpendicular to triangle

  22. Solid Shapes • Is it just adding more polygons? • Must be careful the order in which the polygons are drawn – or the back will cover the front • Most efficient: don’t draw polygons that aren’t visible, then… • Order the visible polygons correctly.

  23. Back-face Culling • Reduce the number of polygons drawn by about half • Need the normal to the polygon • Normal: vector perpendicular to the polygon, facing the same direction as the polygon • Polygon is “facing the camera” if the angle between the camera and the normal is less than 90 degrees

  24. Computing Normals • Cross Product • U x V = (UyVz – UzVy, UzVx – UxVz, UxVy – UyVx) • The vector perpendicular to U and V

  25. Calculating normals • Right-handed: define “front” as counter-clockwise ordering of vertices. • U = v2-v1 • V = v0-v1 • Normal = UxV 1 0 2

  26. Angle between two vectors • Dot product: • U·V = UxVx + UyVy + UzVz • U·V =|U||V|cosӨ • All we care about is whether or not Ө<90: • if U·V<0, then Ө > 90 • if U·V=0, Ө = 90 • if U·V>0,Ө < 90

  27. Does it face camera? • U = camera - v0 • V = Normal • Polygon faces camera if U·V >= 0 1 0 2

  28. Tackling Roundoff • More accurate polygon drawing:Scan Converter • Draw horizontal lines to draw a polygon • Problem: don’t want polygons to overlap, so round down on the right side of the polygon

  29. Horizontal Scanner • Scan object: tells me the left and right x values to draw for all y values in range for the polygon. • For each edge • Find the highest and lowest y values • For each intermediate y, • Find the x point of the intersection • Keep up with the leftmost and rightmost x for this y value over all edges • At the end, you have the leftmost and rightmost x values for each y – then draw horizontal lines

  30. Finding that intersection • You have 2 vertices (x1,y1) and (x2,y2) • The equation of the edge is: y-y1 = m(x-x1) (y-y1)/m+x1 = x • So, x = x1 + (y-y1)/m where m is (y2-y1)/(x2-x1)

  31. Finally,… • For each y, draw a line from left to right • Gives you the filled in polygon with little round-off error

  32. 3D Clipping • What about polygons partially in the frustum? • First, clip to a plane: • Polygon is behind plane, ignore it. • Problem: Compute the line segment where the polygon intersects the clipping plane. This becomes a new edge and only vertices in front of the pane are kept.

  33. Hidden-surface Removal • So far: • Back-face culling • Clipping • Doesn’t work for overlapping polygons

  34. More Hidden-Surface Removal • How do you know which objects are in front of others? • Simple ordering • Inefficient • Doesn’t always work • Use Z-Buffer • Collection of depth valueswith pixel color

  35. Hidden surface removal • Painter’s Algorithm: Draw things back to front • Reverse Painter’s Algorithm: Draw things front to back, but don’t draw over a pixel already drawn • Problem: Which point on polygon determines its depth?

  36. Z-Buffering • Or depth-buffering • Store depth of each pixel • Start with all pixels = inf. • Only overwrite if depth is less than current

  37. Z-Buffering

  38. Final Pipeline • To Draw a polygon: • Check to see if it’s facing the camera • Apply transforms • Project onto the view window • Scan-convert it • Draw the horizontal lines • Use Z-Buffering to determine final pixel-by-pixel coloring

  39. Polygon Rendering • Texture: Picture to paste on the triangles • Shader: Program that determines coloring of triangles • Material: Rendering description including shaders, textures, and lots more • Mesh: Collection of triangles, vertices, and material to render it with • Render Object: Set of meshes defining an object, sometimes uses a skeleton

  40. Types of Shaders • Wireframe – Edges only • Flat – Triangle is single color • Gouraud – Interpolate color between vertices • Phong – takes more lighting models into account (interpolates normals between vertices) • Texture Map – paste picture on triangle • Environment mapping – cube map of environment is put on object to fake shininess

More Related