Graphics Reference
In-Depth Information
of 0, it is common to map the two lowest bit patterns to
1, thus sliding the
number line slightly and making
1, 0, and 1 all exactly representable.
Normalized values are particularly important in computer graphics because
we frequently need to represent unit vectors, dot products of unit vectors, and
fractional reflectivities using compact storage.
A terse naming convention is desirable for expressing numeric types in a
graphics program because there are frequently so many variations. One common
convention for fixed point decorates int ,or fix with prefixes and suffixes. In this
convention, the prefix u denotes unsigned, the prefix n denotes normalized, and
the suffix denotes the bit allocations using an underscore instead of a period. For
example, uint8 is an 8-bit unsigned fixed-point number with range [0, 255] and
ufix5_3 is an unsigned fixed-point number with 5 integer bits and 3 fractional bits
on the range [0, 2 5
2 3 ] = [0, 31.875]. An even more terse variation of this in
OpenGL is the use of I to represent non-normalized fixed point and an assump-
tion of unsigned normalized representation. For example, GL_R8 indicates an 8-bit
normalized value ( unint8 ) on the range [0, 1] and GL_RI8 indicates an integer on
the range [0, 255].
Some common fixed-point formats currently in use in hardware graphics are
unsigned normalized 8-bit for reflectivity, normalized 8-bit for unit vectors, and
24.8 fixed point for 2D positions during rasterization. Fixed-point is infrequently
used in modern software rendering. CPUs are not very efficient for most opera-
tions on fixed-point formats and software rendering today tends to focus on qual-
ity more than performance, so one less frequently seeks minimal data formats
if they are inconvenient. The exception is software rasterization —24.8 format is
used in hardware, not for performance but because fixed-point arithmetic is exact:
a + b
b = a (so long as the intermediate results do not overflow), which is not
the case for most floating-point a and b .
14.3.2 Floating Point
Floating-point representations allow the location of the decimal point to move—in
some cases, far beyond the number of digits. Although the details of the commonly
used IEEE 754 floating-point representations are slightly more complicated than
scientific notation, the key ideas are similar. A number can be represented as a
mantissa and an exponent; for example, a
10 b can be encoded by concatenating
the bits of a and b , which are themselves integer or fixed-point numbers. In prac-
tice, the IEEE 754 representations allow explicit representation of concepts like
“not a number” (e.g., 0
×
0) and positive and negative infinity. These could be, but
rarely are, represented as specific bit patterns in fixed point. Floating point offers
increased range or precision over fixed point at the same bit count; the catch is that
it rarely offers both at the same time. The magnitude of the error in the approxi-
mation of a real number depends on the specific number; it tends to be larger for
larger-magnitude numbers (see Figures 14.3, 14.4). This makes it complicated to
bound the error in algorithms that use this representation. Floating point also tends
to require more complicated circuits to implement.
Both 32-bit and 64-bit floating-point numbers (sometimes called single-
and double-precision) are common across all application domains. The 32-bit
float is often preferred in graphics for space and time efficiency. Graphics also
employs other floating-point sizes that are less common in other areas, such as
16-bit “half” precision and some very special-purpose sizes like 10-bit floating
/
 
 
Search WWH ::




Custom Search