**Contents**

## Bézier Surfaces

Once we understand the principle of Bézier curve extending the same technique to Bézier surface is really straightforward. Rather than having 4 points we will define the surface with 16 points which you can see as a grid of 4x4 control points. In the case of curves we had 1 parameter to move along the curve (t). In the case of surface we will need two: one to move in the u direction and one to move in the v direction (see figure 1). Both u and v are contained within the range [0,1]. You can see the process of going from (u, v) to 3D space as a remapping of the unit square (defined by u, v) into a smooth continuous surface within the tree dimensional space. intuitively, you can see that a Bézier surface is made of many curves going along either the u or v direction. For instance, if we move in the v direction we need to interpolate the curves defined by the points 1, 2, 3, 4 and 5, 6, 7, 8 (and so on for the rest of the surface). If we move along the u direction, the curves defined by the points 1, 5, 9, 13 and 2, 6, 10, 14 need to be interpolated instead. More formally, a point on the Bézier surface depends of the parametric values u and v, and can be defined (equation 1) as a double sum of control points and coefficients ("a sum of Bézier curves"):

$$P(u, v) = \sum_{i=0}^n \sum_{j=0}^m B_i^n(u) B_j^m(v)P_{ij}$$where as for curves,

$$B_i^n(u)=\left(\begin{array}{c}n\\i\end{array}\right) u^i(1-u)^{n-i}$$

is a **Bernstein polynomial (equation 2)**, and

is a **binomial coefficient** (equation 3). We can see easily see the similarities with curves. If you are interested in the terminology, we say that a Bézier surface (or patch) is constructed as the **tensor product** of two Bézier curves. Note that we will only consider bicubic Bézier surface in this lesson, that is, surfaces for which n = 3 and m = 3. Therefore, the Bernstein polynomials (equation 4) are the same as with bicubic curves (we have four of them and they are the same for n and m. We just show the coefficients for u but the same equation are used for v):

## Tesselating a Bézier Patch

Bézier surface can be ray traced directly but the methods known haven't always been robust and can be slow. An easier solution (which is often the choice made by many renderers) is to convert Bézier patches to polygon grids. Evaluating the position of a point on the surface for a pair of values (u, v) is easy. We need to treat each row of the 4x4 control point grid as individual bezier curves. We will use one of the parameters (u) to evaluate a position in 3D space along each one of these curves. From this process we obtain four points which we can look at as the four control points of another Bézier curve oriented along the other direction (v). Using the second parameter v, we can evaluate the final position along this curve. This correspond to a point on the surface for a given pair of values (u, v). Similarly to curve, we will compute position at regular intervals of u, b which we can use at the vertices of polygon grid. The pseudocode looks like this:

Creating the grid once we have this function is straighforward. We need to decide how many rows and vertices of quads we want, which defines the number of steps we take in u and v, compute the vertices positions on the surface for these pairs of (u, v) values and connect these vertices to form the mesh (check the source code further down). The advantage of converting a Bézier surface into a polygon grid is that we can adapt the number of polygons (the resolution of the grid) based on some criteria such as the curvature of the surface or its distance to the camera (a surface closer to the camera requires a higher definition. This is the principle of the REYES algorithm used by Pixar's renderer). What we render at the end is not the Bézier surface. Instead we evaluate the Bézier surface as a polygon mesh which we can ray trace as a mesh (as we did with the polygon sphere in lesson 10).

## Source Code

The renderer needs to access the teapot data which we have saved in a separate file. The format is very similar to that of polygonal objects. We first have a series of vertices and 32 arrays of 16 integers which defines the position of the patches' control points in this array.

Finally, before the render starts, we need to convert each one of these Bézier patches into a polygon grid. For each converted patch, we set the sixteen control points (lines 26-29), then construct a pair of (u, v) values for each vertex of the grid (we can control the resolution of the grid line 19) which is used to compute a position on the surface (line 33). The function returning this position, computes the four auxillary control points necesary to create a curve along the v direction, using the u parameter. We can then use the v parameter to compute the position on the surface along this curve. The rest of the code sets an array to connect the vertices together (lines 36-45), and pushes the resulting polygon mesh to the list of objects (line 47).

## What's Next?

In the next chapter, we will learn about another technique called fast forward differential to convert a Bézier patch into a grid. Nowadays this technique is not necessary: the conversion steps takes a fraction of the overall time it takes to render the frame. However when computers where slower, it was valuable to speed up this pre-process step.