Copyright
Game Programming Gems 8
Edited by Adam Lake
Publisher and General Manager,
Course Technology PTR:
Stacy L. Hiquet
Associate Director of Marketing:
Sarah Panella
Manager of Editorial Services:
Heather Talbot
Marketing Manager:
Jordan Castellani
Senior Acquisitions Editor:
Emi Smith
Project and Copy Editor:
Cathleen D. Small
Interior Layout:
Shawn Morningstar
Cover Designer:
Mike Tanamachi
CD-ROM Producer:
Brandon Penticuff
Indexer:
Katherine Stimson
Proofreader:
Heather Urschel
© 2011 Course Technology, a part of Cengage Learning.
ALL RIGHTS RESERVED. No part of this work covered by the copyright herein may be
reproduced, transmitted, stored, or used in any form or by any means graphic, electronic,
or mechanical, including but not limited to photocopying, recording, scanning, digitizing,
taping, Web distribution, information networks, or information storage and retrieval
systems, except as permitted under Section 107 or 108 of the 1976 United States Copyright
Act, without the prior written permission of the publisher.
For product information and technology assistance, contact us at Cengage Learning
Customer & Sales Support, 1-800-354-9706
For permission to use material from this text or product, submit all requests online at
cengage.com/permissions Further permissions questions can be emailed to
For product information and technology assistance, contact us at Cengage Learning
Customer & Sales Support, 1-800-354-9706
permissionrequest@cengage.com
All trademarks are the property of their respective owners.
Cover image used courtesy of Valve Corporation.
All other images © Cengage Learning unless otherwise noted.
Library of Congress Control Number: 2010920327
ISBN-10: 1-58450-702-0
eISBN-10: 1-43545-771-4
Course Technology, a part of Cengage Learning
20 Channel Center Street
Boston, MA 02210
USA
Cengage Learning is a leading provider of customized learning solutions with office locations
around the globe, including Singapore, the U nited Kingdom, Australia, Mexico, Brazil, and
Japan. Locate your local office at: international.cengage.com/region
Cengage Learning products are represented in Canada by Nelson Education, Ltd.
For your lifelong learning solutions, visit courseptr.com
Visit our corporate website at cengage.com
Printed in the United States of America
1 2 3 4 5 6 7 12 1 1 10
Preface
Welcome to the eighth edition of the Game Programming Gems series, started by Mark
DeLoura in 2000. The first edition was inspired by Andrew Glassner‘s popular Graphics
Gems series. Since then, other Gems series have started, including AI Gems and a new
series focused on the capabilities of programmable graphics, the ShaderX series. These
tomes serve as an opportunity to share our experience and best practices with the rest of
the industry.
Many readers think of the Game Programming Gems series as a collection of articles with
sections that target specialists. For me, I‘ve read through them as a way to get exposure to
the diverse subsystems used to create games and stay abreast of the latest techniques. For
example, I may not be a specialist in networking, but reading this section will often
enlighten and stimulate connections that I may not have made between areas in which I
have expertise and ones in which I do not.
One statement I‘ve heard recently regarding our industry is the idea that we now have all
the horsepower we need to create games, so innovations by hardware companies are not
needed. I believe this argument is flawed in many ways. First, there are continued
advancements in graphical realism in academia, in R&D labs, and in the film industry that
have yet to be incorporated into our real-time pipelines. As developers adopt these new
features, computational requirements of software will continue to increase. Second, and the
more important issue, is that this concept of play isn‘t entirely correct—the very notion of
what gaming serves from an anthropological perspective. Play is fundamental, not just to
the human condition, but to the sentient condition. We invent interactive experiences on
any platform, be it a deck of cards, a set of cardboard cutouts, or a next-gen PC platform
with multi-terabyte data and multi-threaded, multi-gigahertz, multi-processor
environments. It‘s as natural as the pursuit of food. This play inspires real-world
applications and pushes the next generation of platform requirements. It enables
affordability of ever-increased computational horsepower in our computing platforms.
The extension of gaming into other arenas, mobile and netbook platforms, serves only to
prove the point. While the same ideas and themes may be used in these environments, the
experience available to the player is different if the designer is to leverage the full
capabilities and differentiating features of the platform.
There is an often-chanted ―ever increasing cost of game development‖ quote for console
and PC platforms. In the same breath, it‘s alluded that this spiral of cost cannot continue. I
believe these issues are of short-term concern. If there is a community willing to play, our
economies will figure out a way to satisfy those needs. This will open up new opportunities
for venture capital and middleware to reduce those platform complexities and cross-industry
development costs, fueling the next generation of interactive experiences. I do believe the
process has changed and will continue to evolve, but game development will continue to
thrive. Will there be 15 first-person military simulations on a single platform? Perhaps not,
but will there continue to be compelling multiplayer and single-player experiences? I believe
so. The ingenuity of the game developer, when brought to the task of leveraging new
incarnations of silicon, will continue to create enriching interactive experiences for ever-
increasing audiences.
Finally, I‘d like to take a moment to address another issue often mentioned in the press. In
November 2009, the Wall Street Journal ran an article by Jonathan V. Last from the Weekly
Standard discussing the social implications of gaming. The majority of his article,
―Videogames—Not Only for the Lonely,‖ was making this observation in the context of a
holiday gathering of family members of many generations sharing experiences with their
Nintendo Wii. Near the end of the article, he refers to the fact that ―the shift to videogames
might be lamenting if it meant that people who would otherwise be playing mini-golf or
Monopoly were sealing themselves off and playing Halo 3 death matches across the
Internet.‖ Much to the contrary, I have personally spent many quality multiplayer hours
interacting socially with longtime friends when playing multiplayer games. A few days ago, I
was having a conversation with an acquaintance who was thrilled that she could maintain
her relationship with her brother on the East Coast by playing World of Warcraft with him.
Ultimately, whether we are discussing our individual game experiences with others or
interacting directly while playing, games do what they have always done across generations
and platforms—they bring us together with shared experiences, whether it be cardboard
cutouts, a deck of cards, or multiplayer capture the flag. Despite the overall informed
message of the article, the writer encouraged a myth I see repeated in the mainstream
press by those out of touch with the multiplayer, socially interactive game experiences that
are common today, including Halo 3.
Overview of Content
The graphics section in this edition covers several topics of recent interest, leveraging new
features of graphics APIs such as Compute Shader, tessellation using DirectX 11, and two
gems on the implementation details of Screen Space Ambient Occlusion (SSAO). In the
physics and animation section, we have selected a number of gems that advance beyond
the basics of the topics such as IK solvers or fluid simulation in general. Instead, these
gems go deeper with improvements to existing published techniques based on real-world
experience with the current state of the art—for example, a simple, fast, and accurate IK
solver, leveraging swarm systems for animation, and modeling air and fluid resistance.
Artificial intelligence, AI, is one of the hottest areas in game development these days. Game
players want worlds that don‘t just look real, but that also feel and act real. The acting part
is the responsibility of the AI programmer. Gems in the AI section are diverse, covering
areas such as decision making, detailed character simulation, and player modeling to solve
the problem of gold farm detection. The innovations discussed are sure to influence future
gems.
In the general programming section, we have a number of tools to help with the
development, performance, and testing of our game engines. We include gems that deal
with multi-threading using Intel‘s Thread Building Blocks, an open-source multithreading
library, memory allocation and profiling, as well as a useful code coverage system used by
the developers at Crytek. The gems in the networking and multiplayer section cover
architecture, security, scalability, and the leveraging of social networking applications to
create multiplayer experiences.
The audio section had fewer submissions than in past years. Why is this? Is the area of
audio lacking in innovation? Has it matured to the point where developers are buying off-
the-shelf components? Regardless, we‘ve assembled a collection of gems for audio that we
think will be of interest. In one of the articles in the audio section, we discuss a relatively
new idea—the notion of real-time calculation of the audio signal based on the actual physics
instead of using the traditional technique of playing a pre-recorded processed sound. As
games become more interactive and physics driven, there will be a corresponding demand
for more realistic sound environments generated by such techniques enabled with the
increasing computational horsepower Moore‘s Law continues to deliver to game developers.
I‘m excited to introduce a new section in this edition of Game Programming Gems 8 that I‘m
calling ―General Purpose Computing on GPUs.‖ This is a new area for the Gems series, and
we wanted to have a real-world case study of a game developer using the GPU for non-
graphics tasks. We‘ve collected three gems for this section. The first is about OpenCL, a
new open standard for programming heterogeneous platforms of today, and we also have
two gems that leverage PhysX for collision detection and fluid simulation. The PhysX
components were used in Batman: Arkham Asylum by Rocksteady Studios Ltd. As the
computing capabilities of the platform evolve, I expect game developers will face the
decision of what to compute, where to compute, and how to manage the data being
operated upon. These articles serve as case studies in what others have done in their
games. I expect this to be an exciting area of future development.
While we all have our areas of specialty, I think it‘s fair to say game developers are a
hungry bunch, with a common desire to learn, develop, and challenge ourselves and our
abilities. These gems are meant to insprire, enlighten, and evolve the industry. As always,
we look forward to the contributions and feedback developers have when putting these
gems into practice.
Adam Lake
Adam_t_lake@yahoo.com
About the Cover Image
© Valve Corporation
The cover of Game Programming Gems 8 features the Engineer from Valve‘s Team Fortress
2. With their follow-up to the original class-based multiplayer shooter Team Fortress, Valve
chose to depart from the typical photorealistic military themes of the genre. Instead, they
employed an ―illustrative‖ non-photorealistic rendering style, reminiscent of American
commercial illustrators of the 1920s. This was motivated by the need for players to be able
to quickly visually identify each other‘s team, class, and weapon choices in the game. The
novel art style and rendering techniques of Team Fortress 2 allowed Valve‘s designers to
visually separate the character classes from each other and from the game‘s environments
through the use of strong silhouettes and strategic distribution of color value.
CD-ROM Downloads
If you purchased an ebook version of this book, and the book had a companion CD-ROM, we
will mail you a copy of the disc. Please send ptrsupplements@cengage.com the title of the
book, the ISBN, your name, address, and phone number. Thank you.
Acknowledgments
I‘d like to take a moment to acknowledge the section editors that I worked with to create
this tome. They are the best and brightest in the industry. The quality of submissions and
content in this book is a testament to this fact. They worked incredibly hard to bring this
book together, and I thank them for their time and expertise. Also, I appreciate the time
and patience that Emi Smith and Cathleen Small at Cengage Learning have put into this
first-time book editor. They were essential in taking care of all the details necessary for
publication. Finally, I‘d like to acknowledge the artists at Valve who provided the cover
image for this edition of Game Programming Gems.
I have been blessed to have had exposure to numerous inspirational individuals— friends
who refused to accept norms, parents who satiated my educational desires, teachers willing
to spend a few extra minutes on a random tangent, instructors to teach not just what we
know about the world, but also to make me aware of the things we do not. Most
importantly, I want to acknowledge my wife, Stacey Lake, who remained supportive while I
toiled away in the evenings and weekends for the better part of a year on this book.
I dedicate these efforts to my mother, Amanda Lake. I thank her for teaching me that
education is an enjoyable lifelong endeavor.