- 电子工业出版社
- 9787121393983
- 1
- 349773
- 16开
- 2020-08
- 808
- 计算机科学与技术(工学/理学)
- 本科 研究生(硕士、EMBA、MBA、MPA、博士)
作者简介
内容简介
本书采用自顶向下的方法并辅以面向编程的方式,基于现代可编程GPU的WebGL 2.0着色器编程,综合利用HTML5、JavaScript和GLSL(OpenGL ES 3.0),开发可以在所有最新浏览器中运行的三维图形应用程序,同时系统地介绍了现代计算机图形学的核心概念、原理和方法。本书是作者多年教学与科研的结晶,涵盖了交互式图形编程、可编程GPU绘制流水线、变换与观察、光照与着色、曲线与曲面建模、离散技术等计算机图形学的基本内容,以及层级建模、过程建模、光线跟踪、并行绘制、体绘制和虚拟现实等高级内容。为了方便读者进一步深入学习和研究计算机图形学,本书在每章末尾提供了相关的建议阅读资料。
目录
CONTENTS
CHAPTER 1 GRAPHICS SYSTEMS AND MODELS 1
1.1 Applications of Computer Graphics 2
1.1.1 Display of Information 2
1.1.2 Design 3
1.1.3 Simulation and Animation 4
1.1.4 User Interfaces 6
1.2 A Graphics System 7
1.2.1 Pixels and the Framebuffer 8
1.2.2 The CPU and the GPU 9
1.2.3 Output Devices 10
1.2.4 Input Devices 13
1.3 Images: Physical and Synthetic 13
1.3.1 Objects and Viewers 14
1.3.2 Light and Images 15
1.3.3 Imaging Models 17
1.4 Imaging Systems 19
1.4.1 The Pinhole Camera 19
1.4.2 The Human Visual System 21
1.5 The Synthetic-Camera Model 22
1.6 The Programmer’s Interface 24
1.6.1 The Pen-Plotter Model 25
1.6.2 Three-Dimensional APIs 28
1.6.3 A Sequence of Images 31
1.6.4 The Modeling–Rendering Paradigm 32
1.7 Graphics Architectures 35
1.7.1 Display Processors 36
1.7.2 Pipeline Architectures 37
1.7.3 The Graphics Pipeline 38
1.7.4 Vertex Processing 39
1.7.5 Clipping and Primitive Assembly 40
1.7.6 Rasterization 40
1.7.7 Fragment Processing 40
1.8 Programmable Pipelines 41
1.9 Performance Characteristics 42
1.10 OpenGL Versions and WebGL 43
Summary and Notes 44
Suggested Readings 45
Exercises 45
CHAPTER 2 GRAPHICS PROGRAMMING 49
2.1 The Sierpinski Gasket 49
2.2 Programming Two-Dimensional Applications 52
2.3 The WebGL Application Programming Interface 58
2.3.1 Graphics Functions 59
2.3.2 The Graphics Pipeline and State Machines 61
2.3.3 OpenGL and WebGL 61
2.3.4 The WebGL Interface 62
2.3.5 Coordinate Systems 64
2.4 Primitives and Attributes 65
2.4.1 Polygon Basics 67
2.4.2 Polygons in WebGL 70
2.4.3 Triangulation 71
2.4.4 Text 73
2.4.5 Vertex Attributes 75
2.5 Color 76
2.5.1 RGB Color 78
2.5.2 Color Tables 80
2.5.3 Setting of Color Attributes 81
2.6 Viewing 82
2.6.1 The Orthographic View 83
2.6.2 Two-Dimensional Viewing 84
2.7 Control Functions 85
2.7.1 The HTML Canvas 87
2.7.2 Aspect Ratio and Viewports 88
2.7.3 Application Execution 89
2.8 The Gasket Program 90
2.8.1 Sending Data to the GPU 93
2.8.2 Rendering the Points 94
2.8.3 The Vertex Shader 94
2.8.4 The Fragment Shader 96
2.8.5 Combining the Parts 96
2.8.6 The initShaders Function 97
2.8.7 The init Function 98
2.8.8 Reading the Shaders from the Application 99
2.9 Polygons and Recursion 100
2.10 The Three-Dimensional Gasket 102
2.10.1 Use of Three-Dimensional Points 103
2.10.2 Use of Polygons in Three Dimensions 106
2.10.3 Hidden-Surface Removal 109
Summary and Notes 110
Code Examples 113
Suggested Readings 113
Exercises 114
CHAPTER 3 INTERACTION AND ANIMATION 119
3.1 Animation 119
3.1.1 The Rotating Square 120
3.1.2 The Display Process 122
3.1.3 Double Buffering 123
3.1.4 Using a Timer 124
3.1.5 Using requestAnimationFrame 125
3.2 Interaction 125
3.3 Input Devices 127
3.4 Physical Input Devices 127
3.4.1 Keyboard Codes 128
3.4.2 The Mouse and the Trackball 128
3.4.3 Data Tablets,Touch Pads, and Touch Screens 130
3.4.4 Multidimensional Input Devices 131
3.4.5 Logical Devices 132
3.4.6 Input Modes 133
3.4.7 Clients and Servers 134
3.5 Programming Event-Driven Input 135
3.5.1 Events and Event Listeners 135
3.5.2 Adding a Button 136
3.5.3 Menus 137
3.5.4 Using Key Codes 138
3.5.5 Sliders 139
3.6 Position Input 140
3.7 Window Events 142
3.8 Gesture and Touch 143
3.9 Picking 145
3.10 Building Models Interactively 146
3.11 Design of Interactive Programs 150
Summary and Notes 151
Code Examples 153
Suggested Readings 153
Exercises 154
CHAPTER 4 GEOMETRIC OBJECTS AND TRANSFORMATIONS 159
4.1 Scalars, Points, and Vectors 160
4.1.1 Geometric Objects 160
4.1.2 Coordinate-Free Geometry 162
4.1.3 The Mathematical View: Vector and Affine Spaces 163
4.1.4 The Computer Science View 164
4.1.5 Geometric ADTs 165
4.1.6 Lines 166
4.1.7 Affine Sums 167
4.1.8 Convexity 168
4.1.9 Dot and Cross Products 169
4.1.10 Planes 170
4.2 Three-Dimensional Primitives 172
4.3 Coordinate Systems and Frames 175
4.3.1 Representations and N-Tuples 177
4.3.2 Change of Coordinate Systems 178
4.3.3 Example: Change of Representation 180
4.3.4 Homogeneous Coordinates 182
4.3.5 Example: Change in Frames 185
4.3.6 Working with Representations 187
4.4 Frames in WebGL 189
4.5 Matrix and Vector Types 193
4.5.1 Row Versus Column Major Matrix Representations 195
4.6 Modeling a Colored Cube 195
4.6.1 Modeling the Faces 196
4.6.2 Inward- and Outward-Pointing Faces 197
4.6.3 Data Structures for Object Representation 198
4.6.4 The Colored Cube 198
4.6.5 Color Interpolation 200
4.6.6 Displaying the Cube 201
4.6.7 Drawing by Elements 202
4.6.8 Primitive Restart 203
4.7 Affine Transformations 204
4.8 Translation, Rotation, and Scaling 207
4.8.1 Translation 207
4.8.2 Rotation 207
4.8.3 Scaling 209
4.9 Transformations in Homogeneous Coordinates 211
4.9.1 Translation 212
4.9.2 Scaling 213
4.9.3 Rotation 214
4.9.4 Shear 215
4.10 Concatenation of Transformations 217
4.10.1 Rotation About a Fixed Point 218
4.10.2 General Rotation 219
4.10.3 The Instance Transformation 220
4.10.4 Rotation About an Arbitrary Axis 222
4.11 Transformation Matrices in WebGL 226
4.11.1 Current Transformation Matrices 227
4.11.2 Basic Matrix Functions 228
4.11.3 Rotation, Translation, and Scaling 229
4.11.4 Rotation About a Fixed Point 229
4.11.5 Order of Transformations 230
4.12 Spinning of the Cube 231
4.12.1 Uniform Matrices 233
4.13 Smooth Rotations 235
4.13.1 Incremental Rotation 236
4.14 Quaternions 237
4.14.1 Complex Numbers and Quaternions 237
4.14.2 Quaternions and Rotation 238
4.14.3 Quaternions and Gimbal Lock 240
4.15 Interfaces to Three-Dimensional Applications 242
4.15.1 Using Areas of the Screen 242
4.15.2 A Virtual Trackball 243
4.15.3 Implementing the Trackball with Quaternions 245
Summary and Notes 247
Code Examples 247
Suggested Readings 248
Exercises 248
CHAPTER 5 VIEWING 253
5.1 Classical and Computer Viewing 253
5.1.1 Classical Viewing 255
5.1.2 Orthographic Projections 255
5.1.3 Axonometric Projections 256
5.1.4 Oblique Projections 258
5.1.5 Perspective Viewing 259
5.2 Viewing with a Computer 260
5.3 Positioning of the Camera 262
5.3.1 From the Object Frame to the Camera Frame 262
5.3.2 Two Viewing APIs 267
5.3.3 The Look-At Function 271
5.4 Parallel Projections 272
5.4.1 Orthogonal Projections 274
5.4.2 Parallel Viewing with WebGL 275
5.4.3 Projection Normalization 276
5.4.4 Orthogonal Projection Matrices 277
5.4.5 Oblique Projections 279
5.4.6 An Interactive Viewer 282
5.5 Perspective Projections 284
5.5.1 Simple Perspective Projections 285
5.6 Perspective Projections with WebGL 288
5.6.1 Perspective Functions 289
5.7 Perspective Projection Matrices 290
5.7.1 Perspective Normalization 291
5.7.2 WebGL Perspective Transformations 294
5.7.3 Perspective Example 296
5.8 Hidden-Surface Removal 296
5.8.1 Culling 298
5.9 Displaying Meshes 299
5.9.1 Displaying Meshes as Surfaces 302
5.9.2 Polygon Offset 304
5.9.3 Walking Through a Scene 305
5.10 Projections and Shadows 306
5.10.1 Projected Shadows 306
5.11 Shadow Maps 310
Summary and Notes 312
Code Examples 313
Suggested Readings 313
Exercises 313
CHAPTER 6 LIGHTING AND SHADING 317
6.1 Light and Matter 318
6.2 Light Sources 321
6.2.1 Color Sources 322
6.2.2 Ambient Light 322
6.2.3 Point Sources 323
6.2.4 Spotlights 324
6.2.5 Distant Light Sources 325
6.3 The Phong Lighting Model 326
6.3.1 Ambient Reflection 328
6.3.2 Diffuse Reflection 329
6.3.3 Specular Reflection 330
6.3.4 The Modified Phong Model 333
6.4 Computation of Vectors 334
6.4.1 Normal Vectors 334
6.4.2 Angle of Reflection 336
6.5 Polygonal Shading 338
6.5.1 Flat Shading 339
6.5.2 Smooth and Gouraud Shading 339
6.5.3 Phong Shading 341
6.6 Approximation of a Sphere by Recursive Subdivision 343
6.7 Specifying Lighting Parameters 346
6.7.1 Light Sources 346
6.7.2 Materials 347
6.8 Implementing a Lighting Model 348
6.8.1 Applying the Lighting Model in the Application 348
6.8.2 Efficiency 351
6.8.3 Lighting in the Vertex Shader 353
6.9 Shading of the Sphere Model 357
6.10 Per-Fragment Lighting 359
6.11 Nonphotorealistic Shading 361
6.12 Global Illumination 363
Summary and Notes 364
Code Examples 365
Suggested Readings 366
Exercises 366
CHAPTER 7 TEXTURE MAPPING 369
7.1 Buffers 369
7.2 Digital Images 371
7.3 Mapping Methods 375
7.4 Two-Dimensional Texture Mapping 377
7.5 Texture Mapping in WebGL 384
7.5.1 Texture Objects 384
7.5.2 The Texture Image Array 385
7.5.3 Texture Coordinates and Samplers 386
7.5.4 Texture Sampling 391
7.5.5 Working with Texture Coordinates 395
7.5.6 3D Texture Mapping 397
7.5.7 Multitexturing 403
7.6 Environment Maps 407
7.7 Reflection Map Example 412
7.8 Bump Mapping 417
7.8.1 Finding Bump Maps 418
7.8.2 Bump Map Example 421
Summary and Notes 425
Code Examples 427
Suggested Readings 427
Exercises 427
CHAPTER 8 WORKING WITH FRAMEBUFFERS 429
8.1 Blending Techniques 429
8.1.1 Opacity and Blending 429
8.1.2 Image Blending 431
8.1.3 Blending in WebGL 431
8.1.4 Antialiasing Revisited 433
8.1.5 Back-to-Front and Front-to-Back Rendering 435
8.1.6 Scene Antialiasing and Multisampling 436
8.2 Image Processing 436
8.2.1 Other Multipass Methods 438
8.3 GPGPU 439
8.4 Framebuffer Objects 443
8.5 Multi-pass Rendering Techniques 449
8.5.1 Ambient Occlusion 450
8.5.2 Deferred Lighting 451
8.6 Buffer Ping-Ponging 452
8.7 Picking 455
8.8 Shadow Maps 460
8.9 Projective Textures 464
Summary and Notes 466
Code Examples 467
Suggested Readings 468
Exercises 468
CHAPTER 9 MODELING AND HIERARCHY 471
9.1 Geometries and Instances 472
9.2 Hierarchical Models 474
9.3 A Robot Arm 476
9.4 Trees and Traversal 480
9.4.1 A Stack-Based Traversal 481
9.5 Use of Tree Data Structures 485
9.6 Animation 489
9.7 Graphical Objects 490
9.7.1 Methods, Attributes, and Messages 491
9.7.2 A Cube Object 492
9.7.3 Instancing in WebGL 496
9.7.4 Objects and Hierarchy 498
9.7.5 Geometric and Nongeometric Objects 499
9.8 Scene Graphs 500
9.9 Implementing Scene Graphs 502
9.9.1 Examples 504
9.10 Other Tree Structures 508
9.10.1 CSG Trees 508
9.10.2 BSP Trees 510
9.10.3 Quadtrees and Octrees 512
Summary and Notes 514
Code Examples 515
Suggested Readings 515
Exercises 516
CHAPTER 10 PROCEDURAL METHODS 519
10.1 Algorithmic Models 519
10.2 Physically Based Models and Particle Systems 521
10.3 Newtonian Particles 522
10.3.1 Independent Particles 524
10.3.2 Spring Forces 524
10.3.3 Attractive and Repulsive Forces 526
10.4 Solving Particle Systems 527
10.5 Constraints 530
10.5.1 Collisions 530
10.5.2 Soft Constraints 533
10.6 A Simple Particle System 533
10.6.1 Displaying the Particles 534
10.6.2 Updating Particle Positions 535
10.6.3 Collisions 535
10.6.4 Forces 536
10.6.5 Flocking 537
10.7 Agent-Based Models 538
10.8 Using Point Sprites 541
10.9 Language-Based Models 545
10.10 Recursive Methods and Fractals 550
10.10.1 Rulers and Length 551
10.10.2 Fractal Dimension 552
10.10.3 Midpoint Division and Brownian Motion 554
10.10.4 Fractal Mountains 555
10.10.5 The Mandelbrot Set 556
10.10.6 Mandelbrot Fragment Shader 559
10.11 Procedural Noise 561
Summary and Notes 563
Code Examples 565
Suggested Readings 566
Exercises 566
CHAPTER 11 CURVES AND SURFACES 569
11.1 Representation of Curves and Surfaces 569
11.1.1 Explicit Representation 569
11.1.2 Implicit Representations 571
11.1.3 Parametric Form 572
11.1.4 Parametric Polynomial Curves 573
11.1.5 Parametric Polynomial Surfaces 574
11.2 Design Criteria 575
11.3 Parametric Cubic Polynomial Curves 578
11.4 Interpolation 579
11.4.1 Blending Functions 581
11.4.2 The Cubic Interpolating Patch 582
11.5 Hermite Curves and Surfaces 584
11.5.1 The Hermite Form 584
11.5.2 Geometric and Parametric Continuity 587
11.6 Be′ zier Curves and Surfaces 588
11.6.1 Be′ zier Curves 588
11.6.2 Be′ zier Surface Patches 591
11.7 Cubic B-Splines 592
11.7.1 The Cubic B-Spline Curve 593
11.7.2 B-Splines and Basis 597
11.7.3 Spline Surfaces 597
11.8 General B-Splines 598
11.8.1 Recursively Defined B-Splines 599
11.8.2 Uniform Splines 601
11.8.3 Nonuniform B-Splines 601
11.8.4 NURBS 602
11.8.5 Catmull-Rom Splines 603
11.9 Rendering Curves and Surfaces 604
11.9.1 Polynomial Evaluation Methods 605
11.9.2 Recursive Subdivision of Be′ zier Polynomials 606
11.9.3 Rendering Other Polynomial Curves by Subdivision 609
11.9.4 Subdivision of Be′ zier Surfaces 610
11.10 The Utah Teapot 611
11.11 Algebraic Surfaces 614
11.11.1 Quadrics 614
11.11.2 Rendering of Surfaces by Ray Casting 615
11.12 Subdivision Curves and Surfaces 615
11.12.1 Mesh Subdivision 616
11.13 Mesh Generation from Data 619
11.13.1 Height Fields Revisited 619
11.13.2 Delaunay Triangulation 620
11.13.3 Point Clouds 624
11.14 Graphics API support for Curves and Surfaces 624
11.14.1 Tessellation Shading 625
11.14.2 Geometry Shading 626
Summary and Notes 626
Code Examples 627
Suggested Readings 627
Exercises 627
CHAPTER 12 FROM GEOMETRY TO PIXELS 631
12.1 Basic Rendering Strategies 632
12.2 Rendering Pipeline 634
12.2.1 Modeling 634
12.2.2 Geometry Processing 635
12.2.3 Rasterization 636
12.2.4 Fragment Processing 637
12.3 Clipping 638
12.3.1 Clipping 638
12.3.2 Bounding Boxes and Volumes 639
12.3.3 Clipping Against Planes 640
12.4 Rasterization 642
12.5 Polygon Rasterization 645
12.5.1 Inside–Outside Testing 646
12.5.2 WebGL and Concave Polygons 647
12.6 Hidden-Surface Removal 649
12.6.1 Object-Space and Image-Space Approaches 649
12.6.2 Sorting and Hidden-Surface Removal 651
12.6.3 Scan Line Algorithms 651
12.6.4 Back-Face Removal 653
12.6.5 The z-Buffer Algorithm 655
12.6.6 Depth Sort and the Painter’s Algorithm 657
12.7 Hardware Implementations 660
12.8 Antialiasing 663
12.9 Display Considerations 666
12.9.1 Color Systems 666
12.9.2 The Color Matrix 669
12.9.3 Gamma Correction 671
12.9.4 Dithering and Halftoning 671
Summary and Notes 672
Suggested Readings 674
Exercises 675
CHAPTER 13 ADVANCED RENDERING 679
13.1 Going Beyond Pipeline Rendering 679
13.2 Ray Tracing 680
13.3 Building a Simple Ray Tracer 684
13.3.1 Recursive Ray Tracing 685
13.3.2 Calculating Intersections 686
13.3.3 Ray-Tracing Variations 689
13.4 The Rendering Equation 690
13.5 Global Illumination and Path Tracing 693
13.6 RenderMan 695
13.7 Parallel Rendering 696
13.7.1 Sort-Middle Rendering 699
13.7.2 Sort-Last Rendering 699
13.7.3 Sort-First Rendering 703
13.8 Implicit Functions and Contour Maps 704
13.8.1 Marching Squares 704
13.8.2 Marching Triangles 709
13.9 Volume Rendering 710
13.9.1 Volumetric Data Sets 711
13.9.2 Visualization of Implicit Functions 712
13.10 Isosurfaces and Marching Cubes 714
13.11 Marching Tetrahedra 716
13.12 Mesh Simplification 717
13.13 Direct Volume Rendering 719
13.13.1 Assignment of Color and Opacity 719
13.13.2 Splatting 720
13.13.3 Volume Ray Tracing 722
13.13.4 Texture Mapping of Volumes 723
13.14 Image-Based Rendering 723
13.14.1 Distance from Stereo Pairs 724
13.14.2 The Fundamental Matrix 727
13.15 Virtual, Augmented, and Mixed Reality 727
13.16 A Final Example 729
Summary and Notes 731
Suggested Readings 732
Exercises 733
APPENDIX A INITIALIZING SHADERS 735
A.1 Shaders in the HTML file 735
A.2 Reading Shaders from Source Files 738
APPENDIX B SPACES 741
B.1 Scalars 741
B.2 Vector Spaces 742
B.3 Affine Spaces 744
B.4 Euclidean Spaces 747
B.5 Projections 747
B.6 Gram-Schmidt Orthogonalization 748
Suggested Readings 749
Exercises 749
APPENDIX C MATRICES 751
C.1 Definitions 751
C.2 Matrix Operations 752
C.3 Row and Column Matrices 753
C.4 Rank 754
C.5 Change of Representation 755
C.6 The Cross Product 757
C.7 Eigenvalues and Eigenvectors 757
C.8 Vector and Matrix Objects 759
Suggested Readings 759
Exercises 760
APPENDIX D SAMPLING AND ALIASING 761
D.1 Sampling Theory 761
D.2 Reconstruction 766
D.3 Quantization 768
Suggested Readings 769
References 771
CHAPTER 1 GRAPHICS SYSTEMS AND MODELS 1
1.1 Applications of Computer Graphics 2
1.1.1 Display of Information 2
1.1.2 Design 3
1.1.3 Simulation and Animation 4
1.1.4 User Interfaces 6
1.2 A Graphics System 7
1.2.1 Pixels and the Framebuffer 8
1.2.2 The CPU and the GPU 9
1.2.3 Output Devices 10
1.2.4 Input Devices 13
1.3 Images: Physical and Synthetic 13
1.3.1 Objects and Viewers 14
1.3.2 Light and Images 15
1.3.3 Imaging Models 17
1.4 Imaging Systems 19
1.4.1 The Pinhole Camera 19
1.4.2 The Human Visual System 21
1.5 The Synthetic-Camera Model 22
1.6 The Programmer’s Interface 24
1.6.1 The Pen-Plotter Model 25
1.6.2 Three-Dimensional APIs 28
1.6.3 A Sequence of Images 31
1.6.4 The Modeling–Rendering Paradigm 32
1.7 Graphics Architectures 35
1.7.1 Display Processors 36
1.7.2 Pipeline Architectures 37
1.7.3 The Graphics Pipeline 38
1.7.4 Vertex Processing 39
1.7.5 Clipping and Primitive Assembly 40
1.7.6 Rasterization 40
1.7.7 Fragment Processing 40
1.8 Programmable Pipelines 41
1.9 Performance Characteristics 42
1.10 OpenGL Versions and WebGL 43
Summary and Notes 44
Suggested Readings 45
Exercises 45
CHAPTER 2 GRAPHICS PROGRAMMING 49
2.1 The Sierpinski Gasket 49
2.2 Programming Two-Dimensional Applications 52
2.3 The WebGL Application Programming Interface 58
2.3.1 Graphics Functions 59
2.3.2 The Graphics Pipeline and State Machines 61
2.3.3 OpenGL and WebGL 61
2.3.4 The WebGL Interface 62
2.3.5 Coordinate Systems 64
2.4 Primitives and Attributes 65
2.4.1 Polygon Basics 67
2.4.2 Polygons in WebGL 70
2.4.3 Triangulation 71
2.4.4 Text 73
2.4.5 Vertex Attributes 75
2.5 Color 76
2.5.1 RGB Color 78
2.5.2 Color Tables 80
2.5.3 Setting of Color Attributes 81
2.6 Viewing 82
2.6.1 The Orthographic View 83
2.6.2 Two-Dimensional Viewing 84
2.7 Control Functions 85
2.7.1 The HTML Canvas 87
2.7.2 Aspect Ratio and Viewports 88
2.7.3 Application Execution 89
2.8 The Gasket Program 90
2.8.1 Sending Data to the GPU 93
2.8.2 Rendering the Points 94
2.8.3 The Vertex Shader 94
2.8.4 The Fragment Shader 96
2.8.5 Combining the Parts 96
2.8.6 The initShaders Function 97
2.8.7 The init Function 98
2.8.8 Reading the Shaders from the Application 99
2.9 Polygons and Recursion 100
2.10 The Three-Dimensional Gasket 102
2.10.1 Use of Three-Dimensional Points 103
2.10.2 Use of Polygons in Three Dimensions 106
2.10.3 Hidden-Surface Removal 109
Summary and Notes 110
Code Examples 113
Suggested Readings 113
Exercises 114
CHAPTER 3 INTERACTION AND ANIMATION 119
3.1 Animation 119
3.1.1 The Rotating Square 120
3.1.2 The Display Process 122
3.1.3 Double Buffering 123
3.1.4 Using a Timer 124
3.1.5 Using requestAnimationFrame 125
3.2 Interaction 125
3.3 Input Devices 127
3.4 Physical Input Devices 127
3.4.1 Keyboard Codes 128
3.4.2 The Mouse and the Trackball 128
3.4.3 Data Tablets,Touch Pads, and Touch Screens 130
3.4.4 Multidimensional Input Devices 131
3.4.5 Logical Devices 132
3.4.6 Input Modes 133
3.4.7 Clients and Servers 134
3.5 Programming Event-Driven Input 135
3.5.1 Events and Event Listeners 135
3.5.2 Adding a Button 136
3.5.3 Menus 137
3.5.4 Using Key Codes 138
3.5.5 Sliders 139
3.6 Position Input 140
3.7 Window Events 142
3.8 Gesture and Touch 143
3.9 Picking 145
3.10 Building Models Interactively 146
3.11 Design of Interactive Programs 150
Summary and Notes 151
Code Examples 153
Suggested Readings 153
Exercises 154
CHAPTER 4 GEOMETRIC OBJECTS AND TRANSFORMATIONS 159
4.1 Scalars, Points, and Vectors 160
4.1.1 Geometric Objects 160
4.1.2 Coordinate-Free Geometry 162
4.1.3 The Mathematical View: Vector and Affine Spaces 163
4.1.4 The Computer Science View 164
4.1.5 Geometric ADTs 165
4.1.6 Lines 166
4.1.7 Affine Sums 167
4.1.8 Convexity 168
4.1.9 Dot and Cross Products 169
4.1.10 Planes 170
4.2 Three-Dimensional Primitives 172
4.3 Coordinate Systems and Frames 175
4.3.1 Representations and N-Tuples 177
4.3.2 Change of Coordinate Systems 178
4.3.3 Example: Change of Representation 180
4.3.4 Homogeneous Coordinates 182
4.3.5 Example: Change in Frames 185
4.3.6 Working with Representations 187
4.4 Frames in WebGL 189
4.5 Matrix and Vector Types 193
4.5.1 Row Versus Column Major Matrix Representations 195
4.6 Modeling a Colored Cube 195
4.6.1 Modeling the Faces 196
4.6.2 Inward- and Outward-Pointing Faces 197
4.6.3 Data Structures for Object Representation 198
4.6.4 The Colored Cube 198
4.6.5 Color Interpolation 200
4.6.6 Displaying the Cube 201
4.6.7 Drawing by Elements 202
4.6.8 Primitive Restart 203
4.7 Affine Transformations 204
4.8 Translation, Rotation, and Scaling 207
4.8.1 Translation 207
4.8.2 Rotation 207
4.8.3 Scaling 209
4.9 Transformations in Homogeneous Coordinates 211
4.9.1 Translation 212
4.9.2 Scaling 213
4.9.3 Rotation 214
4.9.4 Shear 215
4.10 Concatenation of Transformations 217
4.10.1 Rotation About a Fixed Point 218
4.10.2 General Rotation 219
4.10.3 The Instance Transformation 220
4.10.4 Rotation About an Arbitrary Axis 222
4.11 Transformation Matrices in WebGL 226
4.11.1 Current Transformation Matrices 227
4.11.2 Basic Matrix Functions 228
4.11.3 Rotation, Translation, and Scaling 229
4.11.4 Rotation About a Fixed Point 229
4.11.5 Order of Transformations 230
4.12 Spinning of the Cube 231
4.12.1 Uniform Matrices 233
4.13 Smooth Rotations 235
4.13.1 Incremental Rotation 236
4.14 Quaternions 237
4.14.1 Complex Numbers and Quaternions 237
4.14.2 Quaternions and Rotation 238
4.14.3 Quaternions and Gimbal Lock 240
4.15 Interfaces to Three-Dimensional Applications 242
4.15.1 Using Areas of the Screen 242
4.15.2 A Virtual Trackball 243
4.15.3 Implementing the Trackball with Quaternions 245
Summary and Notes 247
Code Examples 247
Suggested Readings 248
Exercises 248
CHAPTER 5 VIEWING 253
5.1 Classical and Computer Viewing 253
5.1.1 Classical Viewing 255
5.1.2 Orthographic Projections 255
5.1.3 Axonometric Projections 256
5.1.4 Oblique Projections 258
5.1.5 Perspective Viewing 259
5.2 Viewing with a Computer 260
5.3 Positioning of the Camera 262
5.3.1 From the Object Frame to the Camera Frame 262
5.3.2 Two Viewing APIs 267
5.3.3 The Look-At Function 271
5.4 Parallel Projections 272
5.4.1 Orthogonal Projections 274
5.4.2 Parallel Viewing with WebGL 275
5.4.3 Projection Normalization 276
5.4.4 Orthogonal Projection Matrices 277
5.4.5 Oblique Projections 279
5.4.6 An Interactive Viewer 282
5.5 Perspective Projections 284
5.5.1 Simple Perspective Projections 285
5.6 Perspective Projections with WebGL 288
5.6.1 Perspective Functions 289
5.7 Perspective Projection Matrices 290
5.7.1 Perspective Normalization 291
5.7.2 WebGL Perspective Transformations 294
5.7.3 Perspective Example 296
5.8 Hidden-Surface Removal 296
5.8.1 Culling 298
5.9 Displaying Meshes 299
5.9.1 Displaying Meshes as Surfaces 302
5.9.2 Polygon Offset 304
5.9.3 Walking Through a Scene 305
5.10 Projections and Shadows 306
5.10.1 Projected Shadows 306
5.11 Shadow Maps 310
Summary and Notes 312
Code Examples 313
Suggested Readings 313
Exercises 313
CHAPTER 6 LIGHTING AND SHADING 317
6.1 Light and Matter 318
6.2 Light Sources 321
6.2.1 Color Sources 322
6.2.2 Ambient Light 322
6.2.3 Point Sources 323
6.2.4 Spotlights 324
6.2.5 Distant Light Sources 325
6.3 The Phong Lighting Model 326
6.3.1 Ambient Reflection 328
6.3.2 Diffuse Reflection 329
6.3.3 Specular Reflection 330
6.3.4 The Modified Phong Model 333
6.4 Computation of Vectors 334
6.4.1 Normal Vectors 334
6.4.2 Angle of Reflection 336
6.5 Polygonal Shading 338
6.5.1 Flat Shading 339
6.5.2 Smooth and Gouraud Shading 339
6.5.3 Phong Shading 341
6.6 Approximation of a Sphere by Recursive Subdivision 343
6.7 Specifying Lighting Parameters 346
6.7.1 Light Sources 346
6.7.2 Materials 347
6.8 Implementing a Lighting Model 348
6.8.1 Applying the Lighting Model in the Application 348
6.8.2 Efficiency 351
6.8.3 Lighting in the Vertex Shader 353
6.9 Shading of the Sphere Model 357
6.10 Per-Fragment Lighting 359
6.11 Nonphotorealistic Shading 361
6.12 Global Illumination 363
Summary and Notes 364
Code Examples 365
Suggested Readings 366
Exercises 366
CHAPTER 7 TEXTURE MAPPING 369
7.1 Buffers 369
7.2 Digital Images 371
7.3 Mapping Methods 375
7.4 Two-Dimensional Texture Mapping 377
7.5 Texture Mapping in WebGL 384
7.5.1 Texture Objects 384
7.5.2 The Texture Image Array 385
7.5.3 Texture Coordinates and Samplers 386
7.5.4 Texture Sampling 391
7.5.5 Working with Texture Coordinates 395
7.5.6 3D Texture Mapping 397
7.5.7 Multitexturing 403
7.6 Environment Maps 407
7.7 Reflection Map Example 412
7.8 Bump Mapping 417
7.8.1 Finding Bump Maps 418
7.8.2 Bump Map Example 421
Summary and Notes 425
Code Examples 427
Suggested Readings 427
Exercises 427
CHAPTER 8 WORKING WITH FRAMEBUFFERS 429
8.1 Blending Techniques 429
8.1.1 Opacity and Blending 429
8.1.2 Image Blending 431
8.1.3 Blending in WebGL 431
8.1.4 Antialiasing Revisited 433
8.1.5 Back-to-Front and Front-to-Back Rendering 435
8.1.6 Scene Antialiasing and Multisampling 436
8.2 Image Processing 436
8.2.1 Other Multipass Methods 438
8.3 GPGPU 439
8.4 Framebuffer Objects 443
8.5 Multi-pass Rendering Techniques 449
8.5.1 Ambient Occlusion 450
8.5.2 Deferred Lighting 451
8.6 Buffer Ping-Ponging 452
8.7 Picking 455
8.8 Shadow Maps 460
8.9 Projective Textures 464
Summary and Notes 466
Code Examples 467
Suggested Readings 468
Exercises 468
CHAPTER 9 MODELING AND HIERARCHY 471
9.1 Geometries and Instances 472
9.2 Hierarchical Models 474
9.3 A Robot Arm 476
9.4 Trees and Traversal 480
9.4.1 A Stack-Based Traversal 481
9.5 Use of Tree Data Structures 485
9.6 Animation 489
9.7 Graphical Objects 490
9.7.1 Methods, Attributes, and Messages 491
9.7.2 A Cube Object 492
9.7.3 Instancing in WebGL 496
9.7.4 Objects and Hierarchy 498
9.7.5 Geometric and Nongeometric Objects 499
9.8 Scene Graphs 500
9.9 Implementing Scene Graphs 502
9.9.1 Examples 504
9.10 Other Tree Structures 508
9.10.1 CSG Trees 508
9.10.2 BSP Trees 510
9.10.3 Quadtrees and Octrees 512
Summary and Notes 514
Code Examples 515
Suggested Readings 515
Exercises 516
CHAPTER 10 PROCEDURAL METHODS 519
10.1 Algorithmic Models 519
10.2 Physically Based Models and Particle Systems 521
10.3 Newtonian Particles 522
10.3.1 Independent Particles 524
10.3.2 Spring Forces 524
10.3.3 Attractive and Repulsive Forces 526
10.4 Solving Particle Systems 527
10.5 Constraints 530
10.5.1 Collisions 530
10.5.2 Soft Constraints 533
10.6 A Simple Particle System 533
10.6.1 Displaying the Particles 534
10.6.2 Updating Particle Positions 535
10.6.3 Collisions 535
10.6.4 Forces 536
10.6.5 Flocking 537
10.7 Agent-Based Models 538
10.8 Using Point Sprites 541
10.9 Language-Based Models 545
10.10 Recursive Methods and Fractals 550
10.10.1 Rulers and Length 551
10.10.2 Fractal Dimension 552
10.10.3 Midpoint Division and Brownian Motion 554
10.10.4 Fractal Mountains 555
10.10.5 The Mandelbrot Set 556
10.10.6 Mandelbrot Fragment Shader 559
10.11 Procedural Noise 561
Summary and Notes 563
Code Examples 565
Suggested Readings 566
Exercises 566
CHAPTER 11 CURVES AND SURFACES 569
11.1 Representation of Curves and Surfaces 569
11.1.1 Explicit Representation 569
11.1.2 Implicit Representations 571
11.1.3 Parametric Form 572
11.1.4 Parametric Polynomial Curves 573
11.1.5 Parametric Polynomial Surfaces 574
11.2 Design Criteria 575
11.3 Parametric Cubic Polynomial Curves 578
11.4 Interpolation 579
11.4.1 Blending Functions 581
11.4.2 The Cubic Interpolating Patch 582
11.5 Hermite Curves and Surfaces 584
11.5.1 The Hermite Form 584
11.5.2 Geometric and Parametric Continuity 587
11.6 Be′ zier Curves and Surfaces 588
11.6.1 Be′ zier Curves 588
11.6.2 Be′ zier Surface Patches 591
11.7 Cubic B-Splines 592
11.7.1 The Cubic B-Spline Curve 593
11.7.2 B-Splines and Basis 597
11.7.3 Spline Surfaces 597
11.8 General B-Splines 598
11.8.1 Recursively Defined B-Splines 599
11.8.2 Uniform Splines 601
11.8.3 Nonuniform B-Splines 601
11.8.4 NURBS 602
11.8.5 Catmull-Rom Splines 603
11.9 Rendering Curves and Surfaces 604
11.9.1 Polynomial Evaluation Methods 605
11.9.2 Recursive Subdivision of Be′ zier Polynomials 606
11.9.3 Rendering Other Polynomial Curves by Subdivision 609
11.9.4 Subdivision of Be′ zier Surfaces 610
11.10 The Utah Teapot 611
11.11 Algebraic Surfaces 614
11.11.1 Quadrics 614
11.11.2 Rendering of Surfaces by Ray Casting 615
11.12 Subdivision Curves and Surfaces 615
11.12.1 Mesh Subdivision 616
11.13 Mesh Generation from Data 619
11.13.1 Height Fields Revisited 619
11.13.2 Delaunay Triangulation 620
11.13.3 Point Clouds 624
11.14 Graphics API support for Curves and Surfaces 624
11.14.1 Tessellation Shading 625
11.14.2 Geometry Shading 626
Summary and Notes 626
Code Examples 627
Suggested Readings 627
Exercises 627
CHAPTER 12 FROM GEOMETRY TO PIXELS 631
12.1 Basic Rendering Strategies 632
12.2 Rendering Pipeline 634
12.2.1 Modeling 634
12.2.2 Geometry Processing 635
12.2.3 Rasterization 636
12.2.4 Fragment Processing 637
12.3 Clipping 638
12.3.1 Clipping 638
12.3.2 Bounding Boxes and Volumes 639
12.3.3 Clipping Against Planes 640
12.4 Rasterization 642
12.5 Polygon Rasterization 645
12.5.1 Inside–Outside Testing 646
12.5.2 WebGL and Concave Polygons 647
12.6 Hidden-Surface Removal 649
12.6.1 Object-Space and Image-Space Approaches 649
12.6.2 Sorting and Hidden-Surface Removal 651
12.6.3 Scan Line Algorithms 651
12.6.4 Back-Face Removal 653
12.6.5 The z-Buffer Algorithm 655
12.6.6 Depth Sort and the Painter’s Algorithm 657
12.7 Hardware Implementations 660
12.8 Antialiasing 663
12.9 Display Considerations 666
12.9.1 Color Systems 666
12.9.2 The Color Matrix 669
12.9.3 Gamma Correction 671
12.9.4 Dithering and Halftoning 671
Summary and Notes 672
Suggested Readings 674
Exercises 675
CHAPTER 13 ADVANCED RENDERING 679
13.1 Going Beyond Pipeline Rendering 679
13.2 Ray Tracing 680
13.3 Building a Simple Ray Tracer 684
13.3.1 Recursive Ray Tracing 685
13.3.2 Calculating Intersections 686
13.3.3 Ray-Tracing Variations 689
13.4 The Rendering Equation 690
13.5 Global Illumination and Path Tracing 693
13.6 RenderMan 695
13.7 Parallel Rendering 696
13.7.1 Sort-Middle Rendering 699
13.7.2 Sort-Last Rendering 699
13.7.3 Sort-First Rendering 703
13.8 Implicit Functions and Contour Maps 704
13.8.1 Marching Squares 704
13.8.2 Marching Triangles 709
13.9 Volume Rendering 710
13.9.1 Volumetric Data Sets 711
13.9.2 Visualization of Implicit Functions 712
13.10 Isosurfaces and Marching Cubes 714
13.11 Marching Tetrahedra 716
13.12 Mesh Simplification 717
13.13 Direct Volume Rendering 719
13.13.1 Assignment of Color and Opacity 719
13.13.2 Splatting 720
13.13.3 Volume Ray Tracing 722
13.13.4 Texture Mapping of Volumes 723
13.14 Image-Based Rendering 723
13.14.1 Distance from Stereo Pairs 724
13.14.2 The Fundamental Matrix 727
13.15 Virtual, Augmented, and Mixed Reality 727
13.16 A Final Example 729
Summary and Notes 731
Suggested Readings 732
Exercises 733
APPENDIX A INITIALIZING SHADERS 735
A.1 Shaders in the HTML file 735
A.2 Reading Shaders from Source Files 738
APPENDIX B SPACES 741
B.1 Scalars 741
B.2 Vector Spaces 742
B.3 Affine Spaces 744
B.4 Euclidean Spaces 747
B.5 Projections 747
B.6 Gram-Schmidt Orthogonalization 748
Suggested Readings 749
Exercises 749
APPENDIX C MATRICES 751
C.1 Definitions 751
C.2 Matrix Operations 752
C.3 Row and Column Matrices 753
C.4 Rank 754
C.5 Change of Representation 755
C.6 The Cross Product 757
C.7 Eigenvalues and Eigenvectors 757
C.8 Vector and Matrix Objects 759
Suggested Readings 759
Exercises 760
APPENDIX D SAMPLING AND ALIASING 761
D.1 Sampling Theory 761
D.2 Reconstruction 766
D.3 Quantization 768
Suggested Readings 769
References 771