Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Advanced graphics programming using openGL
Nội dung xem thử
Mô tả chi tiết
Advanced Graphics
Programming
Using OpenGL
TOM McREYNOLDS
DAVID BLYTHE
AMSTERDAM • BOSTON • HEIDELBERG • LONDON
NEW YORK • OXFORD • PARIS • SAN DIEGO
SAN FRANCISCO • SINGAPORE • SYDNEY • TOKYO
MORGAN KAUFMANN PUBLISHERS IS AN IMPRINT OF ELSEVIER
TEAM LinG
Advanced Graphics Programming Using OpenGL
TEAM LinG
The Morgan Kaufmann Series in Computer Graphics and Geometric Modeling
Series Editor: Brian A. Barsky University of California, Berkeley
This series publishes the finest works for the accomplished and aspiring graphics professional. The series includes intermediate
and advanced textbooks, graphics programming books, surveys of important new areas and methods, and reference works.
Advanced Graphics Programming Using OpenGL
Tom McReynolds and David Blythe
Digital Geometry Geometric Methods for Digital
Picture Analysis
Rienhard Klette and Azriel Rosenfeld
Digital Video and HDTV Algorithms and Interfaces
Charles Poynton
Real-Time Shader Programming
Ron Fosner
Complete Maya Programming:
An Extensive Guide to MEL and the C++ API
David Gould
MEL Scripting for Maya Animators
Mark R. Wilkins and Chris Kazmier
Digital Video and HDTV Algorithms and Interfaces
Charles Poynton
Texturing & Modeling:
A Procedural Approach, Third Edition
David S. Ebert, F. Kenton Musgrave, Darwyn Peachey,
Ken Perlin, and Steven Worley
Geometric Tools for Computer Graphics
Philip Schneider and David Eberly
Understanding Virtual Reality:
Interface, Application, and Design
William Sherman and Alan Craig
Jim Blinn’s Corner: Notation, Notation, Notation
Jim Blinn
Level of Detail for 3D Graphics:
David Luebke, Martin Reddy, Jonathan D. Cohen,
Amitabh Varshney, Benjamin Watson, and
Robert Huebner
Pyramid Algorithms: A Dynamic Programming
Approach to Curves and Surfaces for Geometric
Modeling
Ron Goldman
Non-Photorealistic Computer Graphics:
Modeling, Rendering, and Animation
Thomas Strothotte and Stefan Schlechtweg
Curves and Surfaces for CAGD: A Practical Guide,
Fifth Edition
Gerald Farin
Subdivision Methods for Geometric Design:
A Constructive Approach
Joe Warren and Henrik Weimer
Computer Animation: Algorithms and Techniques
Rick Parent
The Computer Animator’s Technical Handbook
Lynn Pocock and Judson Rosebush
Advanced RenderMan:
Creating CGI for Motion Pictures
Anthony A. Apodaca and Larry Gritz
Curves and Surfaces in Geometric Modeling:
Theory and Algorithms
Jean Gallier
Andrew Glassner’s Notebook:
Recreational Computer Graphics
Andrew S. Glassner
Warping and Morphing of Graphical Objects
Jonas Gomes, Lucia Darsa, Bruno Costa, and Luiz Velho
Jim Blinn’s Corner: Dirty Pixels
Jim Blinn
Rendering with Radiance:
The Art and Science of Lighting Visualization
Greg Ward Larson and Rob Shakespeare
Introduction to Implicit Surfaces
Edited by Jules Bloomenthal
Jim Blinn’s Corner:
A Trip Down the Graphics Pipeline
Jim Blinn
Interactive Curves and Surfaces:
A Multimedia Tutorial on CAGD
Alyn Rockwood and Peter Chambers
Wavelets for Computer Graphics:
Theory and Applications
Eric J. Stollnitz, Tony D. DeRose, and David H. Salesin
Principles of Digital Image Synthesis
Andrew S. Glassner
Radiosity & Global Illumination
François X. Sillion and Claude Puech
Knotty: A B-Spline Visualization Program
Jonathan Yen
User Interface Management Systems:
Models and Algorithms
Dan R. Olsen, Jr.
Making Them Move: Mechanics, Control, and Animation
of Articulated Figures
Edited by Norman I. Badler, Brian A. Barsky, and
David Zeltzer
Geometric and Solid Modeling: An Introduction
Christoph M. Hoffmann
An Introduction to Splines for Use in Computer Graphics
and Geometric Modeling
Richard H. Bartels, John C. Beatty, and Brian A. Barsky
TEAM LinG
Publishing Director: Diane Cerra
Publishing Services Manager: Simon Crump
Project Manager: Brandy Lilly
Editorial Coordinator: Mona Buehler
Cover Design: Dutton & Sherman Design
Text Design: Julio Esperas
Composition: Cepha Imaging Pvt. Ltd.
Illustrations: Dartmouth Publishing, Inc.
Copyeditor: Daril Bentley; Graphic World
Proofreader: Graphic World
Indexer: Graphic World
Interior printer: China Translation & Printing Services, Ltd.
Cover printer: China Tranalation & Printing Services, Ltd.
Morgan Kaufmann Publishers is an imprint of Elsevier.
500 Sansome Street, Suite 400, San Francisco, CA 94111
This book is printed on acid-free paper.
© 2005 by Elsevier Inc. All rights reserved.
Designations used by companies to distinguish their products are often claimed as trademarks or
registered trademarks. In all instances in which Morgan Kaufmann Publishers is aware of a claim,
the product names appear in initial capital or all capital letters. Readers, however, should contact
the appropriate companies for more complete information regarding trademarks and registration.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form
or by any means—electronic, mechanical, photocopying, scanning, or otherwise—without prior written
permission of the publisher.
Permissions may be sought directly from Elsevier’s Science & Technology Rights Department in Oxford,
UK: phone: (+44) 1865 843830, fax: (+44) 1865 853333, e-mail: permissions@elsevier.com.uk. You
may also complete your request on-line via the Elsevier homepage (http://elsevier.com) by selecting
“Customer Support” and then “Obtaining Permissions.”
Library of Congress Cataloging-in-Publication Data
Application Submitted
ISBN: 1-55860-659-9
For information on all Morgan Kaufmann publications,
visit our Web site at www.mkp.com or www.books.elsevier.com
Printed in China
10 9 8 7 6 5 4 3 2 1
TEAM LinG
To my friends and colleagues from Silicon Graphics; it was a fabulous time and place to
learn about 3D graphics. – DB
To Ede Forney and Harry McGinnis; you were there when it counted. – TM
TEAM LinG
Contents
Preface xxiii
Acknowledgments xxvii
Biographies xxviii
PART I
Concepts 1
CHAPTER 1
Geometry Representation and Modeling 3
1.1 Polygonal Representation 3
1.2 Decomposition and Tessellation 4
1.3 Shading Normals 8
1.3.1 Smooth Shading 9
1.3.2 Vertex Winding Order 11
1.4 Triangle Stripping 12
1.4.1 Greedy Tri-stripping 13
1.5 Vertices and Vertex Arrays 14
1.5.1 Vertex Buffer Objects 15
1.5.2 Triangle Lists 16
1.6 Modeling vs. Rendering Revisited 17
vi
TEAM LinG
Contents vii
CHAPTER 2
3D Transformations 19
2.1 Data Representation 19
2.2 Overview of the Transformation Pipeline 20
2.2.1 Object Space and the Modelview Transform 20
2.2.2 Eye Space and Projection Transform 21
2.2.3 Clip Space and Perspective Divide 22
2.2.4 NDC Space and the Viewport Transform 22
2.2.5 Window Space 23
2.3 Normal Transformation 23
2.4 Texture Coordinate Generation and Transformation 25
2.4.1 Texture Matrix 25
2.4.2 Texture Coordinate Generation 25
2.5 Modeling Transforms 27
2.6 Visualizing Transform Sequences 28
2.7 Projection Transform 30
2.8 The Z Coordinate and Perspective Projection 30
2.8.1 Z Coordinates and Fog 32
2.9 Vertex Programs 32
2.10 Summary 34
CHAPTER 3
Color, Shading, and Lighting 35
3.1 Representing Color 35
3.1.1 Resolution and Dynamic Range 36
3.1.2 Gamma 37
3.1.3 Alpha 39
3.1.4 Color Index 39
3.2 Shading 40
3.3 Lighting 43
3.3.1 Intensities, Colors, and Materials 46
3.3.2 Light Source Properties 47
TEAM LinG
viii Contents
3.3.3 Material Properties 49
3.3.4 Vertex and Fragment Lighting 50
3.4 Fixed-Point and Floating-Point Arithmetic 53
3.4.1 Biased Arithmetic 54
3.5 Summary 56
CHAPTER 4
Digital Images and Image Manipulation 57
4.1 Image Representation 57
4.2 Digital Filtering 60
4.3 Convolution 62
4.4 Images in OpenGL 63
4.5 Positioning Images 65
4.6 Pixel Store Operations 65
4.7 Pixel Transfer Operations 67
4.7.1 Scale and Bias 67
4.7.2 Pixel Mapping Operations 67
4.8 ARB Imaging Subset 68
4.8.1 Convolution 68
4.8.2 Color Matrix Transform 68
4.8.3 Histogram 69
4.8.4 MinMax 70
4.8.5 Color Tables 70
4.8.6 Blend Equation and Constant Color Blending 71
4.9 Off-Screen Processing 72
4.10 Summary 72
CHAPTER 5
Texture Mapping 73
5.1 Loading Texture Images 73
5.1.1 Texture Borders 74
5.1.2 Internal Texture Formats 75
TEAM LinG
Contents ix
5.1.3 Compressed Textures 76
5.1.4 Proxy Textures 77
5.2 Texture Coordinates 77
5.2.1 Texture Coordinate Generation and Transformation 79
5.3 Loading Texture Images from the Frame Buffer 79
5.4 Environment Mapping 80
5.4.1 Generating Environment Map Texture Coordinates 81
5.4.2 Texture Maps Used in Environment Mapping 82
5.4.3 Cube Mapping 83
5.4.4 Sphere Mapping 85
5.5 3D Texture 88
5.5.1 Using 3D Textures to Render Solid Materials 89
5.6 Filtering 90
5.7 Additional Control of Texture Level of Detail 91
5.8 Texture Objects 93
5.9 Multitexture 95
5.9.1 Multitexture Model 96
5.9.2 Multitexture Texture Environments 97
5.10 Texture Environment 98
5.10.1 Advanced Texture Environment Functionality 99
5.10.2 Fragment Programs 100
5.11 Summary 102
CHAPTER 6
Rasterization and Fragment Processing 103
6.1 Rasterization 104
6.1.1 Rasterization Consistency 105
6.1.2 Z-Fighting 105
6.1.3 Bitmaps and Pixel Rectangles 107
6.1.4 Texture, Color, and Depth Interpolation 108
6.1.5 w Buffering 109
6.2 Fragment Operations 110
6.2.1 Multisample Operations 111
6.2.2 Alpha Test 111
6.2.3 Stencil Test 111
TEAM LinG
x Contents
6.2.4 Blending 112
6.2.5 Logic Op 114
6.3 Framebuffer Operations 115
6.3.1 Accumulation Buffer 116
6.4 Summary 117
CHAPTER 7
Window System and Platform Integration 119
7.1 Renderer and Window State 120
7.2 Address Space and Threads 121
7.3 Anatomy of a Window 122
7.3.1 Overlay and Underlay Windows 122
7.3.2 Multiple Displays 123
7.4 Off-Screen Rendering 124
7.4.1 GLX Pbuffers 125
7.4.2 WGL Pbuffers 126
7.5 Rendering to Texture Maps 126
7.6 Direct and Indirect Rendering 127
CHAPTER 8
OpenGL Implementations 129
8.1 OpenGL Versions 129
8.2 OpenGL Extensions 131
8.3 OpenGL ES for Embedded Systems 131
8.3.1 Embedded Profiles 132
8.3.2 Common and Common-Lite Profiles 133
8.3.3 Safety Critical Profile 136
8.3.4 OpenGL ES Revisions 136
8.4 OpenGL Pipeline Evolution 137
8.5 Hardware Implementations of the Pipeline 138
8.5.1 Rasterization Acceleration 138
8.5.2 Primitive Setup Acceleration 141
8.5.3 Transform and Lighting Acceleration 141
8.5.4 Pipeline Balance 142
TEAM LinG
Contents xi
8.5.5 Parallelism Opportunities 142
8.5.6 Reordering the Pipeline 149
8.5.7 Mixed Software and Hardware Implementations 150
8.6 The Future 151
P A R T II
Basic Techniques 153
CHAPTER 9
Multiple Rendering Passes 155
9.1 Invariance 155
9.2 Multipass Overview 156
9.3 The Multipass Toolbox 159
9.3.1 Arithmetic Operations 159
9.3.2 Arbitrary Functions 160
9.3.3 Conditionals 161
9.3.4 Variables 162
9.3.5 Parameters 163
9.4 Multipass Limitations 165
9.5 Multipass vs. Micropass 165
9.5.1 Multitexture 166
9.6 Deferred Shading 167
9.7 Summary 167
CHAPTER 10
Antialiasing 169
10.1 Full-Scene Antialiasing 170
10.2 Supersampling 171
10.2.1 Supersampling by Overdrawing 172
10.2.2 Supersampling with the Accumulation Buffer 173
10.2.3 Multisample Antialiasing 175
10.2.4 Drawbacks 176
TEAM LinG
xii Contents
10.3 Area Sampling 177
10.4 Line and Point Antialiasing 178
10.5 Antialiasing with Textures 180
10.6 Polygon Antialiasing 181
10.7 Temporal Antialiasing 182
10.7.1 Motion Blur 183
10.8 Summary 184
CHAPTER 11
Compositing, Blending, and Transparency 185
11.1 Combining Two Images 185
11.1.1 Compositing 186
11.1.2 Compositing Multiple Images 187
11.1.3 Alpha Division 190
11.2 Other Compositing Operators 190
11.3 Keying and Matting 192
11.4 Blending Artifacts 192
11.4.1 Arithmetic Errors 192
11.4.2 Blending with the Accumulation Buffer 193
11.4.3 Approximation Errors 193
11.4.4 Gamma Correction Errors 193
11.5 Compositing Images with Depth 194
11.6 Other Blending Operations 195
11.7 Dissolves 196
11.8 Transparency 199
11.9 Alpha-Blended Transparency 200
11.9.1 Dynamic Object Transparency 202
11.9.2 Transparency Mapping 203
11.9.3 Transparency Sorting 204
11.9.4 Depth Peeling 205
11.10 Screen-Door Transparency 205
11.10.1 Multisample Transparency 207
11.11 Summary 208
TEAM LinG
Contents xiii
CHAPTER 12
Image Processing Techniques 211
12.1 OpenGL Imaging Support 211
12.2 Image Storage 212
12.3 Point Operations 213
12.3.1 Color Adjustment 213
12.3.2 Interpolation and Extrapolation 213
12.3.3 Scale and Bias 215
12.3.4 Thresholding 215
12.3.5 Conversion to Luminance 216
12.3.6 Manipulating Saturation 216
12.3.7 Rotating Hue 218
12.3.8 Color Space Conversion 219
12.4 Region-based Operations 223
12.4.1 Contrast Stretching 224
12.4.2 Histogram Equalization 224
12.5 Reduction Operations 225
12.6 Convolution 227
12.6.1 Separable Filters 227
12.6.2 Convolutions Using the Accumulation Buffer 228
12.6.3 Convolution Using Extensions 230
12.6.4 Useful Convolution Filters 230
12.6.5 Correlation and Feature Detection 233
12.7 Geometric Operations 235
12.7.1 Pixel Zoom 235
12.7.2 Scaling Using Texture Mapping 236
12.7.3 Rotation Using Texture Mapping 237
12.7.4 Distortion Correction 237
12.8 Image-Based Depth of Field 238
12.9 High Dynamic Range Imaging 241
12.9.1 Dynamic Range 241
12.9.2 Tone Mapping 242
12.9.3 Modeling Adaptation 245
12.10 Summary 245
TEAM LinG
xiv Contents
CHAPTER 13
Basic Transform Techniques 247
13.1 Computing Inverse Transforms Efficiently 247
13.2 Stereo Viewing 249
13.3 Depth of Field 252
13.4 Image Tiling 254
13.5 Billboarding Geometry 257
13.6 Texture Coordinate vs. Geometric Transformations 261
13.6.1 Direct Vertex to Texture Coordinate Mapping 263
13.6.2 Overlaying an Entire Scene with a Texture 263
13.6.3 Overlaying a Scene with an Independent Texture
Projection 264
13.7 Interpolating Vertex Components through a Perspective
Transformation 265
13.7.1 Transforming Vertices in the Application 265
13.7.2 Interpolating Vertex Components 266
13.7.3 Computing LOD 267
13.8 Summary 268
CHAPTER 14
Texture Mapping Techniques 269
14.1 Loading Texture Images into a Framebuffer 270
14.2 Optimizing Texture Coordinate Assignment 270
14.3 3D Textures 271
14.4 Texture Mosaics 274
14.5 Texture Tiling 277
14.6 Texture Paging 279
14.6.1 Texture Subimage Loading 282
14.6.2 Paging Images in System Memory 285
14.6.3 Hardware Support for Texture Paging 286
14.7 Prefiltered Textures 287
14.7.1 Computing Texel Aspect Ratios 288
TEAM LinG
Contents xv
14.8 Dual-Paraboloid Environment Mapping 291
14.8.1 The Mathematics of Dual-Paraboloid Maps 291
14.8.2 Using Dual-Paraboloid Maps 294
14.8.3 OpenGL Dual-Paraboloid Support 296
14.9 Texture Projection 296
14.10 Texture Color Coding and Contouring 298
14.11 2D Image Warping 300
14.12 Texture Animation 302
14.13 Detail Textures 306
14.13.1 Signed Intensity Detail Textures 309
14.13.2 Creating Detail Textures 311
14.14 Texture Sharpening 312
14.15 Mipmap Generation 313
14.16 Texture Map Limits 315
14.17 Summary 316
CHAPTER 15
Lighting Techniques 317
15.1 Limitations in Vertex Lighting 317
15.1.1 Static and Adaptive Tessellation 319
15.1.2 Local Light and Spotlight Attenuation 320
15.2 Fragment Lighting Using Texture Mapping 321
15.3 Spotlight Effects Using Projective Textures 322
15.4 Specular Lighting Using Environment Maps 325
15.4.1 Multitexture 326
15.5 Light Maps 327
15.5.1 2D Texture Light Maps 327
15.5.2 3D Texture Light Maps 330
15.6 BRDF-based Lighting 332
15.7 Reflectance Maps 332
15.7.1 Gloss Maps 332
15.7.2 Emission Maps 334
TEAM LinG