i
i
i
i
i
i
i
i
18.3. Processing Geometry into Pixels 465
strung together to form the overall computation. The rst kernel completes the
rst part of the computation, the second kernel works on the rst kernel’s data,
and so on, until the calculation is complete. In this style of programming, working
with data and data structures on the GPU is different than conventional program-
ming and does require a bit of thought. Fortunately, recent efforts are providing
abstractions and information for creating efcient data structures for GPU pro-
gramming (A. Lefohn et al., 2005).
Using the GPU for general purpose programming does require that you un-
derstand how to program the graphics hardware. For instance, most applications
that perform GPGPU will render a simple quadrilateral, or sets of quadrilater-
als, with vertex and fragment shaders operating on that geometry. The geometry
doesn’t have to be visible, or drawn to the screen, but it is necessary to allow
the vertex and fragment operations to occur. This focus on graphics does make
the learning curve for general purpose computing on this hardware an adventure.
Fortunately, recent efforts are working to make the interface to the GPU more like
traditional programming. The Brook for GPUs project (Buck et al., n.d.) is a sys-
tem that provides a C-like interface to afford stream computations on the GPU,
which should allow more people to take advantage of the computational power on
modern graphics hardware.
Frequently Asked Questions
How do I debug shader programs?
On most platforms, debugging both vertex shaders and fragment shaders is not
simple. There is very little runtime support for debugging graphics applications
in general, and even less available for runtime debugging of shader programs.
However, this is starting to change. In the latest versions of Mac OS X, Linux,
and Windows, support for shader programming is incorporated. A good solution
for debugging shader programs is to use one of the shader development tools
available from various graphics hardware manufacturers.
Notes
There are many good resources available to learn more about the technical de-
tails involved with programming graphics hardware. A good starting point might
be the OpenGL
TM
Programming Guide (Shreiner et al., 2004). The OpenGL
TM
Shading Language (Rost, 2004) and The Cg Tutorial (Fernando & Killgard, 2003)
i
i
i
i
i
i
i
i
466 18. Using Graphics Hardware
provide details on how to program using a shading language. More advanced
technical information and examples for programming the vertex and fragment
processors can be found in the GPU Gems series of books
(Fernando, 2004; Pharr & Fernando, 2005). A source of information for learning
more about general purpose computation on GPUs (GPGPU) can be found on the
GPGPU.org web site (http://www.gpgpu.org).
Exercises
1. How fast is the GPU as compared to performing the operations on the CPU?
Write a program in which you can parameterizehow much data is processed
on the GPU, ranging from no computation using a shader program to all
of the computation being performed using a shader program. How does
the performance of you application change when the computation is being
performed solely on the GPU?
2. Are there sizes of triangle strip lengths that work better than others? Try
to determine the maximum size of a triangle strip that maximizes perfor-
mance. What does this tell you about the memory, or cache structure, on
the graphics hardware?
i
i
i
i
i
i
i
i
Plate XXVIII. The spectrum locus for the CIE 1931 standard
observer. (See also Figure 21.6).
Plate XXIX. The chromaticity boundaries of the CIE RGB
primaries at 435.8, 546.1, and 700 nm (solid) and a typical
HDTV (dashed). (See also Figure 21.7.)
u'
v'
v'
u'
0.5
0.70.60.50.40.30.20.10.0
0.0
0.1
0.2
0.3
0.4
Plate XXX. The CIE u
v
chromaticity diagram. (See also
Figure 21.8.)
Plate XXXI. A series of light sources plotted in the CIE
u
v
chromaticity diagram. A white piece of paper illuminated by
any of these light sources maintains a white color appear-
ance. (See also Figure 21.11.)
400 450 500 550 600 650 700
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
Wavelength (nm)
Sensitivity
Color representing
CIE A rendered into
the sRGB color space
L
M
S
CIE A
Solid lines: relative cone responses
Dashed lines: relative adapted cone responses
Plate XXXII. An exam-
ple of von Kries–style inde-
pendent photoreceptor gain
control. The relative cone
responses (solid line) and
the relative adapted cone
responses to CIE illumi-
nant A (dashed) are shown.
The separate patch of color
represents CIE illuminant
A rendered into the sRGB
color space. (See also Fig-
ure 21.12.)
i
i
i
i
i
i
i
i
Plate XXXIII.
Crysis
exem-
plifies the realistic and de-
tailed graphics expected of
first-person shooters.
Im-
age courtesy Crytek.
(See
also Figure 26.2.)
Plate XXXIV. An example
of highly stylized, non-
photorealistic rendering
from the game
Okami
.
Image courtesy Capcom
Entertainment, Inc.
(See
also Figure 26.3.)
i
i
i
i
i
i
i
i
Plate XXXV. The
LittleBig-
Planet
developers took care
to choose techniques that
fit the game’s constraints,
combining them in unusual
ways to achieve stunning
results.
LittleBigPlanet
c
2007 Sony Computer En-
tertainment Europe. De-
veloped by Media Molecule.
LittleBigPlanet is a trade-
mark of Sony Computer En-
tertainment Europe.
(See
also Figure 26.4.)
Plate XXXVI. The normal
map used in Figure 26.8. In
this image, the red, green
and blue channels of the
texture contain the X, Y, and
Z coordinates of the surface
normals.
Image courtesy
Keith Bruns.
(See also Fig-
ure 26.9.)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.102.34