INF3320 Computer Graphics and Discrete Geometry More smooth Curves and Surfaces Christopher Dyken, Michael Floater and Martin Reimers 10.11.2010 Page 1
More smooth Curves and Surfaces Akenine-Möller, Haines and Hoffman: Tessellation (Chapter 13.6) Implicit surfaces (Chapter 13.3) Subdivision curves (Chapter 13.4) Subdivision surfaces (Chapter 13.5) Page 2
Parametric patches Page 3
Previously in inf3320... Parametric curves and surfaces (patches) p(u 1,v 1 ) p(u 2,v 1 ) v 2 v p p(u,v) v 1 u1 u u2 p(u 1,v 2 ) p(u 2,v 2 ) Page 4
Composing patches Did not talk about: Complex models by composing patches: Challenge: make patches match with C 0, C 1,... continuity Page 5
Composing patches with continuity Constraints on control-points C 0 C 1 Page 6
Composing patches... Nice shading/reflections reveal continuity Page 7
Composing patches... Nice shading/reflections reveal continuity How to render spline patches? Convert to triangles... Page 8
Tessellation Page 9
Tessellation Recall: OpenGL can only handle points, lines, triangles,... Smooth geometry must be tessellated, i.e. approximated Standard approach: sample the smooth geometry, eg uniformly render linear geometry 0 1 Page 10
Tessellation Recall: OpenGL can only handle points, lines, triangles,... Smooth geometry must be tessellated, i.e. approximated Standard approach: sample the smooth geometry, eg uniformly render linear geometry 0 1 Page 11
Smooth surface tessellation More challenging to sample parametric surfaces Basic approach: tessellate parameter domain render corresponding surface mesh Page 12
Smooth surface tessellation More challenging to sample parametric surfaces Basic approach: tessellate parameter domain render corresponding surface mesh Simple algorithm, suitable for GPU Job for the Geometry shader? (one triangle in - multiple out)... not in practice (too few output triangles) Page 13
Adaptive tessellation of patches [Dyken,Reimers,Seland 2008] 1 Bezier-triangle per triangle (pre)tessellate each individually Adapt along common boundaries Render corresponding mesh GPGPU and Vertex shader programs, instancing,... Code sample on Nvidias webpages Page 14
Hardware Tessellation Shader model 5.0 HW (DirectX11) Comes with hardware tessellation: OpenGL: ARB_tessellation_shader Configurable step in the pipeline Patches tessellated on GPU Fractional tessellation, continuous LOD Solves many problems... Page 15
Implicit surfaces Page 16
Algebraic Surfaces Zero set of polynomial f : R 3 R f (x, y, z) = f ijk x i y j z k = 0 0 i+j+k d Sphere: x 2 + y 2 + z 2 1 = 0 Classic field of mathematics Very compact representation Renewed interest as geom. rep. Visualized by e.g. marching cubes (contouring) or ray-casting Page 17
Ray-casting Overview Given a view frustum and screen resolution (m + 1) (n + 1) Let each pixel correspond to a ray r pq : [0, 1] R 3 Find first intersection i.e. f (r pq (t)) = 0 Find final pixel color Little brother of ray-tracing Back plane m + 1 n + 1 Ray-casting is in some sense the opposite of rasterization Page 18
Digression: Real time raytracing on the GPU Raycasting is computationally demanding embarrassingly parallel (check Wikipedia!) A good candidate application for a GPU implementation [Reimers-Seland, Eurographics 2008] paper/video: http://folk.uio.no/martinre Page 19
Subdivision curves Page 20
Subdivision of Bézier Curves We have seen that the de Casteljau algorithm evaluates a Bézier curve from its control polygon. The intermediate points of the de Casteljau algorithm define the control points of two Bézier segments representing the original. = We can divide one Bézier segment into two Bézier segments! Page 21
On the left is the triangular structure of the intermediate points of the de Casteljau evaluation. On the right is a figure of the points. p 0 0 p 1 0 p 2 0 p 3 0 p 1 0 p 2 0 1 t t 1 t t 1 t p1 p1 p1 0 2 1 t t 1 t t t p 0 1 p 0 2 p 0 3 p 1 2 p 2 1 p 0 2 p 1 2 1 t t p3 0 p 0 0 p 3 0 The original segment on [0, 1] has control points p 0 0, p0 1, p0 2, p0 3. The segment on [0, t] has control points p 0 0, p1 0, p2 0, p3 0. The segment on [t, 1] has control points p 3 0, p2 1, p1 2, p0 3. Page 22
If we divide at t = 1 2, we get p 0 0 = p 0 0 p 3 0 = 1 8 (p0 0 + 3p 0 1 + 3p 0 2 + p 0 3), p 1 0 = 1 2 (p0 0 + p 0 1), p 2 1 = 1 4 (p0 1 + 2p 0 2 + p 0 3), p 2 0 = 1 4 (p0 0 + 2p 0 1 + p 0 2), p 1 2 = 1 2 (p0 2 + p 0 3), p 3 0 = 1 8 (p0 0 + 3p 0 1 + 3p 0 2 + p 0 3), p 0 3 = p 0 3, This is a refinement rule for cubic Bézier curves. Under repeated division, called subdivision, the control polygon converges to the curve. In practice: render the control polygon after a few subdivisions There are similar rules for (uniform) splines Subdivision curves are defined by such refinement rules. Page 23
Subdivision curves Curves generated by iterative refinement of a given control polygon (vertices=control points). The result after infinitely many steps is called the limit curve. Both Bézier curves and spline curves are subdivision curves. (I.e. there exists subdivision schemes to generate them) Many such schemes (subdivision zoo). Page 24
Chaikin s scheme From control points..., p i 1, p i, p i+1,..., 0 0 p i p i+1 we refine with the rule 1 p 2i+1 p k+1 2i = 1 4 pk i + 3 4 pk i 1 0 p i 1 1 p 2i p k+1 2i+1 = 3 4 pk i + 1 4 pk i 1 Important: The indices differs slightly from the book. Repeat the refinement ad infinitum.! Observation: the number of points doubles at each iteration. Converges to a quadratic C 1 spline curve. Page 25
Masks and stencils Collect coefficients into even stencil and odd stencils (rules) and get a e = { 1 4, 3 4 } and ao = { 3 4, 1 4 }, p k+1 2i = 1 4 pk i + 3 4 pk i 1 = j Z a e j p k i j p k+1 2i+1 = 3 4 pk i + 1 4 pk i 1 = aj o p k i j, j Z combined, the even and odd stencils form the mask of the scheme, a = { 1 4, 3 4, 3 4, 1 4 } which yields p k+1 i = j Z a i 2jp k j for i Z The mask express the influence of an old vertex on the new verts. Page 26
C 2 cubic spline subdivision Another example is a C 2 cubic spline curve. 0 0 p i p i+1 The subdivision rule is 0 p i 2 0 p i 1 1 p 2i 1 p 2i+1 p k+1 2i = 1 8 pk i + 6 8 pk i 1 + 1 8 pk i 2 p k+1 2i+1 = 1 2 pk i + 1 2 pk i 1 i.e. even (vertex) and odd (edge) stencils a e = { 1 8, 6 8, 1 8 } and ao = { 1 2, 1 2 }, and the mask a = { 1 8, 1 2, 6 8, 1 2, 1 8 }. Note: stencils are convex combinations of control points Page 27
General C d 1 uniform spline subdivision The mask for a C d 1 spline curve of degree d is given by a = {a 0, a 1,..., a d+1 } = 1 2 d {( d + 1 0 ), ( d + 1 1 ) ( )} d + 1,..., d + 1 Examples: a = { 1 2, 1, 1 2 } a = { 1 4, 3 4, 3 4, 1 4 } a = { 1 8, 1 2, 6 8, 1 2, 1 8 } Linear spline Quadratic spline (Chaikin) Cubic spline a = { 1 16, 5 16, 10 16, 10 16, 5 16, 1 16 } Quartic spline Note: level d mask can be obtained by averaging level d 1 masks Page 28
Interpolatory subdivision Quadratic spline scheme: convex comb. yields convex hull-property The four-point scheme interpolates control points Page 29
Subdivision surfaces Page 30
Subdivision surfaces Page 31
Subdivision surfaces Generated by iterative refinement of a polygonal mesh. Usually, the mesh has four-sided faces (quadrilateral meshes) or three sided faces (triangle meshes). Scheme given by refinement rule, typically generalize 1D rules Can repeat to infinity in theory, interested in limit surface Page 32
Subdivision surfaces Surfaces modeled in one piece - built-in continuity Page 33
For uniform ( structured ) meshes, the limit surface is a spline surface (e.g. piecewise polynomial). Rectangular grid Triangular grid uniform rectangular mesh = tensor-product spline surface. uniform triangular mesh = box-spline surface. Page 34
Tensor-product subdivision on rectangular grids Example 1: Chaikin s scheme. We can create subdivision rules for tensor product surfaces by taking tensor products of curve stencils. For example [ 1 ] [ 4 3 3 4 4 1 4 ] = [ 3 16 9 16 1 16 3 16 ] = 1 16 [ ] 3 1. 9 3 which is the tensor product of the even and odd stencil. There are four ways to combine the even and odd stencils: [ ] [ ] [ ] [ ] 1 3 1 1 1 3 1 9 3 1 3 9,,,. 16 9 3 16 3 9 16 3 1 16 1 3 Page 35
Tensor products of Chaikin stencils yields subdivision rule for C 1 biquadratic tensor product splines. Get 4 nodes inside each quad: n 1 v i 1,j n v 2i,2j+1 n 1 v i,j n v 2i+1,2j+1 v n 2i,2j n 1 vi 1,j 1 n v2i+1,2j n 1 v i,j 1 v n 2i,2j = 1 16 (9vn 1 i 1,j 1 + 3vn 1 i,j 1 + 3vn 1 i 1,j + vn 1 i,j ) v n 2i+1,2j = 1 16 (3vn 1 i 1,j 1 + 9vn 1 i,j 1 + vn 1 i 1,j + 3vn 1 i,j ) v n 2i,2j+1 = 1 16 (3vn 1 i 1,j 1 + vn 1 i,j 1 + 9vn 1 i 1,j + 3vn 1 i,j ) v n 2i+1,2j+1 = 1 16 (vn 1 i 1,j 1 + 3vn 1 i,j 1 + 3vn 1 i 1,j + 9vn 1 i,j ) Page 36
Example 2: C 2 bicubic. The mask for cubic curves is [ ] 1 [ ] a0 a 1 a 2 a 3 a 4 = 1 4 6 4 1. 8 i.e., the even and odd stencils are 1 [ ] 1 6 1 8 and 1 [ ] 1 1. 2 Tensor-products of these stencils yields four bicubic stencils: 1 6 1 1 6 36 6, 64 1 6 1 }{{} Stencil A 1 1 [ ] 1 6 6 1 1 6 1,, 16 16 1 6 1 1 1 }{{} Stencils B [ ] 1 1 1. 4 1 1 }{{} Stencil C Page 37
These are used to compute the four new control points [ v n 2i+1,2j v2i+1,2j+1 n ] n 1 v i,j v n 2i,2j v n 2i,2j+1 from the old control points v n 1 i 2,j v n 1 i 2,j 1 v n 1 i 2,j 2 v n 1 i 1,j v n 1 i 1,j 1 v n 1 i 1,j 2 1 6 1 1 6 36 6, 64 1 6 1 }{{} Stencil A v n 1 i,j v n 1 i,j 1 v n 1 i,j 2. n 1 v i 2,j n 1 v i 1,j n v 2i,2j+1 n 1 vi 2,j 1 v n 2i+1,2j+1 n v 2i,2j n 1 vi 1,j 1 1 1 [ ] 1 6 6 1 1 6 1,, 16 16 1 6 1 1 1 }{{} Stencils B v n 2i+1,2j n 1 vi 2,j 2 n 1 v i,j 1 n 1 v i 1,j 2 [ ] 1 1 1. 4 1 1 }{{} Stencil C n 1 vi,j 2 Page 38
Generalized subdivision So far: polynomial surfaces can be described by subdivision Want to extend rules to handle meshes that are not regular grids Also want the limit surface to be as smooth as possible. Page 39
Non-uniform meshes Faces with n vertices (not only 3 and 4) Vertices with valence m 4, 6, so called extraordinary points Many subdivision schemes, for different mesh-types typically polynomial locally... but not near extraordinary points. Page 40
Catmull-Clark subdivision surfaces A generalization of C 2 bicubic spline subdivision scheme to an arbitrary polygonal mesh. The limit surface is C 1 at extraordinary points and C 2 elsewhere. It has been shown that C 2 continuity at extraordinary points is impossible without using larger stencils. Page 41
The basic idea of the Catmull-Clark subdivision scheme is: The input mesh can contain any types of polygons (triangles, quads, etc.) Calculate face points, edge points, and vertex points. For each vertex in each face, create a quad connecting the vertex point, two edge points, and a face point. After one refinement, the mesh consists of quads exclusively. Page 42
Face points are averages of the polygon vertices v1 k,..., vk m, f k+1 = 1 n vi k n Edge points are the average of the two end-points of the edge v k, e k and the face points of the two adjacent faces f k+1 i, f k+1 e k+1 = 1 ( ) v k + e k + f k+1 i + f k+1 j 4 i=1 j, Vertex points are combinations of surrounding vertices v1 k,..., vk n and the face points f1 k,..., fk n of the adjacent faces, v k+1 = n 2 n vk + 1 n n 2 e k i + 1 n n 2 f k+1 i i=1 i=1 Page 43
Catmull Clark New control points are convex comb. of the old = Convex hull property, stable algorithms Limit points, tangents, etc can be computed Usually not evaluated, but can be done Page 44
Loop subdivision A subdivision scheme for arbitrary triangle meshes. The Loop scheme is based on so-called C 2 quartic box-splines Page 45
The Loop subdivision scheme uses the 1-4 split: After one subdivision step each former triangle is replaced by four: V i+1 = V i + E i, E i+1 = 2 E i + 3 T i, T i+1 = 4 T i. There are only two stencils in the Loop scheme: 1. positions for vertices corresponding to the old vertices, and 2. positions for vertices corresponding to edge points. Page 46
In the Loop scheme, the new position is a combination of the position of the old vertex and its immediate neighbours: where β β β β = 1 ( ) 5 (3 + 2 cos(2π/n))2. n 8 64 1 nβ β β β β The canonical case is n = 6 in which case the scheme reduces to box-spline subdivision, yielding a C 2 surface. Loop showed that the limit surface is C 1 at extraordinary points, and C 2 elsewhere. Page 47
The position of the edge-point is a combination of the vertices of the two triangles adjacent to that edge: 1/8 3/8 3/8 1/8 Then, what should we do along the boundary? Page 48
A common technique for dealing with the boundary in the Loop scheme is to let the boundary curve be a cubic spline. Recall that the mask of cubic spline curve subdivision is a = { 1 8, 1 2, 3 4, 1 2, 1 8 } and let boundary edge points be determined by the odd stencil and the boundary vertices be determined by the even stencil, i.e., 1/8 3/4 1/2 1/8 1/2 Page 49
3 subdivision A subdivision scheme for arbitrary triangle meshes. The 3 subdivision scheme of Leif Kobbelt creates only 3 new triangles per triangle in each subdivision step (Loop creates 4). C 1 continuous in extraordinary vertices and C 2 elsewhere Page 50
The splitting scheme of 3 subdivision is: Given a triangle mesh, compute the new positions for the vertices as well as the triangle midpoints from the old vertices, split each triangle into three new triangles, then swap the diagonal of all pairs of adjacent triangles where the common edge is an old edge. Page 51
We can create the new triangles directly: Each edge in the old mesh yields two new triangles. To handle boundaries, we use the same rules as Loop (Slide??) to calculate boundary edge points and boundary vertices. Each boundary edge yields two new triangles connecting the end points of the edge, the adjacent triangle midpoint, and the edge point. Note: Only boundary edges get an edge point! Page 52
3 subdivision has a vertex rule and a triangle rule: β β 1 nβ β β The vertex rule is a blend of the old position and the surrounding vertices, where β β β β = 4 2 cos(2π/n). 9n 1/3 The triangle midpoint rule is simple, the position is the barycentre of the triangle. 1/3 1/3 Page 53
Interpolatory subdivision schemes The butterfly scheme: vertex points preserved, edge points by affine combination Yields C 1 smooth surfaces that interpolates control mesh Page 54
Interpolatory subdivision schemes The butterfly scheme: vertex points preserved, edge points by affine combination Yields C 1 smooth surfaces that interpolates control mesh Approximating (spline-based) and interpolatory schemes produce very different limit surfaces Page 55
Features, creases Subdivision surfaces with piecewise continuity Modified rules to get features, sharp creases etc. Page 56
Subdivision surfaces - summary Pros: Many of the pros of splines Flexibility, wrt. topology/mesh Spline surfaces without gaps and seams! Simple to implement Simple/intuitive to manipulate Cons: No global closed form (but locally) Evaluation not straight forward (but?) C k, k > 1 is hard Artefacts (ripples etc.) CC cannot make convex surface for n > 5 Page 57
The last slide Next time - advanced topics: Global illumination Shadows GPU programming... Page 58