Real-Time Rendering Tomas Möller Eric Haines n A K Peters Natick, Massachusetts
Contents Preface 1 Introduction 1 1.1 Contents Overview 2 1.2 Notation and Definitions 3 1.2.1 Mathematical Notation 3 1.2.2 Geometrical Definitions 5 2 The Graphics Rendenng Pipeline 7 2.1 Architecture 8 2.2 The Application Stage 10 2.3 The Geometry Stage 11 2.3.1 Model and View Transform 12 2.3.2 Lighting and Shading 13 2.3.3 Projection 14 2.3.4 Clipping 16 2.3.5 Screen Mapping 16 2.4 The Rasterizer Stage 17 2.5 Through the Pipeline 20 3 Transforms 23 3.1 Basic Transforms 25 3.1.1 Translation Matrix 25 3.1.2 Rotation Maurices 26 3.1.3 Scaling Matrix 27 3.1.4 Shearing Matrices 29 3.1.5 Concatenation of Transforms 31 3.1.6 The Rigid-Body Transform 33 3.1.7 Normal Transform 34 3.1.8 Computation of Inverses 35 3.2 Special Matrix Transforms and Operations 36 3.2.1 The Euler Transform 36 xiü vii
viii Contents 3.2.2 Extracting Parameters from the Euler Transform 38 3.2.3 Matrix Decomposition 40 3.2.4 Rotation About an Arbitrary Axis 41 3.3 Quaternions 42 3.3.1 Mathematical Background 43 3.3.2 Quaternion Transforms 45 3.4 Interpolation 52 3.5 Protections 57 3.5.1 Orthographie Projection 57 3.5.2 Perspective Projection 60 4 Visual Appearance 65 4.1 Light Sources 65 4.2 Material 67 4.3 Lighting and Shading 68 4.3.1 Diffuse Component 71 4.3.2 Specular Component 73 4.3.3 Ambient Component 77 4.3.4 Lighting Equation 78 4.4 Aliasing and Antialiasing 81 4.5 Transparency, Alpha, and Compositing 85 4.6 Fog 89 4.7 Gamma Correction 93 5 Texturing 99 5.1 Generalized Texturing 100 5.2 Image Texturing '.. 106 5.2.1 Magnification 107 5.2.2 Minification 108 5.3 Texture Caching and Compression 117 5.4 Multipass Rendering 119 5.5 Multitexturing ' 121 5.6 Texture Animation 122 5.7 Texturing Methods 123 5.7.1 Alpha Mapping 123 5.7.2 Light Mapping 124 5.7.3 Gloss Mapping 125 5.7.4 Environment Mapping 127 5.7.5 Bump Mapping 136 5.7.6 Other Texturing Techniques 143
Contents ix 6 Special Effects 145 6.1 The Rendenng Spectram 146 6.2 Image-Based Rendenng 147 6.2.1 Lens Flare and Bloom 150 6.2.2 Billboarding 152 6.2.3 Full-Screen Billboarding 155 6.2.4 Particle Systems 156 6.2.5 Fixed-View Effects 157 6.3 Motion Blur 158 6.4 Depth of Field 159 6.5 Reflections 160 6.5.1 Planar Reflections 161 6.5.2 Glossy Effects 165 6.5.3 Reflections from Curved Reflectors 166 6.6 Shadows 167 6.6.1 Planar Shadows 167 6.6.2 Shadows on Curved Surfaces 175 6.7 Lines 183 6.7.1 Edge Highlighting 184 6.7.2 Polygon Edge Rendering 184 6.7.3 Hidden-Line Rendering 185 6.7.4 Haloing 186 6.8 Height-Field and Volume Rendering 186 7 Speed-Up Techniques 191 7.1 Culling Techniques 191 7.1.1 Backface and Clustered Culling 192 7.1.2 Hierarchical View-Frastum Culling 194 7.1.3 Portal Culling 200 7.1.4 Detail Culling 203 7.1.5 Occlusion Culling 204 7.2 Impostors 218 7.2.1 Nailboards 221 7.2.2 Hierarchical Image Caching 222 7.2.3 Related Work 224 7.3 Levels of Detail 224 7.3.1 Discrete Geometry LODs 225 7.3.2 Alpha LODs 226 7.3.3 Geomorph LODs 227 7.3.4 LOD Management 228 7.4 Triangle Strips, Fans, and Meshes 231
x Contents 7.4.1 Strips,,;,... 232 7.4.2 Fans 235 7.4.3 Creating Strips 236 7.4.4 Polygon Meshes 240 8 Pipeline Optimization 241 8.1 Locating the Bottleneck 242 8.1.1 Testing the Application Stage 243 8.1.2 Testing the Geometry Stage 243 8.1.3 Testing the Rasterizer Stage 244 8.2 Optimization 244 8.2.1 Application Stage 244 8.2.2 Geometry Stage 248 8.2.3 Rasterizer Stage 250 8.2.4 Overall Optimization 252 8.3 Balancing the Graphics Pipeline 254 8.4 Host and Accelerator 258 8.5 Multiprocessing 260 8.5.1 Multiprocessor Pipelining 260 8.5.2 Parallel Processing 264 9 Polygonal Techniques 267 9.1 Sources of Three-Dimensional Data 268 9.2 Tessellation 269 9.2.1 Shading Problems.,. 271 9.2.2 Edge Cracking and T-Vertices 274 9.3 Consolidation 275 9.4 Simplification 281 10 Intersection Test Methods 289 10.1 Defmitions 291 10.2 Rules of Thumb 295 10.3 Ray/Sphere Intersection 295 10.3.1 Mathematical Solution 296 10.3.2 Optimized Solution 297 10.4 Ray/Box Intersection 299 10.4.1 Slabs Method 299 10.4.2 Woo's Method 302 10.5 Ray/Triangle Intersection 303 10.5.1 Intersection Algorithm 303 10.5.2 Implementation 305
Contents xi 10.6 Ray/Polygon Intersection 306 10.6.1 The Crossings Test 307 10.7 Plane/Box Intersection Detection 310 10.7.1 AABB 311 10.7.2 OBB 312 10.8 Triangle/Triangle Intersection 313 10.8.1 Interval Overlap Method 314 10.8.2 ERIT's Method 317 10.8.3 Performance Comparison / 318 10.9 Cube/Polygon Intersection 319 10.9.1 General Algorithm 319 10.10 BV/BV Intersection Tests 322 10.10.1 Sphere/Box Intersection 323 10.10.2 AABB/AABB Intersection 324 10.10.3fc-DOP/fc-DOPIntersection 324 10.10.4 OBB/OBB Intersection 325 10.11 View Frustrum Intersection 330 10.11.1 Frustum/Sphere Intersection 332 10.11.2 Frustum/Box Intersection 335 10.12 Line/Line Intersection Tests 336 10.12.1 Two Dimensions 336 10.12.2 Three Dimensions 338 10.13 Intersection Between Three Planes 339 11 CoUision Detection 341 11.1 CoUision Detection with Rays 343 11.2 General Hierarchical CoUision Detection 344 11.2.1 Hierarchy Building 345 11.2.2 CoUision Testing between Hierarchies 347 11.2.3 Cost Function 348 11.3 OBBTree 349 11.4 fc-doptree.354 11.5 A Multiple Objects CD System 357 11.5.1 The First-Level CD 358 11.5.2 Summary 360 12 Graphics Hardware 363 12.1 Buffers and Buffering 363 12.1.1 A Simple Display System 363 12.1.2 The Color Buffer 365 12.1.3 Z-buffering and W-buffering 368
XII Contents 12.1.4 Single, Double, and Triple Buffering 370 12.1.5 Stereo Buffers 372 12.1.6 Stencil and Accumulation Buffering 373 12.1.7 Memory 374 12.2 Architecture 375 12.2.1 General 375 12.2.2 Case Study: Neon 378 12.2.3 Case Study: VISUALIZE fx...,. 380 12.2.4 Case Study: InfiniteReality 383 12.2.5 Other Architectures 386 13 The Fnture 389 13.1 Everything Else 389 13.2 You 391 A Some Linear Algebra 395 A.l The Euclidean Space 396 A.2 Geometrical Interpretation 398 A.3 Matrices 403 A.3.1 Definitions and Operations 403 A.3.2 Change of Base 410 A.4 Homogeneous Notation 411 A.5 Geometry 412 A.5.1 Lines 412 A.5.2 Planes. 414 A.5.3 Convex Hüll 415 A.5.4 Miscellaneous 416 B Trigonometry 419 B.l Definitions 419 B.2 Trigonometrie Laws and Formulae 421 References 427 Index 463