Graphics Reference
In-Depth Information
When width is a power of two, that is, width = 2 k , it is possible to
perform both the forward and reverse mappings using bitwise operations, since
a mod 2 k = a & ( 2 k
1 )
(15.1)
2 k = a » k
a
/
(15.2)
2 k = a « k ,
a
·
(15.3)
for fixed-point values. Here we use » as the operator to shift the bits of the left
operand to the right by the value of the right operand, and & as the bitwise
AND operator.
This is one reason that many graphics APIs historically required power-
of-two image dimensions (another is MIP mapping). One can always express
a number that is not a power of two as the sum of multiple powers of two.
In fact, that's what binary encoding does! For example, 640 = 512 + 128, so
x + 640 y = x +( y «9 )+( y «7 ) .
Inline Exercise 15.2: Implement forward and backward mappings from
integer ( x , y ) pixel locations to 1D array indices i , for a typical HD resolu-
tion of 1920
×
1080, using only bitwise operations, addition, and subtrac-
tion.
Familiarity with the bit-manipulation methods for mapping between 1D
and 2D arrays is important now so that you can understand other people's code.
It will also help you to appreciate how hardware-accelerated rendering might
implement some low-level operations and why a rendering API might have
certain constraints. However, this kind of micro-optimization will not substan-
tially affect the performance of your renderer at this stage, so it is not yet worth
including.
Our Image class stores physically meaningful values. The natural measure-
ment of the light arriving along a ray is in terms of radiance, whose definition
and precise units are described in Chapter 26. The image typically represents the
light about to fall onto each pixel of a sensor or area of a piece of film. It doesn't
represent the sensor response process.
Displays and image files tend to work with arbitrarily scaled 8-bit display
values that map nonlinearly to radiance. For example, if we set the display pixel
value to 64, the display pixel does not emit twice the radiance that it does when
we set the same pixel to 32. This means that we cannot display our image faithfully
by simply rescaling radiance to display values. In fact, the relationship involves
an exponent commonly called gamma, as described briefly below and at length in
Section 28.12.
Assume some multiplicative factor d that rescales the radiance values in an
image so that the largest value we wish to represent maps to 1.0 and the smallest
maps to 0.0. This fills the role of the camera's shutter and aperture. The user will
select this value as part of the scene definition. Mapping it to a GUI slider is often
a good idea.
Historically, most images stored 8-bit values whose meanings were ill-
specified. Today it is more common to specify what they mean. An image that
 
 
Search WWH ::




Custom Search