Download presentation
Presentation is loading. Please wait.
1
© University of Wisconsin, CS559 Fall 2004
Last Time Parametric curves BSpline curves Surface BSpline patches 12/2/2004 © University of Wisconsin, CS559 Fall 2004
2
© University of Wisconsin, CS559 Fall 2004
This Week Modeling with triangle meshes Obtaining polygonal meshes Hierarchical modeling Instancing and Parametric Instancing Constructive Solid Geometry Sweep Objects Octrees Subdivision schemes 12/2/2004 © University of Wisconsin, CS559 Fall 2004
3
© University of Wisconsin, CS559 Fall 2004
Polygon Modeling Polygons are the dominant force in modeling for real-time graphics Why? 12/2/2004 © University of Wisconsin, CS559 Fall 2004
4
© University of Wisconsin, CS559 Fall 2004
Polygons Dominate Everything can be turned into polygons (almost everything) Normally an error associated with the conversion, but with time and space it may be possible to reduce this error We know how to render polygons quickly Many operations are easy to do with polygons Memory and disk space is cheap Simplicity and inertia 12/2/2004 © University of Wisconsin, CS559 Fall 2004
5
What’s Bad About Polygons?
What are some disadvantages of polygonal representations? 12/2/2004 © University of Wisconsin, CS559 Fall 2004
6
© University of Wisconsin, CS559 Fall 2004
Polygons Aren’t Great They are always an approximation to curved surfaces But can be as good as you want, if you are willing to pay in size Normal vectors are approximate They throw away information Most real-world surfaces are curved, particularly natural surfaces They can be very unstructured They are hard to globally parameterize (complex concept) How do we parameterize them for texture mapping? It is difficult to perform many geometric operations Results can be unduly complex, for instance 12/2/2004 © University of Wisconsin, CS559 Fall 2004
7
© University of Wisconsin, CS559 Fall 2004
Polygon Meshes A mesh is a set of polygons connected to form an object A mesh has several components, or geometric entities: Faces Edges, the boundary between faces Vertices, the boundaries between edges, or where three or more faces meet Normals, Texture coordinates, colors, shading coefficients, etc Some components are implicit, given the others For instance, given faces and vertices can determine edges Euler’s formula: #Faces + #Vertices – #Edges = 2 - 2Genus, for closed polygon meshes 12/2/2004 © University of Wisconsin, CS559 Fall 2004
8
Polygonal Data Structures
Polygon mesh data structures are application dependent Different applications require different operations to be fast Find the neighbor of a given face Find the faces that surround a vertex Intersect two polygon meshes You typically choose: Which features to store explicitly (vertices, faces, normals, etc) Which relationships you want to be explicit (vertices belonging to faces, neighbors, faces at a vertex, etc) 12/2/2004 © University of Wisconsin, CS559 Fall 2004
9
© University of Wisconsin, CS559 Fall 2004
Polygon Soup Many polygon models are just lists of polygons struct Vertex { float coords[3]; } struct Triangle { struct Vertex verts[3]; struct Triangle mesh[n]; glBegin(GL_TRIANGLES) for ( i = 0 ; i < n ; i++ ) { glVertex3fv(mesh[i].verts[0]); glVertex3fv(mesh[i].verts[1]); glVertex3fv(mesh[i].verts[2]); glEnd(); Important Point: OpenGL, and almost everything else, assumes a constant vertex ordering: clockwise or counter-clockwise. Default, and slightly more standard, is counter-clockwise 12/2/2004 © University of Wisconsin, CS559 Fall 2004
10
© University of Wisconsin, CS559 Fall 2004
Cube Soup struct Triangle Cube[12] = {{{1,1,1},{1,0,0},{1,1,0}}, {{1,1,1},{1,0,1},{1,0,0}}, {{0,1,1},{1,1,1},{0,1,0}}, {{1,1,1},{1,1,0},{0,1,0}}, … }; (0,0,1) (0,1,1) (1,0,1) (1,1,1) (0,0,0) (0,1,0) (1,0,0) (1,1,0) 12/2/2004 © University of Wisconsin, CS559 Fall 2004
11
Polygon Soup Evaluation
What are the advantages? What are the disadvantages? 12/2/2004 © University of Wisconsin, CS559 Fall 2004
12
Polygon Soup Evaluation
What are the advantages? It’s very simple to read, write, transmit, etc. A common output format from CAD modelers The format required for OpenGL BIG disadvantage: No higher order information No information about neighbors No open/closed information No guarantees on degeneracies 12/2/2004 © University of Wisconsin, CS559 Fall 2004
13
© University of Wisconsin, CS559 Fall 2004
Vertex Indirection v0 v4 vertices v0 v1 v2 v3 v4 v1 faces 2 1 1 4 1 2 3 1 3 4 v2 v3 There are reasons not to store the vertices explicitly at each polygon Wastes memory - each vertex repeated many times Very messy to find neighboring polygons Difficult to ensure that polygons meet correctly Solution: Indirection Put all the vertices in a list Each face stores the indices of its vertices Advantages? Disadvantages? 12/2/2004 © University of Wisconsin, CS559 Fall 2004
14
© University of Wisconsin, CS559 Fall 2004
Cube with Indirection struct Vertex CubeVerts[8] = {{0,0,0},{1,0,0},{1,1,0},{0,1,0}, {0,0,1},{1,0,1},{1,1,1},{0,1,1}}; struct Triangle CubeTriangles[12] = {{6,1,2},{6,5,1},{6,2,3},{6,3,7}, {4,7,3},{4,3,0},{4,0,1},{4,1,5}, {6,4,5},{6,7,4},{1,2,3},{1,3,0}}; 4 7 5 6 3 1 2 12/2/2004 © University of Wisconsin, CS559 Fall 2004
15
Indirection Evaluation
Advantages: Connectivity information is easier to evaluate because vertex equality is obvious Saving in storage: Vertex index might be only 2 bytes, and a vertex is probably 12 bytes Each vertex gets used at least 3 and generally 4-6 times, but is only stored once Normals, texture coordinates, colors etc. can all be stored the same way Disadvantages: Connectivity information is not explicit 12/2/2004 © University of Wisconsin, CS559 Fall 2004
16
OpenGL and Vertex Indirection
struct Vertex { float coords[3]; } struct Triangle { GLuint verts[3]; struct Mesh { struct Vertex vertices[m]; struct Triangle triangles[n]; Continued… 12/2/2004 © University of Wisconsin, CS559 Fall 2004
17
OpenGL and Vertex Indirection (v1)
glEnableClientState(GL_VERTEX_ARRAY) glVertexPointer(3, GL_FLOAT, sizeof(struct Vertex), mesh.vertices); glBegin(GL_TRIANGLES) for ( i = 0 ; i < n ; i++ ) { glArrayElement(mesh.triangles[i].verts[0]); glArrayElement(mesh.triangles[i].verts[1]); glArrayElement(mesh.triangles[i].verts[2]); } glEnd(); 12/2/2004 © University of Wisconsin, CS559 Fall 2004
18
OpenGL and Vertex Indirection (v2)
glEnableClientState(GL_VERTEX_ARRAY) glVertexPointer(3, GL_FLOAT, sizeof(struct Vertex), mesh.vertices); for ( i = 0 ; i < n ; i++ ) glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, mesh.triangles[i].verts); Minimizes amount of data sent to the renderer Fewer function calls Faster! Another variant restricts the range of indices that can be used - even faster because vertices may be cached Can even interleave arrays to pack more data in a smaller space 12/2/2004 © University of Wisconsin, CS559 Fall 2004
19
© University of Wisconsin, CS559 Fall 2004
Yet More Variants Many algorithms can take advantage of neighbor information Faces store pointers to their neighbors Edges may be explicitly stored Helpful for: Building strips and fans for rendering Collision detection Mesh decimation (combines faces) Slicing and chopping Many other things Information can be extracted or explicitly saved/loaded 12/2/2004 © University of Wisconsin, CS559 Fall 2004
20
© University of Wisconsin, CS559 Fall 2004
Normal Vectors Normal vectors give information about the true surface shape Per-Face normals: One normal vector for each face, stored as part of face Flat shading Per-Vertex normals: A normal specified for every vertex (smooth shading) Can keep an array of normals analogous to array of vertices Faces store vertex indices and normal indices separately Allows for normal sharing independent of vertex sharing 12/2/2004 © University of Wisconsin, CS559 Fall 2004
21
Cube with Indirection and Normals
Vertices: (1,1,1) (-1,1,1) (-1,-1,1) (1,-1,1) (1,1,-1) (-1,1,-1) (-1,-1,-1) (1,-1,-1) Normals: (1,0,0) (-1,0,0) (0,1,0) (0,-1,0) (0,0,1) (0,0,-1) Faces ((vert,norm), …): ((0,4),(1,4),(2,4),(3,4)) ((0,0),(3,0),(7,0),(4,0)) ((0,2),(4,2),(5,2),(1,2)) ((2,1),(1,1),(5,1),(6,1)) ((3,3),(2,3),(6,3),(7,3)) ((7,5),(6,5),(5,5),(4,5)) 12/2/2004 © University of Wisconsin, CS559 Fall 2004
22
Storing Other Information
Colors, Texture coordinates and so on can all be treated like vertices or normals Lighting/Shading coefficients may be per-face, per-object, or per-vertex 12/2/2004 © University of Wisconsin, CS559 Fall 2004
23
Indexed Lists vs. Pointers
Previous example have faces storing indices of vertices Access a face vertex with: mesh.vertices[mesh.faces[i].vertices[j]] Lots of address computations Works with OpenGL’s vertex arrays Can store pointers directly Access a face vertex with: *(mesh.faces[i].vertices[j]) Probably faster because it requires fewer address computations Easier to write Doesn’t work directly with OpenGL Messy to save/load (pointer arithmetic) Messy to copy (more pointer arithmetic) 12/2/2004 © University of Wisconsin, CS559 Fall 2004
24
© University of Wisconsin, CS559 Fall 2004
Vertex Pointers struct Vertex { float coords[3]; } struct Triangle { struct Vertex *verts[3]; struct Mesh { struct Vertex vertices[m]; struct Triangle faces[n]; glBegin(GL_TRIANGLES) for ( i = 0 ; i < n ; i++ ) { glVertex3fv(*(mesh.faces[i].verts[0])); glVertex3fv(*(mesh.faces[i].verts[1])); glVertex3fv(*(mesh.faces[i].verts[2])); glEnd(); 12/2/2004 © University of Wisconsin, CS559 Fall 2004
25
© University of Wisconsin, CS559 Fall 2004
So you need a mesh… Buy it (or find a free one) Free meshes typically are not very good quality User defined: A user builds the mesh Tools help with specifying many vertices and faces quickly Take any user-friendly modeling technique, and extract a mesh representation from it Scan a real object 3D probe-based systems Range finders Image based reconstruction Take a bunch of pictures, and infer the object’s shape 12/2/2004 © University of Wisconsin, CS559 Fall 2004
26
© University of Wisconsin, CS559 Fall 2004
Meshes from Scanning Laser scanners sample 3D positions One method uses triangulation Another method uses time of flight Some take images also for use as textures Famous example: Scanning the David Software then takes thousands of points and builds a polygon mesh out of them Research topics: Reduce the number of points in the mesh Reconstruction and re-sampling! 12/2/2004 © University of Wisconsin, CS559 Fall 2004
27
© University of Wisconsin, CS559 Fall 2004
Scanning in Action 12/2/2004 © University of Wisconsin, CS559 Fall 2004
28
© University of Wisconsin, CS559 Fall 2004
Level Of Detail There is no point in having more than 1 polygon per pixel Or a few, if anti-aliasing Level of detail strategies attempt to balance the resolution of the mesh against the viewing conditions Must have a way to reduce the complexity of meshes Must have a way to switch from one mesh to another An ongoing research topic, made even more important as laser scanning becomes popular Also called mesh decimation, multi-resolution modeling and other things 12/2/2004 © University of Wisconsin, CS559 Fall 2004
29
© University of Wisconsin, CS559 Fall 2004
Level of Detail 12/2/2004 © University of Wisconsin, CS559 Fall 2004
30
Problems with Polygons
They are inherently an approximation Things like silhouettes can never be perfect without very large numbers of polygons, and corresponding expense Normal vectors are not specified everywhere Interaction is a problem Dragging points around is time consuming Maintaining things like smoothness is difficult Low level representation Eg: Hard to increase, or decrease, the resolution Hard to extract information like curvature 12/2/2004 © University of Wisconsin, CS559 Fall 2004
31
More Object Representations
Hierarchical modeling Instancing and Parametric Instancing Constructive Solid Geometry Sweep Objects Octrees Blobs and Metaballs and other such things 12/2/2004 © University of Wisconsin, CS559 Fall 2004
32
Hierarchical Modeling
Hierarchical model: Group of meshes related by a tree (or graph) structure Properties of children are derived from their parents Most useful for animating polygonal meshes Consider a walking (humanoid, classic) robot: How would you move the robot around? Does the entire robot move in the same way? Does the position of one part of the robot depend on other parts? 12/2/2004 © University of Wisconsin, CS559 Fall 2004
33
Hierarchical Model Example
Move body Draw body Important Point: Every node has its own local coordinate system. This makes specifying transformations much much easier. What are we assuming about the “upper arm” coordinate system? left arm l Rotate about shoulder Draw upper arm Translate (l,0,0) Rotate about origin of lower arm Draw lower arm 12/2/2004 © University of Wisconsin, CS559 Fall 2004
34
© University of Wisconsin, CS559 Fall 2004
Hierarchical Details Generally represented as a tree, with transformations and instances at any node Can use a general graph, but resolving inheritance conflicts is a problem Rendered by traversing the tree, applying the transformations, and rendering the instances Particularly useful for animation Human is a hierarchy of body, head, upper arm, lower arm, etc… Animate by changing the transformations at the nodes Other things can be inherited (colors, surface properties) 12/2/2004 © University of Wisconsin, CS559 Fall 2004
35
© University of Wisconsin, CS559 Fall 2004
OpenGL Support OpenGL defines glPushMatrix() and glPopMatrix() Takes the current matrix and pushes it onto a stack, or pops the matrix off the top of the stack and makes it the current matrix Note: Pushing does not change the current matrix Rendering a hierarchy (recursive): RenderNode(tree) glPushMatrix() Apply node transformation Draw node contents RenderNode(children) glPopMatrix() 12/2/2004 © University of Wisconsin, CS559 Fall 2004
36
© University of Wisconsin, CS559 Fall 2004
Scene Graphs All parts of the scene are represented in one graph Each node in the graph is one scene element, including cameras, objects, lights, transformations, … A generalization of hierarchical modeling To draw the scene, the graph is walked Each time a node is traversed, the state is changed or something is drawn with the current state E.g. traversing a light node turns on the light for all its children Toolkits exist that implement a scene graph architecture Inventor is the best example 12/2/2004 © University of Wisconsin, CS559 Fall 2004
37
© University of Wisconsin, CS559 Fall 2004
Instancing Sometimes you need many copies of the “same” object Like chairs in a room Define one chair, the base or the prototype Create many instances (copies) of it, and apply a different transformation to each Appears in scene description languages (Renderman, Inventor) as “defining” a label for an object What does it save? 12/2/2004 © University of Wisconsin, CS559 Fall 2004
38
© University of Wisconsin, CS559 Fall 2004
OpenGL Support OpenGL defines display lists for encapsulating commands that are executed frequently list_id = glGenLists(1); glNewList(list_id, GL_COMPILE); glBegin(GL_TRIANGLES); draw some stuff glEnd(); glEndList(); And later glCallList(list_id); 12/2/2004 © University of Wisconsin, CS559 Fall 2004
39
© University of Wisconsin, CS559 Fall 2004
More Display Lists Why use display lists? Almost any command can go in a display list Viewing transformation set-up Lighting set-up Surface property set-up But some things can’t Causes strange bugs – always check that a command can go in a display list The list can be: GL_COMPILE: things don’t get drawn, just stored GL_COMPILE_AND_EXECUTE: things are drawn, and also stored 12/2/2004 © University of Wisconsin, CS559 Fall 2004
40
Display Lists Good/Bad
You should use display lists when: You do the same thing over and over again The commands are supported Nothing changes about the way you do it Advantages: Can’t be much slower than the original way Can be much faster Disadvantages: Can’t use various commands that would offer other speedups For example, can’t use glVertexPointer() 12/2/2004 © University of Wisconsin, CS559 Fall 2004
41
Parametric Instancing
Many things, called primitives, are conveniently described by a label and a few parameters Cylinder: Radius, length, does it have end-caps, … Bolts: length, diameter, thread pitch, … Other examples? This is a modeling format: Provide software that knows how to draw the object given the parameters, or knows how to produce a polygonal mesh How you manage the model depends on the rendering style Can be an exact representation 12/2/2004 © University of Wisconsin, CS559 Fall 2004
42
© University of Wisconsin, CS559 Fall 2004
Rendering Instances Generally, provide a routine that takes the parameters and produces a polygonal representation Conveniently brings parametric instancing into the rendering pipeline May include texture maps, normal vectors, colors, etc OpenGL utility library (glu) defines routines for cubes, cylinders, disks, and other common shapes Renderman does similar things, so does POVray, … The procedure may be dynamic For example, adjust the polygon resolution according to distance from the viewer 12/2/2004 © University of Wisconsin, CS559 Fall 2004
43
Constructive Solid Geometry (CSG)
Based on a tree structure, like hierarchical modeling, but now: The internal nodes are set operations: union, intersection or difference (sometimes complement) The edges of the tree have transformations associated with them The leaves contain only geometry Allows complex shapes with only a few primitives Common primitives are cylinders, cubes, etc, or quadric surfaces Motivated by computer aided design and manufacture Difference is like drilling or milling A common format in CAD products 12/2/2004 © University of Wisconsin, CS559 Fall 2004
44
© University of Wisconsin, CS559 Fall 2004
CSG Example - Fill it in! scale translate - cube scale translate scale translate cylinder cylinder 12/2/2004 © University of Wisconsin, CS559 Fall 2004
45
© University of Wisconsin, CS559 Fall 2004
Sweep Objects Define a polygon by its edges Sweep it along a path The path taken by the edges form a surface - the sweep surface Special cases Surface of revolution: Rotate edges about an axis Extrusion: Sweep along a straight line 12/2/2004 © University of Wisconsin, CS559 Fall 2004
46
© University of Wisconsin, CS559 Fall 2004
Rendering Sweeps Convert to polygons Break path into short segments Create a copy of the sweep polygon at each segment Join the corresponding vertices between the polygons May need things like end-caps on surfaces of revolution and extrusions Normals come from sweep polygon and path orientation Sweep polygon defines one texture parameter, sweep path defines the other 12/2/2004 © University of Wisconsin, CS559 Fall 2004
47
A Circular Tube (A torus)
What do we sweep, along what path? Vector3 points[2][8]; int start_i = 0; int end_i = 1; for ( int i = 0 ; i < 8 ; i++ ) points[start_i][i] = TorusPoint(7,i); for ( int j = 0 ; j < 8 ; j++ ) { glBegin(GL_TRIANGLE_STRIP); for ( int i = 0 ; i < 8 ; i++ ) { glVertex3fv(points[start_i][i]; points[end_i][i] = TorusPoint[j][i]; glVertex3fv(points[end_i][i]; } glVertex3fv(points[start_i][0]); glVertex3fv(points[end_i][0]); glEnd(); int temp = start_i; start_i = end_i; end_i = temp; 12/2/2004 © University of Wisconsin, CS559 Fall 2004
48
© University of Wisconsin, CS559 Fall 2004
General Sweeps The path maybe any curve The polygon that is swept may be transformed as it is moved along the path Scale, rotate with respect to path orientation, … One common way to specify is: Give a poly-line (sequence of line segments) as the path Give a poly-line as the shape to sweep Give a transformation to apply at the vertex of each path segment Difficult to avoid self-intersection 12/2/2004 © University of Wisconsin, CS559 Fall 2004
49
© University of Wisconsin, CS559 Fall 2004
Spatial Enumeration Basic idea: Describe something by the space it occupies For example, break the volume of interest into lots of tiny cubes, and say which cubes are inside the object Works well for things like medical data The process itself, like MRI or CAT scans, enumerates the volume Data is associated with each voxel (volume element) Problem to overcome: For anything other than small volumes or low resolutions, the number of voxels explodes Note that the number of voxels grows with the cube of linear dimension 12/2/2004 © University of Wisconsin, CS559 Fall 2004
50
Octrees (and Quadtrees)
Build a tree where successive levels represent better resolution (smaller voxels) Large uniform spaces result in shallow trees Quadtree is for 2D (four children for each node) Octree is for 3D (eight children for each node) 12/2/2004 © University of Wisconsin, CS559 Fall 2004
51
© University of Wisconsin, CS559 Fall 2004
Quadtree Example top left top right bot left bot right Octree principle is the same, but there are 8 children 12/2/2004 © University of Wisconsin, CS559 Fall 2004
52
© University of Wisconsin, CS559 Fall 2004
Rendering Octrees Volume rendering renders octrees and associated data directly A special area of graphics, visualization, not covered in this class Can convert to polygons by a few methods: Just take faces of voxels that are on the boundary Find iso-surfaces within the volume and render those Typically do some interpolation (smoothing) to get rid of the artifacts from the voxelization Typically render with colors that indicate something about the data, but other methods exist 12/2/2004 © University of Wisconsin, CS559 Fall 2004
53
© University of Wisconsin, CS559 Fall 2004
Smooth versus General Polygon meshes are very general, but hard to model with In a production context (film, game), creating a dense, accurate mesh requires lots of work Biggest problem is smoothness We desire a way to “smooth out” a polygonal mesh We can model at a coarse level, and automatically fill in the smooth parts Subdivision surfaces are part of the answer 12/2/2004 © University of Wisconsin, CS559 Fall 2004
54
© University of Wisconsin, CS559 Fall 2004
Subdivision Schemes Basic idea: Start with something coarse Control points, line segments (for curves), polygons (for surfaces) Refine it into smaller pieces, smoothing along the way Subdivision rules to make finer resolution Still get a discrete approximation to smooth thing Limit Surface (or Curve) The “mathematical” result is what happens after infinite steps Exact Evaluation – tells about points on limit surface Schemes Stationary points /schemes – stay put (interpolate) Non-stationary points – move (approximate original) In this lecture: We will see how it can be used for modeling specific objects, and as a modeling scheme in itself Subdivision for tessellating a sphere Subdivision for fractal surfaces General subdivision surfaces 12/2/2004 © University of Wisconsin, CS559 Fall 2004
55
© University of Wisconsin, CS559 Fall 2004
Tessellating a Sphere Spheres are frequently parameterized in polar coordinates: Note the singularity at the poles Tessellation: The process of approximating a surface with a polygon mesh One option for tessellating a sphere: Step around and up the sphere in constant steps of and Problem: Polygons are of wildly different sizes, and some vertices have very high degree 12/2/2004 © University of Wisconsin, CS559 Fall 2004
56
© University of Wisconsin, CS559 Fall 2004
Subdivision Method Begin with a course approximation to the sphere, that uses only triangles Two good candidates are platonic solids with triangular faces: Octahedron, Isosahedron They have uniformly sized faces and uniform vertex degree Repeat the following process: Insert a new vertex in the middle of each edge Push the vertices out to the surface of the sphere Break each triangular face into 4 triangles using the new vertices Octahedron Isosahedron 12/2/2004 © University of Wisconsin, CS559 Fall 2004
57
© University of Wisconsin, CS559 Fall 2004
The First Stage Each new vertex is degree 6, original vertices are degree 4 Each face gets split into 4: 12/2/2004 © University of Wisconsin, CS559 Fall 2004
58
© University of Wisconsin, CS559 Fall 2004
Regular Meshes Triangle “grids” (regular hex patterns) Guad grids (squares) Semi-regular meshes (few “extraordinary” points) 12/2/2004 © University of Wisconsin, CS559 Fall 2004
59
Sphere Subdivision Advantages
All the triangles at any given level are the same size Relies on the initial mesh having equal sized faces, and properties of the sphere The new vertices all have the same degree Mesh is regular (or uniform) in newly generated areas This is a property we will see later in subdivision surfaces Makes it easier to analyze what happens to the surface The location and degree of existing vertices does not change The only extraordinary points lie on the initial mesh Extraordinary points are those with degree different to the uniform areas 12/2/2004 © University of Wisconsin, CS559 Fall 2004
60
© University of Wisconsin, CS559 Fall 2004
Fractal Surfaces Fractals are objects that show self similarity The word is overloaded – it can also mean other things Landscapes and coastlines are considered fractal in nature Mountains have hills on them that have rocks on them and so on Continents have gulfs that have harbors that have bays and so on Subdivision is the natural way of building fractal surfaces Start with coarse features, Subdivide to finer features Different types of fractals come from different subdivision schemes and different parameters to those schemes 12/2/2004 © University of Wisconsin, CS559 Fall 2004
61
© University of Wisconsin, CS559 Fall 2004
Fractal Terrain (1) Start with a coarse mesh Vertices on this mesh won’t move, so they can be used to set mountain peaks and valleys Also defines the boundary Mesh must not have dangling edges or vertices Every edge and every vertex must be part of a face Also define an “up” direction Then repeatedly: Add new vertices at the midpoint of each edge, and randomly push them up or down Split each face into four, as for the sphere 12/2/2004 © University of Wisconsin, CS559 Fall 2004
62
Fractal Terrain Example
A mountainside 12/2/2004 © University of Wisconsin, CS559 Fall 2004
63
Fractal Terrain Details
There are options for choosing where to move the new vertices Uniform random offset Normally distributed offset – small motions more likely Procedural rule – eg Perlin noise Reducing the offset of new points according to the subdivision level is essential Define a scale, s, and a ratio, k, and at each level: si+1=ksi Colors are frequently chosen based on “altitude” 12/2/2004 © University of Wisconsin, CS559 Fall 2004
64
Fractal Terrain Algorithm
The hard part is keeping track of all the indices and other data Same algorithm works for subdividing sphere Split_One_Level(struct Mesh terrain) Copy old vertices for all edges Create and store new vertex Create and store new edges for all faces Create new edges interior to face Create new faces Replace old vertices, edges and faces 12/2/2004 © University of Wisconsin, CS559 Fall 2004
65
How to divide triangles
Need to do all triangles the same way Can’t break edges on one side, not the other Break edges at midpoint Common way each triangles -> 4 triangles All new points are ordinary (or edges) Don’t break edges (Uncommon triangle -> 3 triangle) 12/2/2004 © University of Wisconsin, CS559 Fall 2004
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.