28(69) Splines Originally a drafting tool to create a smooth curve In computer graphics: a curve built from sections, each described by a 2nd or 3rd degree polynomial. Very common in non-real-time graphics, both 2D and 3D Useful also for real-time. 28(69)
Applications of splines Designing smooth curves (common in 2D illustrations) Filter design Modelling smooth surfaces Representating of smooth surfaces (converted to polygons in real-time) Animation paths 29(69)29(69)
Important application of splines: Text rendering We will return to that subject on a later lecture. 30(69)30(69)
Control points A spline is specified by a set of control points. 31(69)31(69)
Interpolation spline Control points on the curve. Approximation spline Control points not on the curve. 32(69)32(69)
Parametric representation x = x(u) y = y(u) z = z(u) u 1 u u 2 A set of functions for each coordinate 33(69)33(69)
Parametric continuity C 0 = continuous position = the curves meet C 1 = continuous direction = the curves meet at same angle C 2 = continuous curvature = the curves meet at same bend 34(69)34(69)
Specification of splines by polynomials in multiple sections x 1 (u) = a x1 u 3 + b x1 u 2 + c x1 u + d x1 Continuity in this point? y 1 (u) = a y1 u 3 + b y1 u 2 + c y1 u + d y1 z 1 (u) = a z1 u 3 + b z1 u 2 + c z1 u + d z1 x 2 (u) = a x2 u 3 + b x2 u 2 + c x2 u + d x2 1 2 y 2 (u) = a y2 u 3 + b y2 u 2 + c y2 u + d y2 z 2 (u) = a z2 u 3 + b z2 u 2 + c z2 u + d z2 35(69)35(69)
Parametric continuity u = u 1 1 2 C 0 : x 1 (u 1 ) = x 2 (u 1 ) y 1 (u 1 ) = y 2 (u 1 ) z 1 (u 1 ) = z 2 (u 1 ) C 1 : x 1 (u 1 ) = x 2 (u 1 ) y 1 (u 1 ) = y 2 (u 1 ) z 1 (u 1 ) = z 2 (u 1 ) C1: 6 equations per vertex, 12 coefficients per section 36(69)36(69)
Geometric continuity G 0 = C 0 = continuous position = the curves meet G 1 = proportinal direction = the curves meet at same angle but not same velocity G 2 = proportional curvature = the curves meet at same bend but not same velocity 37(69)37(69)
Geometric continuity u = u 1 1 2 G 0 : x 1 (u 1 ) = x 2 (u 1 ) y 1 (u 1 ) = y 2 (u 1 ) z 1 (u 1 ) = z 2 (u 1 ) G 1 : x 1 (u 1 ) = k*x 2 (u 1 ) y 1 (u 1 ) = k*y 2 (u 1 ) z 1 (u 1 ) = k*z 2 (u 1 ) for some k Essentially one less constraint 38(69)38(69)
Blending functions Rewrite parametric form to a set of polynomials, one polynomial for each control point 39(69)39(69)
Approximation splines Use a set of blending functions to blend together control points to points on the curve Bézier curves B-splines NURBS 40(69)40(69)
Common demand on approximations splines: Stay within the convex hull of the control points Convex hull = minimal convex polygon enclosing a specified set of points 41(69)41(69)
Bézier curves Typically uses 3 or 4 control points per section 42(69)42(69)
Bézier curves The 4 points are blended together using 4 blending functions 4 blending functions = Cubic Bézier 43(69)43(69)
Bézier curves Blending functions: Bernstein polynomials BEZ 0,3 = (1-u) 3 BEZ 1,3 = 3u(1-u) 2 BEZ 2,3 = 3(1-u)u 2 BEZ 3,3 = u 3 The sum is 1 for any u 44(69)44(69)
1 P 0 P 1 P 2 P 3 BEZ 0,3 = (1-u) 3 BEZ 1,3 = 3u(1-u) 2 u BEZ 2,3 = 3(1-u)u 2 BEZ 3,3 = u 3 1 u P(u) = P 0 *(1-u) 3 + P 1 *3u(1-u) 2 + P 2 *3(1-u)u 2 + P 3 *u 3 3 = P i * BEZ i,3 (u) i = 0 45(69)45(69)
Fitting together sections C 0 /G 0 continuity: just fit the points C 1 continuity: Tangents are equal along the edge. G 1 continuity: Tangents have same direction along the edge. Simple method: Put 3 points in a line 46(69)46(69)
Quadratic Bezier curves Three control points 2nd order polynomials p(u) = (1-u) 2 p 0 + 2u(1-u)p 1 + u 2 p 2 47(69)47(69)
de Casteljau s algorithm A Bézier is really an interpolation of interpolations p 1 p 3 q 1 q 0 q 2 p 0 p 2 48(69)48(69)
de Casteljau s algorithm Linear interpoations of linear interpolations until only one point remains p 1 p 3 q 1 q 0 r 0 r 1 p(u) q 2 p 0 p 2 49(69)49(69)
de Casteljau s algorithm Gives us the Bernstein polynomials of any level we want. Linear (2 points) = plain interpolation Quadratic Béziers (3 points) Cubic (4 points) Higher levels possible but not practical 50(69)50(69)
de Casteljau s algorithm Obvious from figure/method: Bézier is always inside convex hull Fit together sections by keeping points along a line also obvious - we must start along the tangent 51(69)51(69)
Interpolation splines Passes through all control points. Control points on the curve. 52(69)52(69)
Blending functions for interpolation spline The points are blended together using blending functions 53(69)53(69)
Blending functions for interpolation spline All blending functions are zero or 1 at the control points Actual blending functions for interpolated spline of 4 control points (similar to Bézier) 54(69)54(69)
Cardinal splines Catmull-Rom splines Interpolation spline Specified only by control points Calculated from 4 control points, define between the middle two A tension parameter t can adjust the shape t = 0 => Catmull-Rom 55(69)55(69)
Catmull-Rom splines, Matrix form P(u) = [ u 3 u 2 u 1] -1/2 3/2-3/21/2 1-5/2 2-1/2-1/2 0 1/2 0 0 1 0 0 p k-1 p k p k+1 p k+2 P(u) = p k-1 (-u 3 /2 + u 2 - u/2) + p k (3u 3 /2-5u 2 /2 + 1) + p k+1 (-3u 3 /2 + 2u 2 + u/2) + p k+2 (u 3 /2 - u 2 /2) = p k-1 *CAR 0 (u) + p k *CAR 1 (u) + p k+1 *CAR 2 (u) + p k+2 *CAR 3 (u) 56(69)56(69)
Catmull-Rom splines, Blending functions 57(69)57(69)
Application of Catmull-Rom splines: Animation paths Defined by a sequence of points on the curve Always G 1 /C 1 continuous 58(69)58(69)
Bézier surfaces A surface is built from a set of Bézier patches A Bézier patch consists of 16 control points in a 4x4 grid 59(69)59(69)
Bézier surfaces Blending of the 16 control points as a 2- dimensional sum 3 3 P(u,v) = p j,k BEZ j,3 (v) BEZ k,3 (u) j=0 k=0 u v 60(69)60(69)
Bézier surface example 61(69)61(69)
Fitting together patches Fit in both u and v direction Make a 3x3 joystick at each corner 62(69)62(69)
Drawing splines Subdivide the spline until the error is small enough. u=0 u=0.25 u=0.375 u=1 u=0.5 u=0.75 63(69)63(69)
Splines and surfaces in OpenGL Pre-generated shapes on CPU Generate by multi-pass GPU processing Old OpenGL: Evaluators (glmap) 3.2: Geometry shaders 4: Tesselation shaders 64(69)64(69)
Evaluators Old built-in Bezier evaluator. Easy to use but no longer recommended. Supported both curves and surfaces 65(69)65(69)
Geometry shaders OpenGL 3 (extension in GL 2) Shader between vertex and fragment, converts geometry, can add new vertices Modest hardware demand: G80 or better (2007+) 66(69)66(69)
Tesselation shaders OpenGL 4 Shader between vertex and fragment (before geometry shader), focused on subdivision Higher hardware demand (Southfork is OK) 67(69)67(69)
Applications of geometry stage shaders: Splines/surfaces Edge extraction, silhouettes Polygon-level effects (shrinking triangles) Adaptive subdivision Visualizing normal vectors etc 68(69)68(69)
More object representation soon... Fractals and procedural generation but first let us move to the animation subject 69(69)69(69)