
3D Computer Graphics A Mathematical Introduction with OpenGL Revision draft Draft A.10.b. May 28, 2019 Samuel R. Buss May 28, 2019 This is a draft of a second edition of the book, intended for use by students in Math 155AB at UCSD during Winter-Spring 2019. This draft is available for use for your personal study or projects. Reports of errata or other corrections will be greatly appreciated. All rights reserved. Copyright, Sam Buss, 2019. ii iii To my family Teresa, Stephanie, and Ian iv Contents Table of Contents v Preface xi I Introduction 1 I.1 Points, lines and triangles . 2 I.1.1 Rectangular arrays of pixels . 2 I.1.2 Vectorgraphics .................... 4 I.1.3 Triangles . 5 I.2 Coordinatesystems ....................... 5 I.3 Points, lines and triangles in OpenGL . 7 I.3.1 Loading vertices into a VAO and VBO . 7 I.3.2 Drawing points and lines . 11 I.3.3 Drawing triangles . 14 I.3.4 Rendering with element arrays . 16 I.3.5 Differentcolorspervertex . 17 I.3.6 Face orientation and culling . 19 I.3.7 Wireframe triangles . 21 I.4 Vertexshadersandfragmentshaders . 21 I.4.1 Very simple vertex and fragment shader example . 22 I.4.2 A fragment shader modifying the color . 24 I.4.3 Flat shading . 24 I.4.4 Hiddensurfaces .................... 25 I.5 Animation with double buffering . 27 I.6 Antialiasing with supersampling . 29 I.7 Additionalexercises ....................... 29 II TransformationsandViewing 31 II.1 Transformationsin2-space . 34 II.1.1 Basic definitions . 35 II.1.2 Matrix representation of linear transformations . 38 II.1.3 Rigid transformations and rotations . 42 II.1.4 Homogeneouscoordinates. 46 II.1.5 Matrix representation of an affine transformation . 47 v II.1.6 Two dimensional transformations for computer graphics ........................ 49 II.1.7 Another outlook on composing transformations . 53 II.1.8 Two dimensional projective geometry . 55 II.2 Transformationsin3-space . 57 II.2.1 Movingfrom2-spaceto3-space . 57 II.2.2 Asolarsystemexample. 61 II.2.3 TransformationsandOpenGL . 63 II.2.4 Uniform variables and generic vertex attributes. 67 II.2.5 SolarsysteminOpenGL . 69 II.2.6 Derivation of the rotation matrix . 71 II.2.7 Euler’stheorem .................... 74 II.2.8 Three dimensional projective geometry . 77 II.3 Projectiontransformationsandperspective . 78 II.3.1 Orthographic viewing transformations . 79 II.3.2 Perspective viewing transformations . 81 II.3.3 The power of 4 4matrices ............. 86 II.3.4 Mapping lines to× lines . 87 II.3.5 Anotheruseforprojection: shadows. 88 II.3.6 z-fighting........................ 89 II.3.7 The OpenGL perspective transformations. 90 II.4 Additionalexercises ....................... 93 III The Rendering Pipeline 97 III.1 The core rendering pipeline . 97 III.2 A more detailed look at the rendering pipeline . 99 III.3 Mappingtopixels ........................ 101 III.3.1 Bresenhamalgorithm . 105 III.3.2 The perils of floating point roundoff . 108 III.4 Additionalexercises . 110 IV Lighting,Illumination,andShading 111 IV.1 ThePhonglightingmodel . 114 IV.1.1 Diffusereflection. 117 IV.1.2 Specularreflection. 118 IV.1.3 Ambient reflection and emissivity . 122 IV.1.4 Putting it together: multiple lights and colors . 122 IV.1.5 Schlick’s Fresnel term for specular reflection . 124 IV.1.6 Attenuation and spotlight effects . 125 IV.2 GouraudandPhongshading . 127 IV.3 Computingsurfacenormals. 130 IV.4 Affine transformationsandnormalvectors . 134 IV.5 LightandmaterialpropertiesinOpenGL . 137 IV.6 ShaderprogramsforPhonglighting . 137 IV.7 TheCook-Torrancelightingmodel . 142 IV.7.1 Bidirectional reflectivity . 142 vi IV.7.2 OverviewofCook-Torrance. 144 IV.7.3 The microfacet distribution term . 146 IV.7.4 The geometric surface occlusion term . 147 IV.7.5 TheFresnelterm . 153 IV.8 Additionalexercises . 155 V Averaging and Interpolation 159 V.1 Linear interpolation . 160 V.1.1 Interpolation between two points . 160 V.1.2 Weighted averages and affine combinations . 161 V.1.3 Interpolation on three points: barycentric coordinates163 V.2 Bilinear and trilinear interpolation . 171 V.2.1 Bilinear interpolation . 171 V.2.2 Inverting bilinear interpolation . 177 V.2.3 Trilinear interpolation . 182 V.3 Convexsetsandweightedaverages. 183 V.4 Interpolationand homogeneouscoordinates . 186 V.5 Hyperbolic interpolation . 188 V.6 Spherical linear interpolation . 189 V.7 InterpolationwithGLSLshaders. 192 V.8 Additionalexercises . .. .. .. .. .. .. .. .. .. 193 VI Texture Mapping 195 VI.1 Texturemappinganimage . 195 VI.1.1 Interpolatingatexturetoasurface . 197 VI.1.2 Assigning texture coordinates . 198 VI.1.3 Mipmapping and anti-aliasing . 202 VI.1.4 Stochastic supersampling . 205 VI.2 Bumpmapping ......................... 207 VI.3 Environmentmapping. 210 VI.4 TexturemappinginOpenGL . 212 VI.4.1 Loadingatexturemap . 212 VI.4.2 Specifying texture coordinates . 215 VI.4.3 Modulating color . 215 VI.4.4 Separate specular highlights . 216 VI.4.5 Managing multiple texture maps . 217 VI.4.6 Environment mapping in OpenGL . 218 VII Color 221 VII.1 Colorperception. .. .. .. .. .. .. .. .. .. .. 221 VII.2 Representationofcolorvalues . 224 VII.2.1 Additive and subtractive colors . 225 VII.2.2 RepresentationofRGBcolors . 226 VII.2.3 Hue, saturation, and luminance . 228 VII.3 GammacorrectionandsRGBcolor . 231 VII.3.1 UsingsRGBversusRGB . 232 vii VII.4 Exercises ............................. 235 VIII B´ezier Curves 237 VIII.1 B´eziercurvesofdegreethree . 238 VIII.2 DeCasteljau’smethod . 242 VIII.3 Recursivesubdivision . 243 VIII.4 PiecewiseB´eziercurves . 247 VIII.5 Hermite polynomials . 249 VIII.6 B´eziercurvesofgeneraldegree . 250 VIII.7 DeCasteljau’smethod,revisited . 255 VIII.8 Recursive subdivision, revisited . 256 VIII.9 Degreeelevation . 258 VIII.10B´eziersurfacepatches . 260 VIII.10.1Basic properties of B´ezier patches . 260 VIII.10.2Joining B´ezier patches . 263 VIII.11B´ezier curvesand surfacesin OpenGL . 266 VIII.11.1B´eziercurves. 266 VIII.11.2B´ezierpatches . 268 VIII.12RationalB´eziercurves. 270 VIII.13Conic sections with rational B´ezier curves . 272 VIII.14Surfaceofrevolutionexample . 279 VIII.15Interpolating with B´ezier curves . 282 VIII.15.1Catmull-Rom splines . 282 VIII.15.2Bessel-Overhausersplines . 283 VIII.15.3Tension-continuity-bias splines . 287 VIII.16Interpolating with B´ezier surfaces . 290 VIII.17Additionalexercises . 294 IX B-Splines 297 IX.1 UniformB-splinesofdegreethree . 298 IX.2 Non-uniformB-splines. 302 IX.3 Examplesofnon-uniformB-splines . 306 IX.4 Propertiesofnon-uniformB-splines . 312 IX.5 ThedeBooralgorithm .. .. .. .. .. .. .. .. .. 316 IX.6 Blossoms ............................. 322 IX.7 Derivatives and smoothness of B-spline curves . 327 IX.8 Knotinsertion .......................... 330 IX.9 B´ezierandB-splinecurves . 333 IX.10 Degreeelevation . .. .. .. .. .. .. .. .. .. .. 335 IX.11 RationalB-splinesandNURBS . 336 IX.12 Interpolating with B-splines . 337 IX.13 Additionalexercises . 340 viii X Ray Tracing 343 X.1 Basicraytracing......................... 344 X.1.1 Local lighting and reflection rays . 349 X.1.2 Transmissionrays . 351 X.1.3 Putting it all together . 355 X.2 Advancedraytracingtechniques . 357 X.2.1 Distributed ray tracing . 357 X.2.2 Backwardsraytracing . 366 X.3 Specialeffectswithoutraytracing . 368 XI Intersection Testing 375 XI.1 Fastintersectionswithrays. 376 XI.1.1 Rayversussphereintersections . 376 XI.1.2 Ray versus plane intersections . 379 XI.1.3 Ray versus triangle intersections . 381 XI.1.4 Ray versus convex polytope intersections . 383 XI.1.5 Ray versus cylinder intersections . 387 XI.1.6 Ray versus quadric intersections . 388 XI.1.7 Ray versus B´ezier patch intersections . 389 XI.2 Pruningintersectiontests . 389 XII Radiosity 395 XII.1 Theradiosityequations . 397 XII.1.1 Patches, light levels, and form factors . 397 XII.1.2 High-level description of the radiosity algorithm . 401 XII.2 Calculationofformfactors . 402 XII.2.1 Theraytracingmethod. 405 XII.2.2 Thehemicubemethod . 405 XII.3 Solving the radiosity equations . 408 XII.3.1 Iterativemethods . 408 XII.3.2 Jacobiiteration . 412 XII.3.3 Gauss-Seidel iteration . 413 XII.3.4 Theshootingmethod . 414 XIII Animation and Kinematics 417 XIII.1 Overview ............................. 417 XIII.1.1 Techniques evolved from traditional animation . 418 XIII.1.2 Computerized animation . 420 XIII.2 Animation of position . 422 XIII.2.1 Easein: fixedtarget. 422 XIII.2.2 Easein: movingtarget . 423 XIII.3 Representationsoforientations . 424 XIII.3.1 Rotationmatrices . 425 XIII.3.2 Yaw,pitch,androll . 426 XIII.3.3 Quaternions . 428 XIII.3.4 Theoretical development of quaternions . 430 ix XIII.3.5 Representing rotations with quaternions . 433 XIII.3.6 Quaternion and rotation matrix conversions . 435 XIII.3.7 Interpolation of quaternions . 437 XIII.4 Kinematics ............................ 439 XIII.4.1 Rigid links and joints . 440 XIII.4.2 Forwardkinematics . 441 XIII.4.3 Inverse kinematics, setting it up . 444 XIII.4.4 Inverse kinematics, finding a local solution . 447 A Mathematics Background 455 A.1 Preliminaries . 455 A.2 Vectorsandvectorproducts . 456 A.2.1 Vectors in R2 .....................456 A.2.2 Vectors in R3 .....................461 A.3 Matrices .............................463 A.3.1 Matrices and vector products in R3 ......... 464 A.3.2 Determinants, inverses, and adjoints . ..
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages554 Page
-
File Size-