
IntroductionDirectX 8 Graphics introduced programmable vertex shaders, which allows the vertex processing of Direct3D to be replaced by application specific code. This code, known as a vertex shader, performs the transformation and lighting of vertices, determining their final position, color parameters, and texture coordinates. In this article, we will examine a novel method for rendering landscapes, which uses a vertex shader to perform realtime modeling of bicubic patches in the 3D pipeline. CatmullRom SplinesSplines are a mathematical means of representing a curve, by specifying a series of points at intervals along the curve and defining a function that allows additional points within an interval to be calculated. There are various functions available to approximate a curve, but in this article we will focus on the CatmullRom spline. The points that define the curve are known as "Control Points". One of the features of the CatmullRom spline is that the specified curve will pass through all of the control points  this is not true of all types of splines.
Given the control points P_{0}, P_{1}, P_{2}, and P_{3}, and the value t, the location of the point can be calculated as (assuming uniform spacing of control points):
This formula gives CatmullRom spline the following characteristics:
While a spline segment is defined using four control points, a spline may have any number of additional control points. This results in a continuous chain of segments, each defined by the two control points that form the endpoints of the segments, plus an additional control point on either side of the endpoints. Thus for a given segment with endpoints Pn and Pn+1, the segment would be calculated using [P_{n1}, P_{n}, P_{n+1}, P_{n+2}]. Because a segment requires control points to the outside of the segment endpoints, the segments at the extreme ends of the spline cannot be calculated. Thus, for a spline with control points 1 through N, the minimum segment that can be formulated is P_{2}<>P_{3}, and the maximum segment is P_{N2}<>P_{N1}. Thus, to define S segments, S+3 control points are required. Surface Representation with Splines
To express this algebraically, given function f(t,P_{A},P_{B},P_{C},P_{D}) which calculates a point in a spline segment, then the calculation of a point (u,v) on a surface from control points P_{1}...P_{16} would be: f( v, f(u,P_{1},P_{2},P_{3},P_{4}), f(u,P_{5},P_{6},P_{7},P_{8}), f(u,P_{9},P_{10},P_{11},P_{12}),
f(u,P_{13},P_{14},P_{15},P_{16}) ) Figure 5, below, illustrates the complete flow of data that occurs when calculating a point in a patch.
The processing cost of that operation is quite high to be performed every frame  even given the simplified form presented in Equation 2, the operation would require around 330 floating point operations for each generated 3D vertex. Because of this, landscape meshes are typically created at load time. In a large scene, memory footprint can become an issue, so it is may be necessary to store a local area and regenerate portions of a landscape on the fly as the viewer moves into them. Doing so while maintaining a steady frame rate can require a bit of finesses, so as not to suffer periodic frame rate drops due to processing overhead.
Downloadable demo for this article 
Visitors Since 1/1/2000:
