Fundamentals
of Computer Graphics
F O U R T H E D I T I O N
Fundamentals
of Computer Graphics
F O U R T H E D I T I O N
Steve Marschner
Cornell University
Peter Shirley
Purity, LLC
with
Michael Ashikhmin
Michael Gleicher
Naty Hoffman
Garrett Johnson
Tamara Munzner
Erik Reinhard
William B. Thompson
Peter Willemsen
Brian Wyvill
CRC Press
Taylor & Francis Group
6000 Broken Sound Parkway NW, Suite 300
Boca Raton, FL 33487-2742
© 2016 by Taylor & Francis Group, LLC
CRC Press is an imprint of Taylor & Francis Group, an Informa business
No claim to original U.S. Government works
Version Date: 20151012
International Standard Book Number-13: 978-1-4822-2941-7 (eBook - PDF)
This book contains information obtained from authentic and highly regarded sources. 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, please access www.copyright.com (http://www.copyright.com/) or contact the Copyright
Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. CCC is a not-for-profit organization that provides licenses and registration for a
variety of users. For organizations that have been granted a photocopy license by the CCC, a separate system of payment has been arranged.
Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for identification and explanation without intent to
infringe.
Visit the Taylor & Francis Web site at
http://www.taylorandfrancis.com
and the CRC Press Web site at
http://www.crcpress.com
Contents
Preface
1 Introduction
. . . .
1.1
Graphics Areas . . .
. . . .
1.2 Major Applications .
. . . .
Graphics APIs
1.3
. . .
. . . .
1.4
Graphics Pipeline . .
. . . .
Numerical Issues . .
1.5
Efficiency . . .
1.6
. . . .
. . .
Designing and Coding Graphics Programs .
1.7
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
xi
1
2
3
4
4
5
7
8
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
2 Miscellaneous Math
Sets and Mappings .
. . . .
Solving Quadratic Equations . . . .
. . . .
. . . .
. . .
Trigonometry .
. . . .
. . . .
Vectors . . . .
. . .
. . . .
Curves and Surfaces
. . . .
Linear Interpolation . . . .
. . . .
. . . .
. . . .
Triangles . . .
2.1
2.2
2.3
2.4
2.5
2.6
2.7
. . .
3 Raster Images
3.1
3.2
3.3
3.4
. . . .
. . . .
Raster Devices . . .
Images, Pixels, and Geometry . . .
. . . .
RGB Color . .
. . .
Alpha Compositing .
. . . .
. . . .
. . . .
4 Ray Tracing
4.1
4.2
4.3
4.4
4.5
. . .
The Basic Ray-Tracing Algorithm .
. . . .
Perspective . .
. . . .
Computing Viewing Rays
. . . .
.
. . . .
Ray-Object Intersection . .
Shading . . . .
. . . .
. . . .
. . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . .
. . .
. . .
. . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . .
. . .
. . .
. . .
. . .
. . . .
. . . .
. . . .
. . . .
. . . .
13
. . . . 13
. . . . 17
. . . . 18
. . . . 21
. . . . 30
. . . . 44
. . . . 44
53
. . . . 54
. . . . 59
. . . . 64
. . . . 65
69
. . . . 70
. . . . 71
. . . . 73
. . . . 76
. . . . 81
v
vi
4.6
4.7
4.8
4.9
A Ray-Tracing Program . .
Shadows
. . . .
Ideal Specular Reflection . .
. . . .
Historical Notes
. . . .
. .
. .
Contents
. . . .
. . . .
. . . .
. . . .
. . .
. . .
. . .
. . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . . 84
. . . . 86
. . . . 87
. . . . 87
5 Linear Algebra
Determinants . . . .
. . . .
5.1
5.2 Matrices . . .
5.3
5.4
. . . .
. . . .
Computing with Matrices and Determinants . . .
Eigenvalues and Matrix Diagonalization .
. . . .
. . . .
. . . .
. . . .
. . . .
. . .
. . .
. . . .
. . . .
. . . .
. . . .
6 Transformation Matrices
2D Linear Transformations .
. . .
3D Linear Transformations .
. . .
Translation and Affine Transformations .
Inverses of Transformation Matrices . . .
Coordinate Transformations . . . .
. . .
6.1
6.2
6.3
6.4
6.5
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
7 Viewing
7.1
7.2
7.3
7.4
7.5
. . . .
Viewing Transformations . .
. . . .
Projective Transformations .
Perspective Projection . . .
. . . .
Some Properties of the Perspective Transform . .
Field-of-View . . . .
. . . .
. . . .
. . . .
. . . .
. . .
. . .
. . .
. . . .
. . . .
. . .
8 The Graphics Pipeline
8.1
8.2
8.3
8.4
. . . .
. . . .
Rasterization . . . .
. . . .
Operations Before and After Rasterization . . . .
. . . .
Simple Antialiasing .
. . . .
Culling Primitives for Efficiency . .
. . . .
. . .
. . .
. . . .
. . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
9 Signal Processing
9.1
9.2
9.3
9.4
9.5
Digital Audio: Sampling in 1D . . .
. . . .
Convolution .
. . . .
Convolution Filters .
. . . .
Signal Processing for Images . . . .
Sampling Theory . .
. . . .
. . . .
. . . .
. . . .
. . .
. . .
. . .
. . .
. . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
89
. . . . 89
. . . . 91
. . . . 96
. . . . 101
109
. . . . 109
. . . . 123
. . . . 128
. . . . 132
. . . . 133
139
. . . . 140
. . . . 146
. . . . 149
. . . . 153
. . . . 154
159
. . . . 160
. . . . 171
. . . . 177
. . . . 179
183
. . . . 184
. . . . 187
. . . . 201
. . . . 208
. . . . 217
Contents
10 Surface Shading
10.1 Diffuse Shading . .
10.2 Phong Shading . . .
10.3 Artistic Shading . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . .
. . .
. . .
. . . .
. . . .
. . . .
11 Texture Mapping
. . . .
11.1 Looking Up Texture Values
. . .
11.2 Texture Coordinate Functions
11.3 Antialiasing Texture Lookups
. . .
11.4 Applications of Texture Mapping .
. . . .
11.5 Procedural 3D Textures . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . .
. . .
. . .
. . .
. . .
. . . .
. . . .
. . . .
. . . .
. . . .
12 Data Structures for Graphics
. .
. . .
. . . .
. . . .
12.1 Triangle Meshes
. . . .
12.2 Scene Graphs .
. . . .
. . . .
12.3 Spatial Data Structures . . .
12.4 BSP Trees for Visibility . .
. . . .
12.5 Tiling Multidimensional Arrays . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . .
. . .
. . .
. . .
. . .
. . . .
. . . .
. . . .
. . . .
. . . .
13 More Ray Tracing
13.1 Transparency and Refraction . . . .
13.2 Instancing . . .
. . . .
13.3 Constructive Solid Geometry . . . .
13.4 Distribution Ray Tracing . .
. . . .
. . . .
. . .
. . . .
. . . .
. . . .
. . . .
. . .
. . .
. . .
. . .
. . . .
. . . .
. . . .
. . . .
14 Sampling
. . .
14.1 Integration . .
. . . .
14.2 Continuous Probability . . .
14.3 Monte Carlo Integration . .
14.4 Choosing Random Points . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . .
. . .
. . .
. . .
. . . .
. . . .
. . . .
. . . .
15 Curves
. . . .
. . . .
. . .
15.1 Curves
. . . .
15.2 Curve Properties . .
15.3 Polynomial Pieces
. . . .
.
15.4 Putting Pieces Together . . .
15.5 Cubics
. . . .
15.6 Approximating Curves . . .
15.7 Summary . . .
. . . .
. . . .
. . .
. . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . .
. . .
. . .
. . .
. . .
. . .
. . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
vii
233
. . . . 233
. . . . 236
. . . . 239
243
. . . . 244
. . . . 246
. . . . 260
. . . . 267
. . . . 273
281
. . . . 282
. . . . 295
. . . . 297
. . . . 309
. . . . 317
323
. . . . 324
. . . . 327
. . . . 328
. . . . 329
337
. . . . 337
. . . . 342
. . . . 346
. . . . 349
359
. . . . 359
. . . . 365
. . . . 368
. . . . 375
. . . . 378
. . . . 385
. . . . 402