{0}------------------------------------------------
Fundamentals of Computer Graphics FIFTH F D T N
Steve Marschner Peter Shirley
with
Michael Ashikhmin Michael Gleicher Naty Hoffman Garrett Johnson Tamara Munzner Erik Reinhard William B. Thompson Peter Willemsen Brian Wyvill
Image /page/0/Picture/4 description: The image shows the logo for CRC Press, a Taylor & Francis Group company, and the words "AN A K PETERS BOOK".
{1}------------------------------------------------
FIFTH EDITION
{2}------------------------------------------------
Image /page/2/Picture/0 description: The image shows the logo for Taylor & Francis. The logo consists of a circle containing a stylized image of a lamp, followed by the text "Taylor & Francis" in a large font, "Taylor & Francis Group" in a smaller font, and "http://taylorandfrancis.com" in an even smaller font.
{3}------------------------------------------------
E.
NVIDIA
Peter Shirley
DITION
Steve Marschner
Cornell University
F
with Michael Ashikhmin, Gro Intelligence Michael Gleicher, University of Wisconsin Naty Hoffman, Lucasfilm Garrett Johnson, Rochester Institute of Technology Tamara Munzner, University of British Columbia Erik Reinhard, InterDigital, Inc. William B. Thompson, University of Utah Peter Willemsen, University of Minnesota Duluth Brian Wyvill, SceneWizard Software Ltd.
Image /page/3/Picture/4 description: The image shows the logo for CRC Press, a Taylor & Francis Group. The logo consists of the letters "CRC" in a circle, followed by the words "CRC Press" on the top line, "Taylor & Francis Group" on the second line, and "Boca Raton London New York" on the third line.
CRC Press is an imprint of the Taylor & Francis Group, an informa business AN A K PETERS BOOK
{4}------------------------------------------------
Fifth edition published 2022 by CRC Press 6000 Broken Sound Parkway NW, Suite 300, Boca Raton, FL 33487-2742
and by CRC Press 2 Park Square, Milton Park, Abingdon, Oxon, OX14 4RN
© 2022 Taylor & Francis Group, LLC
CRC Press is an imprint of Taylor & Francis Group, LLC
Reasonable efforts have been made to publish reliable data and information, but the author and publisher cannot assume responsibility for the validity of all materials or the consequences of their use. The authors and publishers have attempted to trace the copyright holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this form has not been obtained. If any copyright material has not been acknowledged please write and let us know so we may rectify in any future reprint.
Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying, microfilming, and recording, or in any information storage or retrieval system, without written permission from the publishers.
For permission to photocopy or use material electronically from this work, access www.copyright.com or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. For works that are not available on CCC please contact mpkbookspermissions@tandf.co.uk
Trademark notice: Product or corporate names may be trademarks or registered trademarks and are used only for identification and explanation without intent to infringe.
Library of Congress Cataloging-in-Publication Data Names: Marschner, Steve, author. | Shirley, Peter, author. Title: Fundamentals of computer graphics / Steve Marschner, Peter Shirley. Description: 5th edition. | Boca Raton: CRC Press, 2021. | Includes bibliographical references and index. Identifiers: LCCN 2021008492 | ISBN 9780367505035 (hardback) | ISBN 9781003050339 (ebook) Subjects: LCSH: Computer graphics. Classification: LCC T385 .M36475 2021 | DDC 006.6—dc23 LC record available at https://lccn.loc.gov/2021008492
ISBN: 978-0-367-50503-5 (bbk) ISBN: 978-0-367-50558-5 (pbk) ISBN: 978-1-003-05033-9 (ebk)
Typeset in Times by codeMantra
{5}------------------------------------------------
Contents
| Preface | | xi |
|---|
| Acknowledgments | | xiii |
| Authors | | xv |
| <b>1</b> Introduction | | 1 |
| 1.1 Graphics Areas | | 2 |
| 1.2 Major Applications | | 3 |
| 1.3 Graphics APIs | | 4 |
| 1.4 Graphics Pipeline | | 4 |
| 1.5 Numerical Issues | | 5 |
| 1.6 Efficiency | | 7 |
| 1.7 Designing and Coding Graphics Programs | | 8 |
{6}------------------------------------------------
| 4 | | <b>Ray Tracing</b> | 79 |
|---|
| 4.1 | The Basic Ray-Tracing Algorithm | 80 |
| 4.2 | Perspective | 81 |
| 4.3 | Computing Viewing Rays | 82 |
| 4.4 | Ray-Object Intersection | 86 |
| 4.5 | Shading | 91 |
| 4.6 | Historical Notes | 95 |
| 5 | | Surface Shading | 97 |
| 5.1 | Point-like light sources |
vi
{7}------------------------------------------------
| 10.4 | Signal Processing for Images | 230 |
|---|
| 10.5 | Sampling Theory | 239 |
| <b>11</b> | <b>Texture Mapping</b> | <b>255</b> |
| 11.1 | Looking Up Texture Values | 256 |
| 11.2 | Texture Coordinate Functions | 258 |
| 11.3 | Antialiasing Texture Lookups | 269 |
| 11.4 | Applications of Texture Mapping | 277 |
| 11.5 | Procedural 3D Textures | 283 |
| <b>12</b> | <b>Data Structures for Graphics</b> | <b>291</b> |
| 12.1 | Triangle Meshes | 292 |
| 12.2 |
vii
{8}------------------------------------------------
| <b>16 Computer Animation</b> | 429 |
|---|
| Michael Ashikhmin | |
| 16.1 | Principles of Animation …………………… | 430 |
| 16.2 | Keyframing ……………………………… | 434 |
| 16.3 | Deformations |
{9}------------------------------------------------
Contents
ix
{10}------------------------------------------------
Contents
| 23.2 | Data Types | | | | | | | | 648 |
|---|
| 23.3 | Human-Centered Design Process | | | | | | | | 650 |
| 23.4 | Visual Encoding Principles | | | | | | | | 652 |
| 23.5 | Interaction Principles | | | | | | | | 660 |
|
{11}------------------------------------------------
Preface
This edition of Fundamentals of Computer Graphics includes substantial rewrites of the material on shading, light reflection, and path tracing, as well as many corrections throughout. This book now provides a better introduction to the techniques that go by the names of physics-based materials and physics-based rendering and are becoming predominant in actual practice. This material is now better integrated, and we think this book maps well to the way many instructors are organizing graphics courses at present.
The organization of this book remains substantially similar to the fourth edition. As we have revised this book over the years, we have endeavored to retain the informal, intuitive style of presentation that characterizes the earlier editions, while at the same time improving consistency, precision, and completeness. We hope the reader will find the result is an appealing platform for a variety of courses in computer graphics.
About the Cover
The cover image is from Tiger in the Water by J. W. Baker (brushed and airbrushed acrylic on canvas, 16" by 20", www.jwbart.com).
The subject of a tiger is a reference to a wonderful talk given by Alain Fournier (1943–2000) at a workshop at Cornell University in 1998. His talk was an evocative verbal description of the movements of a tiger. He summarized his point:
Even though modelling and rendering in computer graphics have been improved tremendously in the past 35 years, we are still not at the point where we can model automatically a tiger swimming in the river in all its glorious details. By automatically I mean in a way that does not need careful manual tweaking by an artist/expert.
The bad news is that we have still a long way to go.
The good news is that we have still a long way to go.
{12}------------------------------------------------
Online Resources
The website for this book is http://www.cs.cornell.edu/~srm/fcg5/. We will continue to maintain a list of errata and links to courses that use the book, as well as teaching materials that match the book's style. Most of the figures in this book are in Adobe Illustrator format, and we would be happy to convert specific figures into portable formats on request. Please feel free to contact us at srm@cs.cornell.edu or ptrshrl@gmail.com.
{13}------------------------------------------------
Acknowledgments
The following people have provided helpful information, comments, or feedback about the various editions of this book: Ahmet Oğuz Akyüz, Josh Andersen, Beatriz Trinchão Andrade Zeferino Andrade, Bagossy Attila, Kavita Bala, Mick Beaver, Robert Belleman, Adam Berger, Adeel Bhutta, Solomon Boulos, Stephen Chenney, Michael Coblenz, Greg Coombe, Frederic Cremer, Brian Curtin, Dave Edwards, Jonathon Evans, Karen Feinauer, Claude Fuhrer, Yotam Gingold, Amy Gooch, Eungyoung Han, Chuck Hansen, Andy Hanson, Razen Al Harbi, Dave Hart, John Hart, Yong Huang, John "Spike" Hughes, Helen Hu, Vicki Interrante, Wenzel Jakob, Doug James, Henrik Wann Jensen, Shi Jin, Mark Johnson, Ray Jones, Revant Kapoor, Kristin Kerr, Erum Arif Khan, Mark Kilgard, Fangjun Kuang, Dylan Lacewell, Mathias Lang, Philippe Laval, Joshua Levine, Marc Levoy, Howard Lo, Joann Luu, Mauricio Maurer, Andrew Medlin, Ron Metoyer, Keith Morley, Eric Mortensen, Koji Nakamaru, Micah Neilson, Blake Nelson, Michael Nikelsky, James O'Brien, Hongshu Pan , Steve Parker, Sumanta Pattanaik, Matt Pharr, Ken Phillis Jr, Nicolò Pinciroli, Peter Poulos, Shaun Ramsey, Rich Riesenfeld, Nate Robins, Nan Schaller, Chris Schryvers, Tom Sederberg, Richard Sharp, Sarah Shirley, Peter-Pike Sloan, Hannah Story, Tony Tahbaz, Jan-Phillip Tiesel, Bruce Walter, Alex Williams, Amy Williams, Chris Wyman, Kate Zebrose, and Angela Zhang.
Ching-Kuang Shene and David Solomon allowed us to borrow their examples. Henrik Wann Jensen, Eric Levin, Matt Pharr, and Jason Waltman generously provided images. Brandon Mansfield helped improve the discussion of hierarchical bounding volumes for ray tracing. Philip Greenspun (philip.greenspun.com) kindly allowed us to use his photographs. John "Spike" Hughes helped improve the discussion of sampling theory. Wenzel Jakob's Mitsuba renderer was invaluable in creating many figures. We are extremely thankful to J. W. Baker for helping create the cover Pete envisioned. In addition to being a talented artist, he was a great pleasure to work with personally.
Many works that were helpful in preparing this book are cited in the chapter notes. However, a few key texts that influenced the content and presentation deserve special recognition here. These include the two classic computer graphics texts from which we both learned the basics: Computer Graphics: Principles & Practice (Foley, Van Dam, Feiner, & Hughes, 1990) and Computer Graphics (Hearn & Baker, 1986). Other texts include both of Alan Watt's influential books (Watt, 1993, 1991), Hill's Computer Graphics Using OpenGL (Francis
{14}------------------------------------------------
S. Hill, 2000), Angel's Interactive Computer Graphics: A Top-Down Approach Using OpenGL (Angel, 2002), Hugues Hoppe's University of Washington dissertation (Hoppe, 1994), and Rogers' two excellent graphics texts (Rogers, 1985, 1989).
We would like to especially thank Alice and Klaus Peters for encouraging Pete to write the first edition of this book and for their great skill in bringing a book to fruition. Their patience with the authors and their dedication to making their books the best they can be has been instrumental in making this book what it is. This book certainly would not exist without their extraordinary efforts.
Steve Marschner, Ithaca, NY Peter Shirley, Salt Lake City, UT February 2021
{15}------------------------------------------------
Authors
Steve Marschner is a Professor of Computer Science at Cornell University. He obtained his Sc.B. from Brown University in 1993 and his Ph.D. from Cornell in 1998. He held research positions at Microsoft Research and Stanford University before joining Cornell in 2002. He is recipient of the SIGGRAPH Computer Graphics Achievement Award in 2015 and co-recipient of a 2003 Technical Academy Award.
Peter Shirley is a Distinguished Research Scientist at NVIDIA. He held academic positions at Indiana University, Cornell University, and the University of Utah. He obtained a B.A. in Physics from Reed College in 1985 and a Ph.D. in Computer Science from University of Illinois in 1991.
{16}------------------------------------------------
Image /page/16/Picture/0 description: The image shows the logo for Taylor & Francis. The logo consists of a circle containing a stylized image of a lamp, followed by the text "Taylor & Francis" in a large font, "Taylor & Francis Group" in a smaller font, and "http://taylorandfrancis.com" in an even smaller font.
{17}------------------------------------------------
Introduction
The term computer graphics describes any use of computers to create and manipulate images. This book introduces the algorithmic and mathematical tools that can be used to create all kinds of images—realistic visual effects, informative technical illustrations, or beautiful computer animations. Graphics can be two- or three-dimensional; images can be completely synthetic or can be produced by manipulating photographs. This book is about the fundamental algorithms and mathematics, especially those used to produce synthetic images of three-dimensional objects and scenes.
Actually doing computer graphics inevitably requires knowing about specific hardware, file formats, and usually a graphics API (see Section 1.3) or two. Computer graphics is a rapidly evolving field, so the specifics of that knowledge are a moving target. Therefore, in this book we do our best to avoid depending on any specific hardware or API. Readers are encouraged to supplement the text with relevant documentation for their software and hardware environment. Fortunately, the culture of computer graphics has enough standard terminology and concepts that the discussion in this book should map nicely to most environments.
This chapter defines some basic terminology and provides some historical background, as well as information sources related to computer graphics.
API: application program interface.
{18}------------------------------------------------
Graphics Areas 1.1
Imposing categories on any field is dangerous, but most graphics practitioners would agree on the following major areas of computer graphics:
- Modeling deals with the mathematical specification of shape and appearance properties in a way that can be stored on the computer. For example, a coffee mug might be described as a set of ordered 3D points along with some interpolation rule to connect the points and a reflection model that describes how light interacts with the mug.
- Rendering is a term inherited from art and deals with the creation of shaded images from 3D computer models.
- Animation is a technique to create an illusion of motion through sequences of images. Animation uses modeling and rendering but adds the key issue of movement over time, which is not usually dealt with in basic modeling and rendering.
There are many other areas that involve computer graphics, and whether they are core graphics areas is a matter of opinion. These will all be at least touched on in the text. Such related areas include the following:
- User interaction deals with the interface between input devices such as mice and tablets, the application, feedback to the user in imagery, and other sensory feedback. Historically, this area is associated with graphics largely because graphics researchers had some of the earliest access to the input/output devices that are now ubiquitous.
- Virtual reality attempts to immerse the user into a 3D virtual world. This typically requires at least stereo graphics and response to head motion. For true virtual reality, sound and force feedback should be provided as well. Because this area requires advanced 3D graphics and advanced display technology, it is often closely associated with graphics.
- Visualization attempts to give users insight into complex information via visual display. Often, there are graphic issues to be addressed in a visualization problem.
- Image processing deals with the manipulation of 2D images and is used in both the fields of graphics and vision.
- Three-dimensional scanning uses range-finding technology to create measured 3D models. Such models are useful for creating rich visual imagery, and the processing of such models often requires graphics algorithms.
{19}------------------------------------------------
1.2. Maior Applications
Computational photography is the use of computer graphics, computer vision, and image processing methods to enable new ways of photographically capturing objects, scenes, and environments.
1.2 Major Applications
Almost any endeavor can make some use of computer graphics, but the major consumers of computer graphics technology include the following industries:
- Video games increasingly use sophisticated 3D models and rendering algorithms
- Cartoons are often rendered directly from 3D models. Many traditional 2D cartoons use backgrounds rendered from 3D models, which allow a continuously moving viewpoint without huge amounts of artist time.
- Visual effects use almost all types of computer graphics technology. Almost every modern film uses digital compositing to superimpose backgrounds with separately filmed foregrounds. Many films also use 3D modeling and animation to create synthetic environments, objects, and even characters that most viewers will never suspect are not real.
- Animated films use many of the same techniques that are used for visual effects, but without necessarily aiming for images that look real.
- CAD/CAM stands for computer-aided design and computer-aided manufac turing. These fields use computer technology to design parts and products on the computer and then, using these virtual designs, to guide the manufacturing process. For example, many mechanical parts are designed in a 3D computer modeling package and then automatically produced on a computer-controlled milling device.
- Simulation can be thought of as accurate video gaming. For example, a flight simulator uses sophisticated 3D graphics to simulate the experience of flying an airplane. Such simulations can be extremely useful for initial training in safety-critical domains such as driving, and for scenario training for experienced users such as specific fire-fighting situations that are too costly or dangerous to create physically.
- Medical imaging creates meaningful images of scanned patient data. For example, a computed tomography (CT) dataset is composed of a large 3D
1
{20}------------------------------------------------
rectangular array of density values. Computer graphics is used to create shaded images that help doctors extract the most salient information from such data.
Information visualization creates images of data that do not necessarily have a "natural" visual depiction. For example, the temporal trend of the price of ten different stocks does not have an obvious visual depiction, but clever graphing techniques can help humans see the patterns in such data.
Graphics APIs 1.3
A key part of using graphics libraries is dealing with a graphics API. An application program interface (API) is a standard collection of functions to perform a set of related operations, and a graphics API is a set of functions that perform basic operations such as drawing images and 3D surfaces into windows on the screen.
Every graphics program needs to be able to use two related APIs: a graphics API for visual output and a user-interface API to get input from the user. There are currently two dominant paradigms for graphics and user-interface APIs. The first is the integrated approach, exemplified by Java, where the graphics and userinterface toolkits are integrated and portable packages that are fully standardized and supported as part of the language. The second is represented by Direct3D and OpenGL, where the drawing commands are part of a software library tied to a language such as C++ , and the user-interface software is an independent entity that might vary from system to system. In this latter approach, it is problematic to write portable code, although for simple programs, it may be possible to use a portable library layer to encapsulate the system specific user-interface code.
Whatever your choice of API, the basic graphics calls will be largely the same, and the concepts of this book will apply.
Graphics Pipeline 1.4
Every desktop computer today has a powerful 3D graphics pipeline. This is a special software/hardware subsystem that efficiently draws 3D primitives in perspective. Usually, these systems are optimized for processing 3D triangles with shared vertices. The basic operations in the pipeline map the 3D vertex locations to 2D screen positions and shade the triangles so that they both look realistic and appear in proper back-to-front order.
{21}------------------------------------------------
1.5 Numerical Issues
Although drawing the triangles in valid back-to-front order was once the most important research issue in computer graphics, it is now almost always solved using the z-buffer, which uses a special memory buffer to solve the problem in a brute-force manner.
It turns out that the geometric manipulation used in the graphics pipeline can be accomplished almost entirely in a 4D coordinate space composed of three traditional geometric coordinates and a fourth homogeneous coordinate that helps with perspective viewing. These 4D coordinates are manipulated using 4×4 matrices and 4-vectors. The graphics pipeline, therefore, contains much machinery for efficiently processing and composing such matrices and vectors. This 4D coordinate system is one of the most subtle and beautiful constructs used in computer science, and it is certainly the biggest intellectual hurdle to jump when learning computer graphics. A big chunk of the first part of every graphics book deals with these coordinates.
The speed at which images can be generated depends strongly on the number of triangles being drawn. Because interactivity is more important in many applications than visual quality, it is worthwhile to minimize the number of triangles used to represent a model. In addition, if the model is viewed in the distance, fewer triangles are needed than when the model is viewed from a closer distance. This suggests that it is useful to represent a model with a varying level of detail (LOD).