Graphics Reference
In-Depth Information
be seen in Figure 38.3, most pipeline stages have access to a generalized memory
system, in addition to the data arriving from the previous stage. In this section we
consider both the opportunities and the performance challenges of such memory
access, using texture mapping as an archetypal example.
38.6.1 Texture Mapping
Recall from Chapter 20 that texture mapping maps image data onto a primitive.
In the graphics pipeline this is implemented in two steps: correspondence and
evaluation .
Correspondence specifies a mapping from the geometric coordinates of the
primitive to the image-space coordinates of the texture image. In the modern
graphics pipeline (see Figure 38.3) correspondence is specified by assigning tex-
ture image coordinates to the vertices of primitives. The assignment may be done
directly by the application, using interfaces such as OpenGL's TexCoord * com-
mands, or indirectly through calculations specified by the vertex shader (i.e., the
application-specified program executing on the vertex processing pipeline stage
can generate texture coordinates, or modify application-specified texture coor-
dinates). To determine the correspondence at sample locations within individual
pixel fragments, the texture coordinates specified at vertices are linearly interpo-
lated to the sample's corresponding position within the primitive. Texture coor-
dinate interpolation to the centers of pixel fragments is implemented as a part of
the rasterization process in the fragment generation pipeline stage. Because inter-
polation is to be linear in the primitive's coordinates, but it is implemented in the
warped, post-projection coordinates of the framebuffer, the mathematics require a
high-precision division for each correspondence calculation (typically, one divi-
sion for each pixel fragment that is generated by rasterization). While this divi-
sion is inexpensive to implement in modern GPUs, it was a nearly insurmountable
burden prior to the '80s, and it is a significant reason why texture mapping was
available only in expensive, specialized graphics systems such as flight training
simulators prior to that.
Evaluation is also an interpolation. But unlike the interpolation of texture
coordinates, which involves accessing only the few coordinates assigned to the
vertices of a primitive, evaluation accesses multiple pixels (called texels ) within a
texture image. And texture images can be very large—Direct3D 10 implementa-
tions must support 4,096
4,096-texel images, which require a minimum of 8 mil-
lion bytes of storage. Thus, large-memory access, which is typically not required
for texture correspondence, is fundamental to texture evaluation.
Images are equivalent to 2D tables of colors, and table-driven interpolation—
constructing new data points within a regularly spaced range of discrete data
points by computing a weighted average of nearby data points—is a fundamental
mathematical operation that is available in many nongraphical systems. The heav-
ily used interp1 , interp2 , and interp3 commands in MATLAB are good exam-
ples: They construct new points within ranges specified as 1D, 2D, or 3D arrays.
Texture image interpolation has always been a part of OpenGL and Direct3D,
but prior to application programmability it was hidden within their fixed-function
texture-mapping mechanisms.
Now, like MATLAB, both the Direct3D and OpenGL shading languages
expose 1D, 2D, and 3D versions of table interpolation, which operate on 1D,
2D, and 3D texture images. Critically, these image-interpolation functions accept
×
 
Search WWH ::




Custom Search