• No results found

Antialiasing Lines

In document SRC TN 1998 013 pdf (Page 71-73)

6 High-Quality Rendering Techniques

6.2 High-Quality Interactive Graphics

6.2.2 Antialiasing Lines

The constraints in rendering line segments differ from those in rendering polygons in that line segments do not represent filled areas, although they are modeled as such. Polygons have well defined borders, and those borders must be respected by rendering algorithms, especially where polygons abut. Line segments do not have well defined borders, and the concept of abutting line segments does not exist. This extra degree of freedom motivates a higher-performance antialiasing algorithm specific to line segments.

To draw an aliased line segment of color C, each of the pixels identified as on the line should be given the value C. If the line segment is smooth shaded (depth cued) from color C1 at vertex P1 to color C2 at vertex P2, then the color values should be linearly interpolated between the two endpoints. Whether smooth shaded or not, aliasing artifacts will be apparent.

The following procedure will lessen these artifacts. The first step is to construct two polygons that share the line segment P1P2 as a common edge. The polygons are described by the vertex lists (P1,P2,P4,P3) and (P1,P2,P6,P5) as shown in figure 6-1. P3, P4, P5, and P6 are offset par- allel to the y axis for x-major line segments and parallel to the x axis for y-major line segments. The distances from P1 to P3, from P1 to P5, from P2 to P4, and from P2 to P6 are the same. The distance is arbitrarily assigned a value of two pixels in the example; however, experimenta- tion will show what values give pleasing results.

Figure 6-1 An antialiased line from P1 to P2 is constructed of two polygons with vertex lists (P1,P2,P4,P3) and (P1,P2,P6,P5). P1 has color C1. P2 has color C2.

The two polygons can be scan-converted independently. Let’s look at the scan-conversion of polygon (P1,P2,P4,P3). Polygon (P1,P2,P6,P5) is its mirror image. As the polygon is scan- converted, the selection of color values for the interior pixels is done in three steps. The first step is to linearly interpolate color values from C1 at P1 and P3 to C2 at P2 and P4. The second step is to linearly interpolate a value, referred to as α, from 1.0 at P1 and P2 to 0.0 at P3 and P4. The final step is to multiply the interpolated color value by the interpolated α value at each

P3 P1,C1 P5 P4 P2,C2 P6

pixel to arrive at the new color value for the pixel. This new color value should be merged into graphics memory as described later. Figure 6-2 shows some α values of the polygons of figure 6-1.

Figure 6-2 α values of figure 6-1. Vertex values are shown as well as select internal values, calculated in the upper left corners of pixels.

The algorithm’s performance can be increased by scan converting the two polygons as a single polygon described by the vertex list (P3,P4,P6,P5). In fact, a wide line from P1 to P2 of width four pixels can conveniently model this polygon. Scan converting polygon (P3,P4,P6,P5) re- quires the same three steps as before: interpolating color values, interpolating α values, and multiplying the color values by the α values. Of the three steps, interpolation of α values is the most difficult, as α must vary from 0.0 along the edge P3P4 to 1.0 in the center along P1P2 and back to 0.0 along the edge P5P6. This is not a linear interpolation.

Fortunately, there is a clever trick for interpolating the α values. Assuming a fixed point inter- nal data representation for α, this can be accomplished by using an extra bit in the interpolator’s data path, and linearly interpolating from 0.0 along P3P4 to 2.0 along P5P6. Whenever a pixel’s α value is between 1.0 and 2.0, it is replaced by (2.0 - α). This effect is approximated by XORing each bit in the fixed point representation for α with the high-order (extra) bit of that representation, and occurs automatically in the PixelVision rendering subsystem when an 8-bit plane equation value (α in this case) exceeds its 8-bit range.

The description above presents a method for generating the color values for pixels included on an antialiased line segment. Once those color values have been computed, they must be com- bined with the values in graphics memory in such a way that overlapping line segments do not cause objectionable patterns. In general, the brightest of two overlapping line segments should persist, regardless of the order in which they are drawn. Straightforwardly copying the new color values into graphics memory will not suffice, as darker areas at the edges of a new line segment will persist over brighter areas of a previous line segment.

There are many possible methods for combining pixel values. We will outline one here which α=0.0 α=0.0 α=1.0 α=0.0 α=0.0 α=1.0 .3 .1 .6 .9 .4 .1 .4 .1

yields good quality and reasonable performance. The task of choosing the brightest of two overlapping line segments can be viewed as essentially a hidden surface problem, except in- stead of qualifying the graphics memory update with a depth comparison, it is qualified with a luminance comparison. In addition to interpolating color values and α values, the algorithm interpolates luminance values, which are computed from the color values at the endpoints. Just as a pixel’s color value is the interpolated color value times the interpolated α value, its lumi- nance value is the interpolated luminance value times the interpolated α value.

In document SRC TN 1998 013 pdf (Page 71-73)

Related documents