Advanced Computer Graphics Lecture 2: Modeling (1): Polygon Meshes Bernhard Jung TU-BAF, Summer 2007 Overview Computer Graphics Icon: Utah teapot Polygon Meshes Subdivision Polygon Mesh Optimization high-level: Level-of-detail, Progressive meshes low-level: Polygon strips & fans Further reading A. Watt. 3D Computer Graphics. 3rd edition Addison-Wesley. 2000. Chapter 2. T. Akenine-Möller & E. Haines. Real-Time Rendering. AK Peters. 2002. Chapter 11,12 H. Hoppe. Progressive meshes. Proceedings ACM SIGGRAPH 1996, 99-108. 1
Surfaces Polygon Meshes Classical and ubiquitous in CG Creating polygonal objects is straightforward Visually efficient algorithms exist to produce shaded images. A machine representation, converted from other user representations such as parametric/implicit surfaces, CSG/volume Difficulties of polygonal mesh geometric accuracy shape manipulation Surfaces Polygon Meshes 2
Surfaces - Polygon Meshes Polygons A polygon is a many-sided planar figure composed of vertices and edges. Vertices are represented by points (x,y). Edges are represented as line segments which connect two points, (x1,y1) and (x2,y2). P = { (x i, y i ) } i=1,n (x1,y1) E1 (x2,y2) E3 E2 (x3,y3) Surfaces - Polygon Meshes Convex and Concave Polygons Convex Polygon - For any two points P1, P2 inside the polygon, all points on the line segment which connects P1 and P2 are inside the polygon. All points P = up1 + (1-u)P2, u in [0,1] are inside the polygon provided that P1 and P2 are inside the polygon. Concave Polygon - A polygon which is not convex. 3
Surfaces - Polygon Meshes Simple and non simple Polygons Simple Polygons Polygons whose edges do not cross. Non simple Polygons Polygons whose edges cross. Two different OpenGL implementations may render non simple polygons differently. OpenGL does not check if polygons are simple. Triangle polygon guaranteed to be convex and simple Surfaces Polygon Meshes Mesh Representations Independent Faces Vertex and Face Table Adjacency Lists (Winged Edge) 4
Surfaces - Polygon Meshes Mesh Representation Independent Faces Each face lists vertex coordinates Redundant vertices No topology information Surfaces - Polygon Meshes Mesh Representation Vertex and Face Tables Each face lists vertex references Shared vertices, more compact representation Still no topology information VRML: IndexedFaceSet 5
Surfaces - Polygon Meshes Mesh Representation Adjacency Lists Store all vertex, edge, and face adjacencies Efficient topology traversal Extra storage Advanced Mesh Rep: Winged Edge Stores only some adjacency relationships; can derive others on demand Little extra storage (fixed records) Surfaces Subdivision Properties Accurate Local support Affine invariant Arbitrary topology Guaranteed continuity Efficient display used e.g. in animated movies Pixar: Geri s Game 6
Surfaces Subdivision How do you make a smooth curve? Keep cutting the corners of the polyline until you end up with something that has no corners anymore, i.e., is smooth! Surfaces Subdivision Coarse mesh & subdivision rule Define smooth surface as limit of sequence of refinements 7
Surfaces Subdivision e.g. loop subdivision rule refine each triangle into 4 triangles by splitting each edge and connecting new vertices Surfaces Subdivision Different refinement rules 8
Surfaces Subdivision face split All subdivision schemes have 2 steps: 1. Splitting or refinement step topological rule which introduces new vertices and modifies connectivity 2. Averaging or smoothing step geometric rule which computes the positions for new or all vertices by weighted averages vertex split Surfaces Subdivision Computer Graphics Icon: Ivan Sutherland's Volkswagen, Utah, late 1970ies Quadrilateral subdivision 9
Surfaces Subdivision Subdivision in 3DS Max, tessellate modifier original 1 iteration 2 iterations 4 iterations Surfaces Subdivision loop subdivision example adaptive approximation: surface is subdivided only where topology of the surface requires more detail selection of critical mesh areas (vertices) usually by hand 10
Surfaces Polygonal Models vs Subdivision From 3DS Max Help: You create a subdivision surface by applying a modifier to an object. Two kinds of subdivision surfaces are supported: The HSDS modifier provides hierarchical subdivision surfaces [i.e. at multiple levels of detail] The MeshSmooth modifier provides smoothing. Both these modifiers work best as finishing tools for models. The HSDS modifier implements Hierarchical SubDivision Surfaces. It is intended primarily as a finishing tool rather than as a modeling tool. For best results, perform most of your modeling using low-polygon methods, and then use HSDS to add detail and adaptively refine the model. Surfaces Parametric Surfaces Generalization of parametric curves bi-polynomial, e.g. bi-cubic parametric surfaces piecewise parametric surfaces e.g. Bézier surface, NURBS-surface, C1-continuity requires aligning boundary curves and derivatives (difficult; a reason to prefer subdivision surfaces) 11
Surfaces Summary Polygon meshes games Subdivision surfaces movies Parametric Surfaces CAD/CAM increased accuracy slower rendering Polygon mesh optimization Main disadvantage of polygon meshes: often high polygon count to synthesize an object for a high quality rendition Quote from 1976 It makes no sense to use 500 polygons in describing an object if it covers only 20 raster units on the display For example, when we view the human body from a very large distance, we might need to present only specks for the eyes, or perhaps a block for the head, totally eliminating the eyes from consideration (James H. Clark, 1976) today: objects composed of > 1000000 polygons 12
Polygon mesh optimization Mesh Simplification Reduce polygons to a level that is adequate for the quality required Application: Level of detail approximation [Clark76, Funkhouser93] VRML: LOD node distance from distance from viewer? viewer? close far 10,000 2,000 1,000 500 250 problem: may "pop" Polygon mesh optimization Progressive meshes [Hoppe, 96] Idea: apply sequence of edge collapses v t edge collapse v l v r v l v s v r v s to build hierarchy of meshes: 13,546 500 152 150 M=M ^ n ecol n-1 M 175 M 1 175 ecol ecol i 0 M 0 13
Polygon mesh optimization Progressive meshes [Hoppe, 96] Which edges to select? simple heuristic: edges connecting close polygons with similar orientation or more complex heuristics edge collapse is invertible! inverse operation: vertex split can store required vertex information in coarser mesh lossless v l v t v s edge collapse v r vertex split v l v s v r Applications continuous level of detail progressive transmission selective refinement, e.g. viewer dependent mesh compression Polygon mesh optimization continuous level of detail A multi-resolution model obtained by simplification of the original model (in the top left corner). The number of triangles are respectively 96966, 13334, 3334 and 668. http://gts.sourceforge.net/ Animation of a continuous Level Of Detail model of the horse. The initial number of vertices is 32 and is increased to 10,000. 14
Triangle strips Without strips: 8 triangles * 3 vertices = 24 vertices With strips: use 1 vertex per triangle instead of 3! v 0 v 2 v 4 v 6 v 8 T0 T1 T2 T3 T4 T5 T6 T7 v 1 v 3 What we send to graphics hardware: Startup cost: v 0, v 1 then v 2 (T0), v 3 (T1), v 4 (T2), v 5 (T3), v 6 (T4), v 7 (T5), v 8 (T6), v 9 (T7). 9 vertices 100*9/24= 37.5% or 9/8=1.125 verts/tri v 5 v 7 v 9 Triangle strips 9 vertices instead of 24 100*9/24= 37.5% of data 9/8=1.125 vertices/tri I.e., we can expect the geometry stage to run almost 3 times faster! Definition of triangle strip makes orientation change between neighboring triangles in strip Internally, counterclockwise order is kept consistent by traversing vertices 0-1-2, 1-3-2, 2-3-4, 3-5-4, v 0 v 2 v 4 v 6 v 8 T0 T1 T2 T3 T4 T5 T6 T7 v 1 v 3 v 5 v 7 v 9 15
Triangle strips OpenGL: glbegin(gl_triangle_strip); glend() Swaps in triangle strips Whatcanwedofor this case? (T 3 = v 2 v 4 v 5 ) v 0 v 2 v 5 v 6 T 4 T 3 v 4 T 0 T 1 T 2 Implement a swap! Startup cost: v 0, v 1 then v 2 (T0) v 3 (T1) v 2, v 4 (T2) v 5 (T3), v 6 (T4) Degenerate triangle (0-area): v 2, v 3, v 2 v 1 v 3 16
Swaps (v0, v1, v2, v3, swap, v4, v5, v6) implemented by sending v 0 (v0, v1, v2, v3, v2, v4, v5, v6) cost of degenerate triangle: 1 extra vertex still cheaper than restarting triangle strip T 0 v 1 v 5 v 6 T 3 v 2 v 4 T 1 T 2 v 3 T 4 this example: 8 sent vertices / 5 triangles = 1.6 vertices/triangle restarting triangle strip costs more: 4 vertices (2 triangles) + 5 vertices (3 triangles) Swaps also, hardware determines degenerate triangles efficiently and skips these can use swaps to connect non-connected triangles too the idea is to avoid API call overhead hardware needs caches for this to be efficient v 0 v 2 v 4 v 6 T0 T1 T2 T3 Generates 4 degenerate triangles v 1 v 3 v 5 send these vertices: 0,1,2,3, 3,4, 4,5,6,7 10 vertices (sending as 2 strips: 8 vertices) if 3 and 4 are cached, then 8 vertices v 7 17
How to create triangle strips from a 3D model? manually only doable for small models, and not fun NVIDIA Tri Strip Library http://developer.nvidia.com/object/nvtristrip_library.html or make your own program need to know triangle s adjacencies SGI stripping algorithm 1. Choose a starting triangle 2. Build 3 different triangle strips; one for each edge of the triangle 3. Extend these triangle strips in the opposite direction 4. Choose the longest of these 3 strips 5. Repeat Step 1 until all triangles are included in a strip greedy algorithm; linear time if appropriate data structures are used choice of starting triangle: original algorithm: a triangle with smallest number of neighbors (at least 1) in practice, arbitrary choice produces almost equally good results Triangle fans v 6 v 5 analysis - same as for strips: without fans: 6 triangles * 3 vertices = 18 vertices with fans: use 1 vertex per triangle instead of 3! in practice: harder to find long fans than strips smaller benefit than strips easy to convert arbitrary polygons to triangle fans can convert every triangle fan to a triangle strip (with many swaps) - but not vice versa v 0 v 1 v 2 v 3 v 4 18
Vertex arrays / buffers Idea: most efficient to transform a vertex only once (using strips or fans a vertex will be transformed once for each strip / fan the vertex is contained in) Specifiy each vertex (position, normal, diffuse color, specular color, texture coordinates, etc.) once & send to buffer Then send (e.g., 16 bit) indices to identify vertices in buffer Example: make a buffer of 100 unique vertices A triangle is sent as 3 indices into this buffer: 97, 5, 32 This method mimimizes coyping from main memory to graphics card OpenGL vertex arrays, DirectX vertex bufffers Triangle strips and vertex buffers are (often) fastest way to send triangles today Summary 3D object representation properties Accuracy Accuracy vs. data volume Ease of editing Optimization potential data volume, network transmission, rendering 19