Our objects so far have mostly looked as if they plan to stay home and watch

Size: px
Start display at page:

Download "Our objects so far have mostly looked as if they plan to stay home and watch"

Transcription

1 cgbook 2018/8/22 0:58 page 329 #357 CHAPTER 11 Color and Lght Our objects so far have mostly looked as f they plan to stay home and watch the game. It s tme now to dress up and go party. The goal for ths chapter s to learn how to use lght sources to llumnate a scene and complementarly defne materal propertes of objects to determne how they appear when lt. We begn wth a bref dscusson of the theory of vson and color models n Secton 11.1, learnng partcularly about the RGB color model so mportant n CG, as well as a few other models whch pop up occasonally, such as CMY, CMYK and HSV. In Secton 11.2 we study Phong s lghtng model and how t conceves of lght comng off an object as comprsed of three components ambent, dffuse and specular based on the nature of ther reflectance. Ths secton concludes wth a formula to derve the RGB ntenstes of the lght reflected at a vertex based on Phong s model. We move on to OpenGL n Secton 11.3 and see how fathfully t mplements Phong s model. And, we begn extensvely to experment and code. Secton 11.4 descrbes OpenGL s so-called lghtng model not to be confused wth Phong s lghtng model whch sets certan envronmental parameters. Drectonal lght sources, located far from the scene, and postonal lghts, located n or near t, are dscussed n Secton 11.5, as s the related noton of attenuaton of lght over dstance. Spotlghts are the topc of Secton At ths pont we have all the parts needed to formulate n Secton 11.7 the famous lghtng equaton whch OpenGL actually mplements to calculate color ntenstes at a lt vertex. We dscuss the two so-called shadng models OpenGL offers, smooth and flat, n Secton The former famlarly nterpolates the vertex colors through a prmtve, whle the latter s a somewhat dosyncratc dscrete colorng scheme. Anmaton of lght sources s the topc of Secton Specfyng approprate surface normals s crtcal to good lghtng. OpenGL can sometmes help wth automatc normals, but often the user s on her own and the task can requre a far amount of calculaton. Before we begn wth normal computaton proper, we have an ntroducton n Secton to the calculus of partal dervatves, to the extent requred to calculate tangent planes and normals to the knds of surfaces typcal n CG. The long Secton s devoted to computng and applyng surface normals to lghtng. It begns by followng the nformal taxonomy of 2D objects ntroduced n Secton 10.2, and moves on to Bézer and quadrc surfaces for whch automatc normals are avalable. Secton contans a dscusson of an alternate shadng model proposed by Phong, whch s more sophstcated (and more computaton-ntensve) than OpenGL s smooth shadng. Secton s a whole bunch of exercses. In fact, the reader wll fnd few programmng exercses before that secton as we decded to collect them n one place 329

2 cgbook 2018/8/22 0:58 page 330 #358 Chapter 11 Color and Lght after gettng most of the theory and experments out of the way. However, ths does not mean that the nterested reader should not attempt them earler. She should keep an eye on Secton as she reads to see what comes wthn reach. We conclude wth Secton Vson and Color Models We begn wth a bt of the physcs and bology underlyng color and ts percepton. Electromagnetc (EM) radaton conssts of oscllatng electrc and magnetc felds movng through space. It s produced by the moton of electrcally charged partcles. From a physcs pont of vew, EM radaton can be treated dually as waves or a stream of massless partcles called photons travelng through a vacuum at the speed of lght. EM radaton s characterzed by ts frequency or, equvalently, wavelength, the nverse of frequency. The EM spectrum conssts of EM radaton of all possble frequences. Vsble lght s a (very small) part of ths spectrum. See Fgure Hz: Rado Mcrowave Infrared Vsble UV X-ray 3*10 9 3* * * * *10 19 Gamma-ray Red O Y G B I Volet Vsble spectrum Fgure 11.1: EM spectrum ndcatng approxmate frequency ranges n Hz. Vsble lght emtted from a source s rarely pure,.e., of one partcular frequency. Rather, there s an ntensty dstrbuton across the entre vsble spectrum, and the perceved color depends on the partcular dstrbuton. Lght from a source wth an ntensty dstrbuton, for example, as n Fgure 11.2(a), would be perceved as blue, as ths color s ntensty domnates, whle one wth the dstrbuton of Fgure 11.2(b) would appear whte, because whte s a mx of all colors n the vsble spectrum. Intensty Intensty R O Y G B I V Frequency R O Y G B I V Frequency (a) Fgure 11.2: Intensty dstrbutons across the vsble spectrum: (a) appears blue (b) appears whte. (b) 330 We humans can see because of mllons of lght-senstve cells embedded n the retna of our eyes (see Fgure 11.3 for a smplfed anatomy). These cells are of two knds, rod and cone. Rod cells are senstve to low-ntensty lght, but not ts frequency, whch accounts for our nght vson, as well as the fact that we have partcular dffculty dstngushng colors n the dark. Cone cells, on the other hand, are stmulated only by farly brght lght, but can effcently dstngush frequences n the vsble lght spectrum, enablng us to perceve color. In fact, there are three knds of cones red, green and blue accordng to the color of the lght that most stmulates them. Ths s the bass of the trstmulus theory

3 optc cornea lens nerve retna pupl rs ganglon ce ll bpolar c s ell s cgbook 2018/8/22 0:58 page 331 #359 Secton 11.1 Vson and Color Models rod cone Fgure 11.3: The human eye. of human vson that perceved color s the net effect of the stmulaton of these three knds of cells RGB Color Model A consequence of the trstmulus theory s the ubqutous RGB color model : each color s represented as a sum of the three prmary colors, red, green and blue, and each wth a certan ntensty, typcally a value between 0 and 1 (for ths reason RGB s called an addtve color model ). Typcally, a color s denoted by a color tuple (r, g, b), where each component s the respectve prmary color s ntensty. Note: An ntensty dstrbuton curve, as those n Fgure 11.2, one correspondng to each prmary color, has been standardzed by the Internatonal Commsson on Illumnaton (CIE, from ts French name Commsson Internatonale de L E clarage), as also a standard to convert ntensty dstrbutons across the vsble spectrum to RGB trplets. Blue (0, 0, 1) Magenta (1, 0, 1) b G sc ray ale Cyan (0, 1, 1) Black (0, 0, 0) Green (0, 1, 0) Whte (1, 1, 1) r Red (1, 0, 0) Yellow (1, 1, 0) g (a) (b) Fgure 11.4: (a) The RGB color cube (b) Venn dagram combnng colors. The RGB color space can be depcted as a cube, called a color cube, as n Fgure 11.4(a), wth axes correspondng to R, G and B values. The orgn (0, 0, 0) of the cube corresponds to black, whle ts dagonally opposte vertex (1, 1, 1) to whte, whch, of course, s the maxmal equal mx of red, green and blue. The other three dagonally opposte pars each corresponds to a prmary color and ts complement (the complement of a color beng that whch wth t combnes to produce whte). The straght lne segment from black to whte, each pont (x, x, x) of whch has equal parts of the prmary colors, represents the gray scale. Fgure 11.4(b) s a popularly drawn Venn dagram, where dscs correspond to prmary colors and ther ntersectons are colored accordng to the mxng of the prmares. The mechancs of the addton of colors n the RGB model s nterestng. The color cube, for nstance, ndcates that an equal mx of red (whch s (1, 0, 0)) and green ((0, 1, 0)) produces yellow ((1, 1, 0)). The reason for ths s that the sensaton produced n the human eye by a mx of two lghts, one whose red frequency domnates and another whose green domnates, s smlar to that produced by a sngle lght 331

4 cgbook 2018/8/22 0:58 page 332 #360 Chapter 11 Color and Lght domnant n the yellow frequency. Ths s a consequence of how our optc nerves react to the stmulaton of partcular combnatons of cone cells, not because the frequences of red and green combne accordng to some law of physcs to produce that of yellow! The RGB model, therefore, rests more on the bology of human vson than the physcs of lght. RGB Color Model and Computer Graphcs The RGB model s mplemented n the mllons of color dsplay unts around us, ncludng computer montors, whch are almost all LCD nowadays wth a few CRT stll n use. From a CG programmer s pont of vew though, as we shall see, the exact dsplay technology s of lttle mportance. A CRT (cathode-ray tube) montor has phosphors of the three prmary colors located at each one of a rectangular array of pxels, and three electron guns that each fres a beam at phosphors of one color. A mechansm to am and control ther ntenstes causes the beams to travel together row by row, strkng successve pxels n order to excte the RGB phosphors at each to values specfed for t n the color buffer. See Fgure 11.5(a). phosphors pxel electron beams electron guns (a) (b) Fgure 11.5: (a) Color CRT montor wth electron beams amed at a pxel wth phosphors of the 3 prmares (b) A raster of pxels showng a (very low-res) rasterzed trangle. Pxel 0 Pxel 1 Pxel 2 8 bts 8 bts 8 bts 8 bts R G B A R G B A R G B A Color buffer Raster Fgure 11.6: Pxel color ntenstes read from color buffer. 332 Pxels n an LCD (lqud crystal dsplay) montor, on the other hand, each consst of three subpxels made of lqud crystal molecules, whch separately flter through lght of only one prmary color. The amount of prmary color emergng through each subpxel s controlled by an electrc charge, whose ntensty n turn s determned by the correspondng value n the color buffer. From the standpont of OpenGL and, ndeed, most CG applcatons, what s most mportant s that the pxels n a montor are, n fact, arranged n a rectangular array, called a raster, as depcted n Fgure 11.5(b), each pxel s color determned by three values, each between 0 and 1, determnng red, green and blue ntenstes, respectvely. The number of rows and columns n the raster determnes the montor s resoluton. Ths rectangular layout s the bass of the lowest-level CG algorthms, the so-called raster algorthms, whch actually select and color the pxels to represent user-specfed shapes such as lnes and trangles on the montor. Fgure 11.5(b), for example, shows the rasterzaton of a rght-angled trangle (wth terrble jagges because of the low resoluton). We ll be studyng raster algorthms n far depth ourselves n Chapter 14. Further relevant to CG programmng s that a memory locaton called the color buffer, ether n the computer s CPU or graphcs card, contans, typcally, 32 bts of data per raster pxel 8 bts for each of RGB and 8 for the alpha value (used for blendng). It s the RGB values n the color buffer whch determne the correspondng raster pxel s color ntenstes (for 8 bts) mappng lnearly to the ntensty range 0-1. Fgure 11.6 s a logcal depcton. The values n the color buffer are read by the raster at whch tme the raster s sad to be refreshed at a rate called the

5 cgbook 2018/8/22 0:58 page 333 #361 montor s refresh rate. Beyond ths, the technology underlyng a partcular dsplay, be t CRT, LCD or somethng else, matters lttle to the graphcs programmer CMY and CMYK Color Models The CMY color model, whose augmentaton CMYK s typcally used n color prntng, s a subtractve color model. CMY stands for cyan, magenta and yellow, and they are, respectvely, the complements of red, green and blue. For example, cyan reflects blue and green but absorbs (or subtracts) red. Lkewse, magenta and yellow subtract green and blue, respectvely. Accordngly, cyan, magenta and yellow are referred to as the subtractve prmares. The color cube and Venn dagram for the CMY color model are depcted n Fgure Secton 11.1 Vson and Color Models Yellow y Green Red Black Whte c Cyan Magenta m (a) Blue (b) Fgure 11.7: (a) The CMY color cube (b) Venn dagram of the CMY model. Gong between the RGB and CMY color spaces s smple: c 1 r r 1 m = 1 g and g = 1 y 1 b b 1 c m y (11.1) Ink of the color of each of the three subtractve prmares s coated as a grd of dots (called a screen) on a sheet of paper durng prntng. The relatve proportons of CMY nk at each dot determne the amounts of lght of varous frequences subtracted there; the remanng lght emerges through the nk layers and mparts to the dot ts perceved color. However, n practce, the combnaton of CMY nk to produce RGB color does not work as well as Equatons (11.1) mght suggest. The CMY pgments n prnter toner cartrdges are never pure enough that an equal mx produces 100% black or even proper shades of gray. In addton to ths techncal problem there s an economc one too: makng blacks and grays, by far the most common colors n prntng, by mxng colored nks s expensve. Modern color prnters, accordngly, supplement ther CMY nks wth a black nk so that blacks and the gray scale may be produced drectly wthout mxng, the resultng process beng called four-color prntng. The CMY model augmented wth black s called the CMYK color model (for reasons to do wth prntng termnology black s denoted by K rather than B). Converson formulae between the CMYK color space and the RGB and CMY color spaces are more complcated than those between the latter two and we ll not dscuss them here. However, drawng and mage edtng programs, such as GNU s GIMP (freeware [53]), whch offer both RGB and CMYK models wll automatcally convert between them. A practcal pont to note s that mappng from RGB to CMYK s often devcedependent and rarely 100% accurate, whch s why CMYK prnt-outs are frequently sgnfcantly dfferent from the orgnal RGB dsplay. Keep ths n mnd f you are preparng a color document on your computer to prnt out on paper. Moreover, the space of colors representable n the RGB and CMYK color models ther gamuts 333

6 cgbook 2018/8/22 0:58 page 334 #362 Chapter 11 Color and Lght are not dentcal ether, so some colors smply cannot be transferred exactly from montor to paper (or vce versa) HSV (or HSB) Color Model The RGB color model, though pretty much ngraned nto applcatons around us, s not partcularly ntutve for the mxng of colors. For example, what RGB values should an artst combne for a jungle green, sunset orange, ocean blue,...? The HSV color model was created by Alvy Ray Smth, one of the co-founders of Pxar Corporaton, n 1978 as a more user-frendly alternatve for desgners. HSV s the abbrevaton for hue, saturaton and value. The model s also called HSB, where B stands for brghtness. The HSV model gets past the problem of havng to numercally mx prmares by allowng the desgner to choose a color s coloredness (that whch we perceve as jungle green, sunset orange, ocean blue, etc.) drectly wth a sngle parameter, the hue. The hue parameter space s crcular and often called the color wheel. 0 o 240 o 120 o Trangle Green Hexagon Dodecagon Crcle (Color Wheel) Fgure 11.8: Hues on a trangle, hexagon, dodecagon and crcle (color wheel). Fgure 11.9: HSV coordnates cylnder (thanks SharkD for a Creatve Commons lcense; we modfed). 334 Here s how the color wheel s derved. See Fgure Begn wth a trangle wth corners representng the red, green and blue hues. Double the number of vertces to make a hexagon and fll n the mddle hues, yellow, cyan and magenta (e.g., yellow s an equal mx of red and green, so mdway between them). Agan, double to a dodecagon, addng new hues by nterpolatng between successve hues of the hexagon. Contnung the process leads to a contnuum of hues n a crcle. A poston on ths crcle or, the color wheel as t s called thus represents a partcular hue. Typcally, red, green and blue are located at 0, 120 and 240, respectvely. The hue parameter, though, by tself s nsuffcent to specfy a color. Two other parameters are requred as well. The saturaton of a color, typcally gven as a percentage, represents ts purty. The hgher the saturaton the rcher and more vbrant the color appears; conversely, less saturated colors (called desaturated) appear faded and graysh. The fnal parameter s value, gven as a percentage as well, representng a color s ntensty or brghtness. All three parameters are often represented n cylndrcal coordnates (see Fgure 11.9) where hue s measured along the crcular boundary of the cylnder, saturaton s the dstance from cylnder s axs, whle value s the dstance along the axs Summary of the Models In drawng applcatons the predomnant model s RGB and we ll not have use for any other through the rest of ths book. It s useful, though, to have a noddng acquantance wth models whch may occasonally pop up elsewhere. Wth CMY, CMYK and HSV we have covered the ones the user s most lkely to encounter. CMYK, n fact, becomes partcularly mportant when one goes from drawng to prntng. There are other color models not used as much, such as Lab (an opton n Adobe s Photoshop) and HLS (for hue, lghtness, saturaton). The gold standard among color models was establshed by the CIE (Internatonal Commsson on Illumnaton) n It s the CIE XYZ model, also called the CIE 1931 model, where the X, Y and Z parameters represent, respectvely, three theoretcal prmares, each correspondng to a partcular ntensty dstrbuton standardzed by

7 cgbook 2018/8/22 0:58 page 335 #363 the CIE. Although not seen n practcal nterfaces, the CIE XYZ color model s used to calbrate mplementatons of the other ones Phong s Lghtng Model A model of nteracton between lght sources and objects s called a lghtng model (or reflecton model, or llumnaton model). In 1975 Vetnamese computer scentst Phong Bu Tuong [112] nvented a partcular lghtng model, now known by hs name, whch s currently the one most wdely used n practce. Despte the subsequent development of more authentc lghtng models, e.g., Cook-Torrance [28], ray tracng, etc., Phong s has endured n popularty, especally because t delvers realstc lghtng at moderate computatonal cost. OpenGL mplements Phong s model. But, before we start codng up lght let s frst get an understandng of the model. Secton 11.2 Phong s Lghtng Model Phong Bascs In Phong s model the lght reflected off an object O s the sum of three components ambent, dffuse and specular based on the reflectance propertes of ts surface. We ll descrbe each component next before explanng how to specfy and calculate them. Ambent: Ambent reflectance models O s reflecton of background lght strkng t from multple drectons. For ths reason ambent lght s scattered equally n all drectons from the surface of O as well. See Fgure 11.10(a). O O O (a) Ambent (b) Dffuse (c) Specular Fgure 11.10: Ambent, dffuse and specular reflectance: ncdent lght drawn green, reflected red. Of the lght sources n the envronment e.g., lamps and the sun a part of the lght from each s presumed ambent n that t s scattered n the envronment, e.g., by mnute partcles such as dust, effectvely becomng part of background lght before strkng O. The drecton of the lght s source, therefore, s lost n that part of t whch s ambent. Nether does t matter where the vewer s located because of the scattered reflecton from the surface of O, presumed equal n all drectons. In practcal terms, the ambent component models that part of lght whch supples constant llumnaton throughout a scene. An example of a famlar lght source whch s mostly ambent s a tube lamp recessed behnd a frosted panel (the materal of the panel servng to scatter lght rather than let through a focused beam). In addton to the ambent parts of each lght source, there s presumed to be a global ambent lght as well, from no partcular dentfable source,.e., true background lght. For example, when modelng a scene nsde a buldng, we can adjust the global ambent to account for lght from outsde through doors and wndows, wthout tryng 335

8 cgbook 2018/8/22 0:58 page 336 #364 Chapter 11 Color and Lght to model every possble lght source such as the sun and street lghts, whch would be very complex ndeed. The total ambent component of the lght reflected from an object O s the sum of what t reflects of the ambent parts from each source, plus what t reflects of the global ambent. Informally (we ll be gettng to more precse equatons soon): Ambent Dffuse Blue Blue Green Green Red Red Red Green Blue Specular ambent reflectance from O = (reflectance of ambent part from each lght source) + reflectance of global ambent Dffuse: Dffuse reflectance specfcally models the fne-scale granness of the surface: the dffuse part of lght from a partcular source s presumed to travel n a coherent beam toward O and then be scattered equally n all drectons by dffuse reflectance from the surface of O. See Fgure 11.10(b). Therefore, the drecton of the lght source does matter n the case of dffuse reflectance, but not that of the vewer. Practcally, the dffuse component models the soft part of the lght wth lttle focus as t comes off an object, e.g., that reflected off polshed wood or slky fabrc. The total dffuse component of lght reflected from O s the sum of the reflectances of the dffuse parts from each source: dffuse reflectance from O = (reflectance of dffuse part from each lght source) Specular: Specular reflectance models the shnness of the surface: the specular part of lght from a partcular source s presumed to travel n a coherent beam toward O and then be reflected n mrror-lke manner, agan n a coherent beam, by specular reflectance from the surface of O. See Fgure 11.10(c). Both the drecton of the lght source and the vewer matter n the case of specular reflectance. Specular lght s hard lght wth a focus, e.g., that from a beam bouncng off a polshed metal surface. The total specular component of the lght reflected from O s the sum of the reflectances of the specular parts from each source: (a) Red Green Blue Specular Specular Specular Dffuse Dffuse Dffuse Ambent Ambent Ambent (b) Fgure 11.11: Orthogonal splttng of lght: (a) Reflectance followed by color (b) Color followed by reflectance. 336 specular reflectance from O = (reflectance of specular part from each lght source) Remark Because specular reflecton s mrror-lke, whle the ambent and dffuse reflectons are due to scatterng from the surface of the object, the color of specularly reflected lght depends prmarly on that of the source tself, whle those of the ambent and dffusely reflected on the natve color of the object, as well as the lght source. Remark The splt of lght nto the three components of ambent, dffuse and specular accordng to reflectance s ndependent of the splt nto the prmary color components of red, green and blue, n that each of the ambent, dffuse and specular components has RGB subcomponents and all nne subcomponents can be ndependently set. Or, one can equvalently say that each of RGB has ambent, dffuse and specular subcomponents whch can all be ndependently set. In other words, you can thnk of lght as beng splt as n Fgure 11.11(a) or Fgure 11.11(b) t does not matter. Yet another way ths s often phrased s by sayng that color and reflectance splts are orthogonal. A fnal component of lght emergng from O s not reflected. Emssve: The emssve component of lght from an object O s that whch s manufactured at O and unrelated to external lght sources or the global ambent lght. An example of an emssve object would be a lamp or the headlght of an automoble. Extremely mportant: In OpenGL mplementatons emssve lght s perceved only by the vewer and does not llumnate other objects, n other words, t does not make O a lght source for the rest of the envronment.

9 cgbook 2018/8/22 0:58 page 337 # Specfyng Lght and Materal Values OpenGL allows several lght sources to be specfed the exact number dependng on the mplementaton. For each of the, say, N specfed lght sources L, 0 N 1, the RGB ntenstes of each of ts ambent, dffuse and specular components can be set to between 0 and 1, for nne values altogether per lght source. These are wrtten, typcally, n a 3 3 lght propertes matrx: L amb, R L amb, G L amb, B L dff, R L dff, G L dff, B L spec, R L spec, G L spec, B (11.2) Smlarly, for each object O or, more precsely, each vertex V of O, one can set scalng factors, or, reflectance values as they are also called, between 0 and 1 to determne how much of each component of the ncdent lght s reflected, for agan nne values, contaned n a 3 3 materal propertes matrx: V amb, R V amb, G V amb, B V dff, R V dff, G V dff, B (11.3) V spec, R V spec, G V spec, B Settng nne color values for every vertex n a scene may seem dauntng at frst but, n fact, wll turn out not that hard because of OpenGL s behavor as a state machne, whereby property values reman same untl they are explctly altered. These nne reflectance values represent the object s color: the hgher one s, the more of the correspondng ncomng lght s reflected, so the more of that color the object appears to be. The RGB values of the global ambent lght are contaned n a 3-vector called the global ambent lght vector: Secton 11.2 Phong s Lghtng Model [globamb R globamb G globamb B ] (11.4) The RGB values of the emssve lght from a vertex V s a 3-vector called the emssve lght vector: [V emt, R V emt, G V emt, B ] (11.5) Calculatng the Reflected Lght We come now to calculatng each component of the reflected lght. Ambent Calculatng the ambent component emergng from a vertex V owng to a partcular lght source conssts smply of scalng the lght s ambent ntensty by V s ambent reflectance. So, f the orgnal ntensty of the ambent lght of some prmary color from a source L (or the global ambent) s I, then that of ts reflecton from the surface at V s I materal ambent scalng factor (11.6) The materal ambent scalng factor s the fracton of the ncdent ambent lght that the materal reflects. It s nothng but the ambent reflectance value V amb, X, where X may be R, G or B, n the frst row of the materal propertes matrx. An example wll clarfy use of the equaton. Example Say the ntenstes of the ambent lght from source L are gven by and the ambent reflectances of V by L amb, R = 0.4, L amb, G = 0.9, L amb, B = 0.2 V amb, R = 0.9, V amb, G = 0.9, V amb, B =

10 cgbook 2018/8/22 0:58 page 338 #366 Chapter 11 Color and Lght Then the ntensty of red lght emanatng from V owng to the L ambent s Lamb, R Vamb, R = 0.36 and the ntensty of green lght emanatng from V owng to the L ambent s Lamb, G Vamb, G = 0.81 and the ntensty of blue lght emanatng from V owng to the L ambent s Lamb, B Vamb, B = 0.02 Exercse Contnung the precedng f, n addton to the source L, the global ambent lght vector s [ ] calculate the RGB lght emanatng from V owng to the L ambent and the global ambent. Dffuse n p P s k Fgure 11.12: A normal vector n to a surface s at P les along the normal lne k there and s perpendcular to the tangent plane p at P. Calculaton of the dffuse component of the lght reflected from V s more complex than that of the ambent as, not only must the ncdent lght be scaled by the reflectance at V, but ts drecton taken nto account as well. The latter s done by measurng the angle between the drecton of the lght source and the normal to the surface at V. Remark A lne k s normal to a surface s at the pont P f t s perpendcular to the tangent plane p of s at P. Any non-zero vector n parallel to k s a normal vector to s at P. See Fgure (Thnk ntutvely of the tangent plane as a hard board pressed to touch s at P.) The lght source L s modeled as a pont. Further, the surface of the object O around the llumnated vertex V s assumed flat; n fact, t s taken to concde wth ts own tangent plane at V. See Fgure 11.13(a). Dffuse lght s reflected n all drectons from V. n n ht lg V cl pen tangen t plan O e (a) L l enc θ p ht lg w l w (= w/cos θ) (b) Fgure 11.13: Calculatng the dffuse component: (a) A lght pencl from a pont source L hts the surface, represented by ts tangent plane at V (b) A blow-up of the pencl. One observes from the blow-up n Fgure 11.13(b) that a pencl of lght of crosssectonal wdth w from L llumnates an area of wdth w0, whch s, typcally, greater than w. In ths fgure, θ s the angle between a drecton vector l from V toward the lght source L, called the lght drecton vector, and an outward normal vector n at V. The angle θ s called the angle of ncdence of the lght. We ask the reader to show next, by elementary trgonometry n Fgure 11.13(b), that the wdth w0 = w/ cos θ. Exercse Verfy the clam just made about the wdth of the area llumnated by a lght of wdth w beng w0 = w/ cos θ. Hnt: Consder the rght-angled trangle at the bottom of the pencl n Fgure 11.13(b) wth the rght angle marked. The length of one sde next to the rght angle s w and that of the hypotenuse w0.

11 cgbook 2018/8/22 0:58 page 339 #367 Snce the area llumnated s greater by a factor of 1/ cos θ than the cross-sectonal area of the lght pencl, the ntensty of the lght s dmnshed by a factor of 1/ cos θ,.e., from I to I/(1/ cos θ) = cos θ I. Accordngly, f the orgnal ntensty of the dffuse lght of some prmary color emanatng from the lght source L s I, then that of ts reflecton from the surface of O at V s cos θ I materal dffuse scalng factor (11.7) The materal dffuse scalng factor, gven by the values V dff, X, where X s R, G or B, n the second row of materal propertes matrx, determnes the fracton of the ncdent dffuse lght the materal reflects. Secton 11.2 Phong s Lghtng Model Example Say the ntenstes of the dffuse lght from source L are gven by L dff, R = 0.3, L dff, G = 1.0, L dff, B = 1.0 and the dffuse reflectances of a vertex V by V dff, R = 0.8, V dff, G = 1.0, V dff, B = 0.8 and that the angle θ of ncdence at V s 60. Then the ntensty of red lght emanatng from V owng to the L dffuse s cos θ L dff, R V dff, R = = 0.12 Lkewse, the ntensty of the green lght emanatng from V owng to the L dffuse s cos θ L dff, G V dff, G = 0.5 and the ntensty of the blue lght emanatng from V owng to the L dffuse s cos θ L dff, B V dff, B = 0.4 Remark The relatonshp that the ntensty of the reflected lght vares as the cosne of the angle of ncdence s known as Lambert s law. It s Lambert s law whch explans why early mornngs and late evenngs, when the sun s lower n the sky, are cooler and darker than md-day. Specular For specular lght, as n the case of dffuse lght, the lght source L s modeled as a pont and the surface of O dentfed wth ts tangent plane at the llumnated vertex V. An outward normal vector to the surface of O at V s n. In case of specular lght, though, unlke for dffuse lght, the eye comes nto the equaton. It s modeled as the pont E. E e ψ r s E n L e = r n = s φ l ψ = 0 φ = 0 l L V (a) O tangent plane V (b) Fgure 11.14: Calculatng the specular component: (a) The lght drecton vector l, eye drecton vector e, halfway vector s, normal vector n and reflecton vector r (b) The specal case when reflecton s n the drecton of the eye. (Double arcs ndcate equal angles.) 339

12 cgbook 2018/8/22 0:58 page 340 #368 Chapter 11 Color and Lght The drecton vector from V toward the lght source L s l and the drecton vector from V toward the eye E s e. Further, let s be a vector, called a halfway vector, whch bsects the angle between l and e. The angle between s and the outward normal vector n s φ. See Fgure 11.14(a) (gnore r and ψ for the moment). We ll next state a relatonshp between the ntensty of the reflected specular lght and that of the ncdent whch may seem unntutve at frst, but motvaton wll soon be apparent: If the ntensty of the specular lght of some prmary color emanatng from the lght source L s I, then that of ts reflecton from the surface of O at V s cos f φ I materal specular scalng factor (11.8) where f 0 s a scalar, called the shnness exponent; φ s the angle between the halfway vector and the outward normal vector; the materal specular scalng factor s a value V spec, X read from the materal propertes matrx, determnng the fracton of the ncdent specular lght the materal reflects. Here s what s happenng. If the surface of O s perfectly mrror-lke, then a ray of lght from L to V reflects accordng to the laws of reflecton, whch say that the normal to O at V, the ncdent ray and the reflected ray all le on the same plane and, moreover, that the ncdent and reflected rays make the same angle wth the normal. So, n the case of a perfect mrror, f the eye E s located n the drecton of reflecton, gven by the reflecton vector r, then t perceves all of the ncdent lght from L, f not no lght at all. Now, see agan Fgure 11.14(a) for r. The fgure should really have double arcs between the par r and n and the par l and n, as well, to ndcate equal angles, but that would have made t too cluttered. Say, ψ s the angle the reflecton vector makes wth the eye drecton vector e, as depcted n Fgure 11.14(a). Now, Fgure 11.14(b) shows the partcular case of the general Fgure 11.14(a) when O s a perfect mrror and the eye s actually stuated n the drecton of reflecton, so that ψ = 0. Observe, n ths case, that the halfway vector s algned wth the normal, n other words, φ = 0 as well. Most real surfaces, however, are not perfectly mrror-lke and do not reflect lght only along the drecton of reflecton, but, rather, spread t about that drecton wth an ntensty whch dmnshes wth ncreasng angle. In other words, maxmum ntensty s perceved by the vewer n a confguraton as n Fgure 11.14(b); nevertheless, even n a general confguraton as n Fgure 11.14(a), the eye receves lght, though, wth ntensty nversely related to ψ. Ths suggests that the ntensty of specular reflecton be modeled by the formula angular attenuaton factor I materal specular scalng factor (11.9) 1 f = f =5 ψ f =1 π/2 Fgure 11.15: Graphs of cos f ψ for dfferent values of f (not exact plots). 340 where the angular attenuaton factor, n fact, s n nverse relatonshp wth ψ. Phong suggested the angular attenuaton factor cos f ψ, where the exponent f s larger the more mrror-lke (.e., shny) the surface s. Hs consderatons were emprcal rather than based on actual physcs. In partcular, cos ψ s a functon of ψ whch s at ts maxmum of 1 when ψ = 0 and drops off as ψ ncreases, behavor expected of the angular attenuaton factor. The functon cos f ψ shows also the same behavor, but more markedly, as f ncreases. In partcular, the larger the value of f the more rapd the drop from the value of 1 as ψ ncreases from 0. See Fgure Practcally, the shner the surface the more rapdly the lght dmnshes away from the drecton of reflecton. The angle ψ s often replaced by φ, the angle between the halfway vector s and the normal vector n, because φ s easer to compute and because t s legtmate to do so gven the followng lnear relaton between the two. Example Show that ψ = 2φ. Answer: Label the angles from the tangent plane to the lght drecton, the reflecton and eye drecton vectors θ 1, θ 2 and θ 3, respectvely, as n Fgure

13 cgbook 2018/8/22 0:58 page 341 #369 The angle to the halfway vector, then, s (θ1 + θ3 )/2, mplyng that the angle Secton 11.2 between the halfway vector and the normal s φ = (θ1 + θ3 )/2 π/2. Phong s Lghtng By laws of reflecton, the angle between the lght vector and the normal, whch Model r s n L s π/2 θ1, s the same as the angle between the normal and the reflecton vector, whch s θ2 π/2. Now, π/2 θ1 = θ2 π/2 gves θ2 = π θ1, whch, n turn, l E mples that the angle between the eye drecton vector and the reflecton vector s e θ ψ = θ3 θ2 = θ3 (π θ1 ) = θ1 + θ3 π. That ψ = 2φ now follows. θ 3 θ2 1 V tangent Gven the relatonshp between φ and ψ contaned n the precedng example, plane f f substtutng cos φ for cos ψ as the angular attenuaton factor n Equaton (11.9) makes no qualtatve dfference. The result of the substtuton, n fact, s Fgure 11.16: Provng Equaton (11.8), whch s now fully justfed. ψ = 2φ. Remark The alert reader may have spotted the tact assumpton n the above, partcularly, Fgures 11.14(a) and 11.16, that the eye, and so the eye drecton vector as well, les on the same plane as the normal and the lght; obvously, n general t does not have to. However, we ll leave the mathematcally-nclned to ponder f Equaton (11.8) s stll an acceptable approxmaton n all cases. Keep n mnd that ths equaton s meant to capture plausbly the effect of specular lghtng, not necessarly exactly. The stll skeptcal reader mght want to defer judgement untl Secton 11.3 when we run experments actually mplementng OpenGL s lghtng model. Example Gve a formula for the halfway vector s n terms of the lght drecton vector l and the eye drecton vector e from V, whch are, of course, the two vectors that s bsects. Assume that both l and e are of unt length. Gve s as a unt vector as well. Answer : See Fgure 11.17, where l = OA, e = OB, and where l + e s drawn wth the help of the parallelogram law of addton of vectors. Snce l = e = 1, all four sdes of the parallelogram OACB are of unt length as well. A consequence s that correspondng sdes of the trangles OAC and OBC are of equal lengths. The two trangles are, therefore, congruent, so AOC = BOC. One concludes that the vector l + e bsects l and e. Accordngly, the unt halfway vector s= C l+e A B e l O Fgure 11.17: The vector l + e bsects l and e. l+e (provded that l + e s not the zero vector) l + e Remark When a vector u s used to represent a drecton, so that ts magntude s not of mportance, t s often convenent to scale t to unt length, a step called normalzng u. Normalzaton of a non-zero vector u (note that a vector representng a drecton cannot be zero) conssts smply of dvdng t by ts length, n other words, replacng u by u/ u. Exercse Gve a smple formula, n an OpenGL settng, for the eye drecton vector e from a vertex V, denotng V s poston vector by V too. Accordngly, rewrte the formula for the halfway vector of the precedng example n terms of l and v. Hnt: The OpenGL eye s always at the orgn, so e s the vector from V to the orgn, whch s just the opposte of the vector from the orgn to V. It s nterestng that calculaton of the reflected lght never actually requred determnaton of the reflecton vector r tself. It s not hard though to fnd r as we see next. Exercse Suppose that n s the unt (outward) normal vector and l the unt lght drecton vector at a vertex V. Prove that the unt vector r n the drecton of reflecton s gven by the equaton r = 2(n l)n l (11.10) 341

14 cgbook 2018/8/22 0:58 page 342 #370 Chapter 11 Color and Lght Part answer: Accordng to the laws of reflecton we have to verfy that r les on the plane of l and n and makes the same angle wth n as l. We must also prove that r s of unt length. That r les on the plane of l and n follows from ts formula above, because of the lnear dependence of r on l and n. Now r 2 = r r = (2(n l)n l) (2(n l)n l) = 4(n l) 2 4(n l) 2 + l l = l 2 = 1 provng that r ndeed s a unt vector. We ll leave the reader to prove that r makes the same angle wth n as l makes by computng ts dot product wth n. Example Say the ntenstes of the specular lght from source L are gven by L spec, R = 1.0, L spec, G = 1.0, L spec, B = 1.0 and the specular reflectances of a vertex V by V spec, R = 0.0, V spec, G = 1.0, V spec, B = 0.6 and that the angle φ between the halfway vector and the outward normal vector at V s 60 and that the shnness exponent s 2.0. Then the ntensty of the red lght emanatng from V owng to the L specular s cos f φ L spec, R V spec, R = = 0.0 Lkewse, the ntensty of the green lght emanatng from V owng to the L specular s cos f φ L spec, G V spec, G = 0.25 and the ntensty of the blue lght emanatng from V owng to the L specular s cos f φ L spec, B V spec, B = 0.15 To summarze, then, for each vertex V and each lght source L: (a) Reflected ambent lght from V s the ambent component of lght from L scaled by the ambent reflectance at V (Equaton (11.6)). (b) Reflected dffuse lght from V s the dffuse component of lght from L scaled by both the dffuse reflectance at V and the cosne of the angle of ncdence at V (Equaton (11.7)). (c) Reflected specular lght from V s the specular component of lght from L scaled both by the specular reflectance at V and the cosne of the angle between the halfway vector and the normal at V rased to a power equal to the shnness exponent at V (Equaton (11.8)) Frst Lghtng Equaton At the end of the day we need, of course, a color vector for each vertex V n the scene, n other words, values for R, G and B at V, so that OpenGL can color trangles n the scenes by nterpolatng ther vertex color values nto ther nteror, as we learned how to do n Chapter 7. The color vector at vertex V s obtaned by addng for each of R, G and B contrbutons of the ambent, dffuse and specular reflected lght at V due to all lght sources plus the emtted lght at V. The correspondng equaton, the so-called lghtng equaton, s straghtforwardly wrtten from the formulae of the last secton. Assume that we are gven the values of the lghtng propertes matrx (11.2) for each of the N lght source L, 0 N 1, the materal propertes matrx (11.3)

15 cgbook 2018/8/22 0:58 page 343 #371 for the vertex V, the global ambent lght vector (11.4), as well as the emssve lght vector (11.5) at V. Further, denote the normalzed lght drecton and halfway vectors correspondng to lght source L at vertex V by l and s, respectvely. Denote the normalzed outward surface normal vector at V by n and ts shnness exponent by f. Here, then, s the lghtng equaton gvng the color ntensty V X at V, where X may be any of RGB: Secton 11.2 Phong s Lghtng Model V X = V emt, X + globamb X V amb, X + N 1 ( L amb, X V amb, X + =0 max{l n, 0} L dff, X V dff, X + (max{s n, 0}) f L spec, X V spec, X ) (11.11) Notes: 1. The dot product of two unt vectors gves the cosne of the angle between them. 2. The reason for the max{, 0} terms s not to allow a negatve multpler, whch would mply the physcally mpossble phenomenon of lght beng subtracted. For example, l n s negatve when the angle between l and n s greater than 90, whch means that the lght source L s behnd the surface on whch V s located, contrbutng zero lght, rather than negatve lght. 3. If the RHS sums to more than 1, for any of X equal to R, G or B, then t s clamped to 1. The lghtng equaton smply collects the components that we have already dscussed separately. The frst summand on the RHS s the emssve component; the second the global ambent scaled by the ambent reflectance; the thrd s a summaton over the N lght sources of the values of the reflected ambent, dffuse and specular components. Observe, as well, that all the varables on the RHS are explctly programmer-specfed, except l and s, whch are computed by OpenGL from the postons of the lght sources (whch, of course, the programmer specfes). Equaton (11.11) s actually a frst draft. The fnal lghtng equaton of OpenGL, whch we ll see soon, enhances t by takng nto account the attenuaton of lght over dstance, as well as the spotlght effect, where lght from a source emerges as a cone, rather than n all drectons. Exercse There are two lght sources, L 0 and L 1, the respectve values of whose lghtng propertes matrces are and The materal propertes matrx at a vertex V s Furthermore, the shnness exponent of the surface at V s 2.0, the unt outward normal vector at V s [ ] T and the emssve lght vector at V s [ ] T 343

16 cgbook 2018/8/22 0:58 page 344 #372 Chapter 11 Color and Lght The poston vectors of L 0, L 1, V and the eye are, respectvely, [ ] T, [ ] T, [ ] T and [ ] T The global ambent lght vector s [ ] T Fll out color values at V n the table below. Emsson Global Ambent Ambent Dffuse Specular Total (color vector at V) R G B L l V s 1 s 2 Fgure 11.18: Lght ray from V toward L, along l, s blocked by s 2. Remark Important! Phong s lghtng model s local. As you can see from Equaton 11.11, the color at a vertex V depends only on the external lght source values, as well as values, partcularly, materal propertes and the normal vector, at V tself. Other vertces n the scene do not enter nto the equaton at all. So, for example, no account s taken of whether V s obscured from a lght source by another object (shadows), or of lght that strkes V not drectly from a lght source but havng bounced off other objects (reflecton and secondary lghtng). Consder Fgure 11.18: the color at vertex V s determned by pluggng n the values of the varables on the rght of Equaton In partcular, the lght drecton vector l,.e., the unt vector n the drecton from V to the lght source L, s calculated by OpenGL smply from the coordnates of V and L wthout checkng that an actual ray from V along l, n fact, s blocked by the surface s 2, meanng that V s n s 2 s shadow. One sees then that ths knd of oblvous use of Equaton 11.11, effectvely, lghts s 1 as f s 2 dd not exst! Colloqually, local models lke OpenGL do not consder object-object lght nteracton, only lght-object. If the programmer wants shadows, reflectons and such, then she ll have to code them n herself, e.g., as n ballandtorusltorthoshadowed.cpp, whch we frst ran way back n Secton 4.7.2, where smple-mnded shadowng s seen wth the use of degenerate scalng. We ll have more to say about applyng secondary effects ourselves as we go along. Addtonally, we wll dscuss two global lghtng models, dfferent from Phong s, vz., ray tracng and radosty, where shadows, reflectons and other secondary effects are automatcally captured, n Chapter OpenGL Lght and Materal Propertes 344 Tme for code! The mappng from Phong s lghtng model to OpenGL syntax s pretty much one-to-one. For each lght source the user defnes the values n the lghtng propertes matrx (11.2), as also the values n the materal propertes matrx (11.3) for each vertex. The global ambent vector (11.4) s user-defned as well. The user, too, defnes the shnness exponent f, the emsson color vector (11.5) and, very mportantly, the normal vector at each vertex. If you are worryng that that s a lot of values to specfy to lght a scene, don t! Remember that OpenGL s a state machne, so materal propertes whch are state varables persst n ther current settng untl explctly changed, makng t convenent for the programmer to apply the same propertes to all vertces of a sngle object. Moreover, OpenGL has sensble defaults for values the programmer doesn t care to defne.

17 cgbook 2018/8/22 0:58 page 345 #373 Exercse Show that the lght and materal propertes noted above are suffcent, n fact, for OpenGL to compute the color vector at every vertex usng lghtng equaton (11.11). Hnt: OpenGL can compute the drecton vector at a vertex V toward lght source L from the coordnates of V and L; t can compute the eye drecton vector from the coordnates of V and the eye E (the latter, typcally, beng (0, 0, 0)); the halfway vector, of course, can be derved from the lght and eye drecton vectors. Secton 11.3 OpenGL Lght and Materal Propertes Experment Run sphereinbox1.cpp. Press the up-down arrow keys to open or close the box. Fgure s a screenshot of the box partly open. We ll use ths program as a runnng example to explan much of the OpenGL lghtng and materal color syntax. End Lght Propertes Propertes of lght sources are set by statements of the form: gllght*(lght, parameter, value) where lght s the label of the lght source (vz., GL LIGHT0, GL LIGHT1,...) and ts partcular parameter set to value. The propertes of the sngle lght source of sphereinbox1.cpp are specfed by the followng statements n the setup() routne: gllghtfv(gl LIGHT0, GL AMBIENT, lghtamb); gllghtfv(gl LIGHT0, GL DIFFUSE, lghtdfandspec); gllghtfv(gl LIGHT0, GL SPECULAR, lghtdfandspec); gllghtfv(gl LIGHT0, GL POSITION, lghtpos); The values of GL AMBIENT, GL DIFFUSE and GL SPECULAR lghtamb, lght- DfAndSpec and (repeat) lghtdfandspec, respectvely, above are 4-vectors representng RGBA components. The fourth component, the alpha value, should always be 1.0 for a lght source. Typcally, the dffuse and specular color vectors,.e., the values of the GL DIFFUSE and GL SPECULAR parameters, respectvely, are set dentcally to values perceved as the actual color of the lght source. So, these values, partcularly, {1.0, 1.0, 1.0, 1.0} of lghtdfandspec for the lght source of sphereinbox1.cpp make t a brght whte. It s smplfyng, as well, to consoldate all lght source ambents ther GL AMBIENT values nto the global ambent; n other words, set lght source ambent colors all to 0.0 and adjust the one global ambent lght vector. We follow ths approach n all our lt programs, explanng the value set {0.0, 0.0, 0.0, 1.0} of lghtamb n sphereinbox1.cpp. The value {x, y, z, w} of GL POSITION specfes the locaton [x y z w] T of the lght source n homogeneous coordnates. If w 0 then the lght source s sad to be postonal and s located at world coordnates [x/w y/w z/w] T Fgure 11.19: Screenshot of sphereinbox1.cpp. The value of lghtpos beng {0.0, 1.5, 3.0, 1.0}, the sngle postonal lght source of sphereinbox1.cpp s at [ ] T, whch s just above and some ways n front of the box. We ll see what happens f w = 0 n Secton 11.5 when we dscuss drectonal lght sources. Note that no vsble object s ever created by OpenGL at the locaton of a lght source! Ths locaton s smply a pont used for the purpose of lghtng calculaton. If you want the lght to appear to be from a lamp or car headlght or some such source you ll have to model that object and poston t yourself. Global ambent lght n sphereinbox1.cpp s set wth the statement 345

18 cgbook 2018/8/22 0:58 page 346 #374 Chapter 11 Color and Lght gllghtmodelfv(gl LIGHT MODEL AMBIENT, globamb); n the setup() routne, where the second parameter globamb ponts to the global ambent vector, whose value s the mld whte {0.2, 0.2, 0.2, 1.0}. Fnally, mnd that lghtng calculaton s enabled wth the call glenable- (GL LIGHTING) and ndvdual lghts wth calls to glenable(gl LIGHT). Exercse Show that nothng, n fact, s lost accordng to the frst lghtng equaton (11.11) by settng all lght source ambent colors to 0.0. In partcular, prove that, however the lght source ambents are ntally set, they can all be reset to 0.0 and the global ambent adjusted accordngly so that the color computed at each vertex by (11.11) remans unchanged Materal Propertes Materal propertes at a vertex are set by statements of the form: glmateral*(face, parameter, value) where the parameter of face s set to value. The value of face can be GL FRONT, GL BACK or GL FRONT AND BACK for both faces. Materal propertes of the box of sphereinbox1.cpp are specfed by the followng statements n the drawscene() routne: glmateralfv(gl FRONT AND BACK, GL AMBIENT AND DIFFUSE, matambanddf1); glmateralfv(gl_front AND BACK, GL SPECULAR, matspec); glmateralfv(gl FRONT AND BACK, GL SHININESS, matshne); In fact, these propertes apply to all eght vertces of the box because no property s changed untl after the drawng of the box s complete. As for a lght source, the values of GL AMBIENT, GL DIFFUSE and GL SPECULAR for a materal are 4-vectors representng RGBA components. The A, or alpha, components are currently all set to the default value of 1.0 they pertan to blendng whch s not done n ths chapter. Typcally, the ambent and dffuse color vectors are set dentcally to values to be perceved as an object s natve color. OpenGL makes t convenent to do so va the GL AMBIENT AND DIFFUSE parameter, whch, n fact, s how the ambent and dffuse values of the box are both set to the red {0.9, 0.0, 0.0, 1.0} contaned n matambanddf1. However, the ambent and dffuse values may be set separately as well usng GL AMBIENT and GL DIFFUSE. As specular lght s obtaned from reflecton from the lght source, t s reasonable to set an object s GL SPECULAR value ether to a whte {1.0, 1.0, 1.0, 1.0} fully reflectng the ncdent specular lght, as for the box, the value beng n matspec, or a shade of gray {γ, γ, γ, 1.0}, equally dmnshng each color component. The value of GL SHININESS 50.0 for the box, contaned n matshne s, of course, the shnness exponent f of the frst lghtng equaton (11.11). Its value must be n the range [0.0, 128.0]. The default s 0.0, whch causes no angular attenuaton of specular reflectance. The emssve color at a vertex can be set usng the GL EMISSION parameter, but we choose to leave t at the default of {0.0, 0.0, 0.0, 1.0}, n other words, there s no emsson at any vertex n sphereinbox1.cpp. Fnally, remanng s to defne the normals at the eght vertces of the box. In fact, these are contaned n the global normals[] array and ponted to by a normals vertex array as s seen from the two statements 346 glenableclentstate(gl_normal_array);... glnormalponter(gl_float, 0, normals);

19 cgbook 2018/8/22 0:58 page 347 #375 n the drawng routne. We ll be dscussng our choce of the partcular normal values for the box s vertces as part of a systematc dscusson of normals n Secton Exercse (Programmng) What are the materal ambent, dffuse, specular and emssve values and the shnness exponent of the sphere of sphereinbox1.cpp? Note that OpenGL automatcally supples normals for FreeGLUT objects. Remark Our conventons essentally reduce the specfcaton of the nne components each of the lght propertes and materal propertes matrces to that of just three, n partcular, one RGB trple for ether. Partcularly, for each lght source, we set the dffuse and specular values to one dentcal RGB trple, leavng the ambent black (only the global ambent beng adjusted). For each vertex, the ambent and dffuse values are set to the same RGB trple, whle the specular s made whte, reflectng all specular lght (though ths mght be adjusted to a shade {γ, γ, γ, 1.0} of gray, equally scalng each specular component). Remark As stated at the start of the chapter, programmng exercses are mostly collected n Secton However, ths should not deter the reader from vstng that secton as she reads and attemptng those whch seem wthn reach. Secton 11.3 OpenGL Lght and Materal Propertes Expermentng wth Propertes The two programs lghtandmateral1.cpp and lghtandmateral2.cpp allow the user to experment wth varous materal and lght propertes. Both show a blue ball lt by two lghts, one whte and one green, whose postons are ndcated by small wre spheres. Fgure shows screenshots of both the programs. (a) (b) Fgure 11.20: Screenshots of (a) lghtandmateral1.cpp (b) lghtandmateral2.cpp. Usng the frst program one can change materal propertes of the blue ball, as well as move t. The second program, on the other hand, allows propertes of the whte lght to be controlled, as also those of the global ambent, and enables the user to rotate the whte lght n addton to movng the blue ball. Text messages show property values. Let s take a quck tour of the two before expermentng wth propertes. Experment Run lghtandmateral1.cpp. The ball s current ambent and dffuse reflectances are dentcally set to a maxmum blue of {0.0, 0.0, 1.0, 1.0}, ts specular reflectance to the hghest gray level {1.0, 1.0, 1.0, 1.0} (.e., whte), shnness to 50.0 and emsson to zero {0.0, 0.0, 0.0, 1.0}. Press a/a to decrease/ncrease the ball s blue Ambent reflectance and d/d to change lkewse ts Dffuse reflectance. Pressng s/s decreases/ncreases the gray level of ts Specular reflectance. Pressng h/h decreases/ncreases ts shnness, whle pressng e/e decreases/ncreases the blue component of the ball s Emsson. The page up and down keys move the ball whle r returns t to ts orgnal poston. End 347

20 cgbook 2018/8/22 0:58 page 348 #376 Chapter 11 Color and Lght Experment Run lghtandmateral2.cpp. The whte lght s current dffuse and specular are dentcally set to a maxmum of {1.0, 1.0, 1.0, 1.0} and t gves off zero ambent lght. The green lght s attrbutes are fxed at a maxmum dffuse and specular of {0.0, 1.0, 0.0, 1.0}, agan wth zero ambent. The global ambent currently s a low ntensty gray at {0.2, 0.2, 0.2, 1.0}. Press w to toggle the Whte lght off and on and g to toggle lkewse the Green lght. Press d/d to decrease/ncrease the gray level of the whte lght s Dffuse and specular ntensty (the ambent ntensty never changes from zero). Pressng m/m decreases/ncreases the gray ntensty of the global ambent. Move the ball wth the page up and down keys. Rotate the whte lght about the ball s orgnal poston by pressng the arrow keys (t does not follow the ball f the latter s moved). The program has added functonalty whch we ll need later. End (a) (b) Fgure 11.21: Screenshots of lghtandmateral1.cpp wth specular reflectance value (a) 1.00 (b) Experment Run lghtandmateral1.cpp. Reduce the specular reflectance of the ball. Both the whte and green hghlghts begn to dsappear, as t s the specular components of the reflected lghts whch appear as specular hghlghts (or, glnt). See Fgure End Fgure 11.22: Screenshot of lghtandmateral1.cpp wth shnness exponent Exercse (Programmng) The specular hghlght s sharpened or blunted, respectvely, by ncreasng or decreasng the shnness exponent (see Fgures and 11.23). Why? Hnt: The hgher the shnness exponent the more rapdly the specular lght dmnshes as the reflecton vector rotates away from the eye drecton (recall the defnton of the angular attenuaton factor cos f ψ n Secton ). Fgure 11.23: Screenshot of lghtandmateral1.cpp wth shnness exponent (a) (b) (c) Fgure 11.24: Screenshots of lghtandmateral1.cpp: (a) Only ambent reflectance (b) Ambent and dffuse (c) Ambent, dffuse and specular.

21 cgbook 2018/8/22 0:58 page 349 #377 Experment Restore the orgnal values of lghtandmateral1.cpp. Reduce the dffuse reflectance gradually to zero. The ball starts to lose ts roundness and brghtness untl t looks lke a flat glassy dsc. The reason for ths s that ambent ntensty, whch does not depend on eye or lght drecton, s unform across vertces of the ball and cannot, therefore, provde the percepton of depth that obtans from a contrast n color values across the surface. Dffuse lght, on the other hand, whch vares n ntensty across the surface dependng on how the normal turns, cues the vewer to depth or 3Dness. Even though there s a specular hghlght, senstve to both eye and lght drecton, t s too localzed to provde much depth contrast. Reducng the shnness does spread the hghlght but the effect s not a realstc percepton of depth. Fgure shows the ball startng wth only ambent reflectance, then successvely addng n dffuse and specular. End Remark Watch an artst sketch a portrat and you ll see how carefully she shades the base of the nose where t meets the face. Ths s precsely to apply dffuse lght to make the nose appear to rse from the face. Moral: Dffusve lght lends three-dmensonalty. Secton 11.3 OpenGL Lght and Materal Propertes (a) (b) Fgure 11.25: Screenshots of lghtandmateral1.cpp wth ambent reflectance value (a) 1.00 (b) Experment Restore the orgnal values of lghtandmateral1.cpp. Now reduce the ambent reflectance gradually to zero. The ball seems to shrnk! See Fgure Ths s because the vertex normals rotate away from the lght drecton (and vewer) near the vsble edges of the ball, scalng down the dffuse reflectance there (recall the cos θ term n the dffusve reflectance equaton (11.7)). The result, wth no ambent lght to offset the reducton n dffuse, s that the ends of the ball are dark. End Fgure 11.26: Screenshot of lghtandmateral1.cpp wth ambent and dffuse reflectances both Moral: Ambent lght provdes a level of unform lghtng over a surface. Experment Restore the orgnal values of lghtandmateral1.cpp. Reduce both the ambent and dffuse reflectances to nearly zero. See Fgure It s lke the cat dsappearng, leavng only ts grn! End Moral: Specular lght s for hghlghts and not much else. Exercse (Programmng) Restore the orgnal values of lghtand- Materal1.cpp. Fgure 11.27: Reduce all three of the ball s dffuse, ambent and specular reflectances to nearly Screenshot for zero and rase ts emssve lght ntensty. It does appear to glow but also appears flat. Exercse See Fgure Why? 349

22 cgbook 2018/8/22 0:58 page 350 #378 Chapter 11 Color and Lght Experment Run lghtandmateral1.cpp wth ts orgnal values. Wth ts current hgh ambent, dffuse and specular reflectances the ball looks a shny plastc (Fgure 11.28(a)). Reducng the ambent, dffuse and specular reflectances somewhat makes for a heaver and less plastc appearance (Fgure 11.28(b)). Restorng the ambent and dffuse to hgher values, but reducng the specular reflectance makes t a less shny plastc (Fgure 11.28(c)). Low values for all three of ambent, dffuse and specular reflectances gve the ball a somewhat wooden appearance (Fgure 11.28(d)). But, of course, the eyes of the beholder have fnal say, whch means that color and lght are art as much as scence. End Fgure 11.29: Screenshot of lghtandmateral2.cpp wth the whte lght s dffuse and specular values both 0.1. (a) (b) (c) (d) Fgure 11.28: Screenshots of lghtandmateral1.cpp wth ambent, dffuse and specular reflectance values: (a) 1.00, 1.00, 1.00 (b) 0.75, 0.75, 0.5 (c) 1.0, 1.0, 0.25 (d) 0.6, 0.6, 0.1. Fgure 11.30: Screenshot of lghtandmateral2.cpp: whte lght on, green off. Experment Run lghtandmateral2.cpp. Reduce the whte lght s dffuse and specular ntensty to nearly 0. The ball becomes a flat dull blue dsc wth only the green hghlght promnent (Fgure 11.29). Ths s because the ball s dffuse (and ambent) s blue and cannot reflect the green lght s dffuse component, causng the ball thereby to lose almost all dffuse lght and, consequently, three-dmensonalty. Rasng the whte global ambent brghtens the ball, but t stll looks flat n the absence of dffusve lght. End Exercse (Programmng) Explan the sgnfcant dfference n what s seen when the whte lght s on and the green off (Fgure 11.30) n lghtandmateral2.cpp versus oppostely when the whte lght s off and the green on (Fgure 11.31) Color Materal Mode Fgure 11.31: Screenshot of lghtandmateral2.cpp: whte lght off, green on. Remember glcolor*() whch we used to set vertex color n the dark days before there were lght sources? Now that glmateral*() allows us to set all sorts of materal propertes, ncludng color, per vertex, t seems there s no use any more for glcolor*(). Well, t turns out that the good folk at OpenGL Inc. found a way to keep t on the payroll. Here s how. Suppose you re n the not uncommon stuaton colorng a scene where only a partcular color attrbute, say the ambent and dffuse reflectances of the front faces, changes from one object to the next, other attrbutes remanng constant. What you can do n ths case, nstead of repeatedly callng glmateralfv(gl FRONT, GL AMBIENT AND DIFFUSE, value), s to: 1. Enable the so-called color materal mode wth a call to glenable(gl COLOR - MATERIAL) Call glcolormateral(gl FRONT, GL AMBIENT AND DIFFUSE), whch tells Open- GL to use the current color, set by glcolor*(), to determne the front-face ambent and dffuse color values.

23 cgbook 2018/8/22 0:58 page 351 #379 Generally, the glcolormateral() call can be of the form glcolormateral(face, parameter) where face can be GL FRONT, GL BACK or GL FRONT AND - BACK, and parameter one of GL AMBIENT, GL DIFFUSE, GL AMBIENT AND DIFFUSE, GL SPECULAR or GL EMISSION. 3. Make a call to glcolor*() to set the front-face ambent and dffuse color from one object to the next. Secton 11.4 OpenGL Lghtng Model Experment Run spotlght.cpp. The program s prmarly to demonstrate spotlghtng, the topc of a forthcomng secton. Nevertheless, press the page-up key to see a mult-colored array of spheres. Fgure s a screenshot. Currently, the pont of nterest n the program s the nvocaton of the color materal mode for the front-face ambent and dffuse reflectances by means of the last two statements n the ntalzaton routne, vz., glenable(gl COLOR MATERIAL); glcolormateral(gl FRONT, GL AMBIENT AND DIFFUSE); and subsequent colorng of the spheres n the drawng routne by glcolor4f() statements. End 11.4 OpenGL Lghtng Model Fgure 11.32: Screenshot of spotlght.cpp. The so-called OpenGL lghtng model sets certan envronmental parameters. Ths termnology, even though used n the red book, s somewhat unfortunate as t may suggest laws of nteracton between lght and objects, or a relaton wth Phong s model nether of whch s true. The four parameters the OpenGL lghtng model sets are the followng: 1. The global ambent lght wth the statement gllghtmodel*(gl LIGHT MODEL AMBIENT, globamb) where globamb s the global ambent lght vector. Ths we ve seen already. 2. Whether to use a local or nfnte vewpont for lghtng calculaton. See agan the lghtng equaton (11.11). The halfway vector s at a vertex, one for each lght source, s the unt vector bsectng the angle between the drecton vector l to the lght source L and the drecton vector e to the eye. The OpenGL eye beng fxed at the orgn [0 0 0] T, we can take (the unnormalzed) e = V, denotng a vertex V s poston vector by V as well. Clearly, then, e changes from one vertex to another. However, t smplfes lghtng computaton to keep e constant, partcularly e = [0 0 1] T, equvalent to assumng an eye whch s nfntely far up the z-axs and so, effectvely, n the same drecton from every vertex. See Fgure Ths smplfcaton, often, stll gves adequately authentc lghtng. The OpenGL default vewpont, n fact, s nfnte. For lghtng calculaton to be done usng a local vewpont nstead.e., wth the eye at the orgn call gllghtmodel*(gl LIGHT MODEL LOCAL VIEWER, GL TRUE) whch s what we do n the setup() routnes of both sphereinbox1.cpp and lghtandmateral1.cpp, whle lghtandmateral2.cpp provdes an opton. The local vewpont s more realstc at the expense of greater computaton. Remark The chosen lght model vewpont s used only for lghtng calculatons. The vewng frustum or box stays unchanged. Therefore, n the case of a frustum, for nstance, we stll see the scene from the eye at the orgn. 351

24 cgbook 2018/8/22 0:58 page 352 #380 Chapter 11 Color and Lght [0 0 1]T nfntely far eye y V0 V0 z local eye O V1 x Fgure 11.34: Screenshot of lghtandmateral2.cpp: local vewpont. [0 0 1]T V1 Fgure 11.33: Local versus nfnte vewpont: the eye drecton vector from each vertex toward the nfnte vewpont s black, whle that toward the local vewpont s green. V denotes both a vertex and ts poston vector. Remark The drecton vector l to the lght source, too, changes from vertex to vertex f the source s postonal,.e., f w 6= 0 n the value [x y z w]t of the source s GL POSITION. However, a smplfcaton exactly smlar to that of assumng an nfnte vewpont can be acheved, not by tweakng the OpenGL lghtng model, but by makng the lght drectonal by settng w = 0. We ll dscuss ths next secton. Experment Fgure 11.35: Screenshot of lghtandmateral2.cpp: nfnte vewpont. Run lghtandmateral2.cpp. Press l or L to toggle between the Local and the nfnte vewpont n lghtandmateral2.cpp. See Fgures and for screenshots. End Exercse (Programmng) The change between local and nfnte vewponts n the precedng experment seems to be only n the hghlghts, n other words, only the specular reflecton. Why? 3. Whether to enable two-sded lghtng. The OpenGL default s to perform lghtng calculatons for each polygon based on ts specfed GL FRONT face parameter values and ts specfed vertex normals, regardless f t s front or back facng. As the user lkely sets materal propertes and normal values wth the front faces of polygons n mnd, results tend to be unrealstc for those whose back faces happen to be vsble. So, when back faces mght be vsble, the command to use s Fgure 11.36: Screenshot of lttrangle.cpp showng the back face wth two-sde lghtng on. gllghtmodel*(gl LIGHT MODEL TWO SIDE, GL TRUE) whch causes OpenGL to (a) use the GL BACK (or GL FRONT AND BACK) parameter values to color backfacng polygons, and (b) reverse the specfed vertex normal for back-facng polygons. Experment Run lttrangle.cpp, whch draws a sngle trangle, whose front face s coded to be red and back blue, ntally front-facng and lt two-sded. Press the left and rght arrow keys to turn the trangle and space to toggle two-sded lghtng on and off. See Fgures and for screenshots. Fgure 11.37: Screenshot of lttrangle.cpp showng the back face wth two-sde lghtng off. 352 Notce how the back face s dark when two-sded lghtng s dsabled ths s because the normals are pontng oppostely of the way they should be. End Exercse (Programmng) Comment out the statement enablng two-sded lghtng n sphereinbox1.cpp, predctng what wll be dfferent before runnng.

25 cgbook 2018/8/22 0:58 page 353 # Whether to apply specular lght before or after texturng. The followng remarks wll be more meanngful after the dscusson of textures n the next chapter. The OpenGL default s to apply textures followng lghtng calculatons, whch can cause specular hghlghts to be smothered. However, the command gllghtmodel*(gl LIGHT MODEL COLOR CONTROL, GL SEPARATE SPECULAR COLOR) Secton 11.5 Drectonal Lghts, Postonal Lghts and Attenuaton of Intensty makes OpenGL (a) separately produce two colors at each vertex: a prmary color calculated from all ncomng non-specular components and a secondary color from all ncomng specular components, (b) combne only the prmary color wth texture color at the tme of texture mappng and, fnally, (c) add n the secondary color to the result of the prevous step, whch assures the specular hghlghts Drectonal Lghts, Postonal Lghts and Attenuaton of Intensty Drectonal and Postonal Lght Sources We know that the value of the GL POSITION parameter of a lght source L specfes ts locaton [x y z w] T n homogeneous coordnates. If w 0, then the lght source s called postonal, or local, or pont, and located at world coordnates [x/w y/w z/w] T. Ths s the knd of source we have used so far. And, n ths case, the (unnormalzed) lght drecton vector at a vertex V s l = [x/w y/w z/w] T V (denotng V s poston vector by V as well) whch, of course, vares wth V. See Fgure nfntely far (drectonal) lght source specfed to be at (x, y, z, 0) [x y z] T l 0 (x, y, z) (x/w, y/w, z/w) = poston of (postonal) lght source specfed to be at (x, y, z, w) V 0 O l 1 [x y z] T V 1 Fgure 11.38: Drectonal versus postonal lght: the drecton vector from each vertex toward the drectonal lght s black and parallel to the drecton of the drectonal lght, whle that toward the postonal lght s green. However, f w = 0, then the lght source s drectonal and assumed located at an nfnte dstance n the drecton of [x y z] T from the orgn, n whch case the lght drecton vector at every vertex s the same [x y z] T. 353

26 cgbook 2018/8/22 0:58 page 354 #382 Chapter 11 Color and Lght Fgure 11.39: Screenshot of lghtandmateral2.cpp: postonal lght source at whte ball. Fgure 11.40: Screenshot of lghtandmateral2.cpp: drectonal lght source along whte arrow. When modelng a scene, a postonal lght s one whch s located wthn t or nearby, e.g., a street lght or car headlght, whle a drectonal lght s far removed, e.g., the sun. Evdently, lghtng calculaton s cheaper for drectonal sources. The default value for GL POSITION s [ ] T, whch defnes a drectonal lght shnng down from hgh up the z-axs. Experment Press p or P to toggle between Postonal and drectonal whte lght n lghtandmateral2.cpp. The whte wre sphere ndcates the postonal lght, whle the whte arrow the ncomng drectonal lght. See Fgures and Keep n mnd that you can both move the ball and rotate the lght poston. End Exercse Explan the dfference n how the ball looks n Fgures and Attenuaton of Lght In the real world, the ntensty of lght from a source dmnshes wth dstance from the source followng an nverse square law. Ths phenomenon, called dstance attenuaton, can be modeled n OpenGL as well by a multplcatve dstance attenuaton factor 1 k c + k l d + k q d 2 where d s the dstance from the lght source and k c, k l and k d are the values of the lght parameters GL CONSTANT ATTENUATION, GL LINEAR ATTENUATION and GL QUADRATIC ATTENUATION, respectvely. These values are set by statements of the form gllghtf(gl LIGHT, GL CONSTANT ATTENUATION, k c); gllghtf(gl LIGHT, GL LINEAR ATTENUATION, k l ); gllghtf(gl LIGHT, GL QUADRATIC ATTENUATION, k q); The default values are k c = 1 and k l = k q = 0, whch mply no attenuaton over dstance at all. Attenuatng the ntensty of a drectonal lght over dstance s not meanngful as t s already nfntely far from every vertex; therefore, changng attenuaton parameters from the default has no effect for such a source. Experment Run lghtandmateral2.cpp. The current values of the constant, lnear and quadratc attenuaton parameters are 1, 0 and 0, respectvely, so there s no attenuaton. Press t/t to decrease/ncrease the quadratc attenuaton parameter. Lnear attenuaton s always zero. Move the ball by pressng the page up/down keys to observe the effect of attenuaton. Fgure shows the ball some ways off wth no attenuaton and then wth some amount of attenuaton n the case of both a postonal and a drectonal lght. End (a) (b) (c) 354 Fgure 11.41: Screenshots of lghtandmateral2.cpp: (a) No attenuaton (b) Quadratc attenuaton 0.05 (c) Quadratc attenuaton 0.05 but lght changed to drectonal.

27 cgbook 2018/8/22 0:58 page 355 # Spotlghts The default for a lght source s that t s regular, emttng n all drectons (a fancy descrptor would be omndrectonal ). Ths can be altered by turnng t nto a spotlght, n whch case the emtted lght s n the shape of a cone, the purpose beng, of course, to smulate a real-lfe spotlght llumnatng a lmted area. Fgures 11.42(a) and (b) show, respectvely, plane sectons of the lght from a regular source and a spotlght. Experment Run spotlght.cpp, whch shows a brght whte spotlght llumnatng a mult-colored array of spheres. Fgure s a screenshot. Press the page up/down arrows to ncrease/decrease the angle of the lght cone. Press the arrow keys to move the spotlght. Press t/t to change the spotlght attenuaton exponent (to be explaned soon). A whte wre mesh s drawn separately along the lght cone boundary. End The frst step to turnng a lght source L nto a spotlght s to specfy the half-angle at the apex of the lght cone, called the spotlght cutoff angle, wth a command Secton 11.6 Spotlghts L (regular lght source) (a) Lght ball secton L (spotlght source) spotcutoff α s po td -l re ct l on = gllghtf(gl LIGHT0, GL SPOT CUTOFF, spotcutoff) whch, n fact, sets the spotlght cutoff angle to the value spotcutoff. The whole lght cone angle then s 2spotCutoff. The spotlght cutoff angle should be between 0.0 and The default s the specal value of 180.0, meanng that L s not a spotlght, but a regular source emttng n all drectons (2 180 beng 360 ). The ntal value of the spotlght cutoff angle n spotlght.cpp, n fact, s 10, as the reader may check from the gllghtf(..., GL SPOT CUTOFF,...) statement n the drawscene() routne. The next step s to specfy the spotlght drecton or, more specfcally, that of the axs of ts cone wth a command r V (b) Lght cone secton Fgure 11.42: Partal plane sectons of (a) regular lght (b) spotlght. gllghtfv(gl LIGHT0, GL SPOT DIRECTION, spotdrecton) whch sets the axs n a drecton parallel to the vector [x y z]t, f spotdrecton s set to {x, y, z}. The default value of spotdrecton s {0.0, 0.0, 1.0}, amng the spotlght down the negatve z-axs. It s set to {0.0, 1.0, 0.0} n spotlght.cpp, pontng the spotlght n the negatve y-drecton. The fnal step s to set the spotlght attenuaton exponent, whch controls the dstrbuton of ntensty through the lght cone, wth a command gllghtfv(gl LIGHT0, GL SPOT EXPONENT, spotexponent) If the spotlght attenuaton exponent s h and the angle between the axs of the lght cone and the drecton from the lght source L toward vertex V s α, as n Fgure 11.42(b), then the ntensty of lght at V s attenuated by the multplcatve factor cosh α. Ths, of course, presumes that V les wthn the lght cone n the frst place; f not, of course, no lght reaches V from L at all. Note that a vector from L toward V s, smply, l, the negatve of the lght drecton vector at V. The spotlght attenuaton exponent s set to 2.0, ntally, n spotlght.cpp. The logc behnd the spotlght attenuaton exponent s exactly same as that for the shnness exponent n the calculaton of specular reflecton n Equaton (11.8) so that the greater the value h of the attenuaton exponent, the more rapdly the ntensty of the spotlght dmnshes away from the cone s axs. Equvalently, the greater h the more concentrated or focused the spotlght. OpenGL s default value for the spotlght attenuaton exponent s 0, mplyng no attenuaton at all. Experment Run agan spotlght.cpp. Observe the darkenng of the balls near the cone boundary as the attenuaton exponent s ncreased by pressng T. Fgure s a screenshot wth the attenuaton exponent equal to Compare ths wth the Fgure where the exponent was 2.0. End Fgure 11.43: Screenshot of spotlght.cpp (wth attenuaton exponent 2.0). Fgure 11.44: Screenshot of spotlght.cpp (wth attenuaton exponent 10.0). 355

28 cgbook 2018/8/22 0:58 page 356 #384 Chapter 11 Color and Lght Exercse A spotlght should always be postonal. Why? For use n the upcomng fnal OpenGL lght equaton, let s wrte a sngle complete formula for a spotlght attenuaton factor or, brefly, saf, at a vertex V, for a gven lght source L. Denote the unt vector along the spotlght axs,.e., the normalzed value of the spotlght drecton, by r. Assume that l, the lght drecton vector at V, s normalzed as well. Denote the spotlght cutoff angle by spotcutoff and the spotlght attenuaton exponent by h. Then we have: 1, f spotcutof f = saf = 0, f l r < cos(spotcutoff) (11.12) ( l r) h, otherwse Here s how to parse the formula. The frst lne s the case when L, n fact, s not a spotlght, so there s no angular attenuaton. For the second lne, refer to Fgure 11.42(b) as you read on. Note that l s the unt vector from L toward V. Therefore, l r = cos α, where α s the angle between the axs of the lght cone and the drecton of V from L. Now, f cos α < cos(spotcutoff), then α > spotcutoff, whch means that V les outsde the lght cone and gets no lght. Ths explans the second lne. The thrd lne, of course, gves the multplcatve angular attenuaton factor cos h α. Note: A spotlght could be dstance attenuated, as well as angle attenuated. Exercse Why sn t t necessary to wrte (max{ l d, 0}) h, nstead of just ( l d) h, n Equaton (11.12) n a manner smlar to the frst lghtng equaton (11.11)? 11.7 OpenGL Lghtng Equaton We now have the two addtonal peces needed to enhance the frst lghtng equaton (11.11) to the form whch s, n fact, used by OpenGL to calculate RGB color ntenstes at a vertex V, namely, dstance attenuaton and spotlght attenuaton. The enhancement s straghtforward. All symbols from the frst lghtng equaton retan the same meanng. Addtonally, d denotes the dstance of V from the th lght source; k c, k l and k q denote, respectvely, the constant, lnear and quadratc attenuaton parameters for the th lght source; and saf s the spotlght attenuaton factor for the th lght source at the vertex V, as gven by Equaton (11.12). So, fnally, here t s, the grand ole lghtng equaton of OpenGL: V X = V emt, X + globamb X V amb, X + N 1 =0 1 k c + k l d + k q(d ) 2 saf ( L amb, X V amb, X + max{l n, 0} L dff, X V dff, X + (max{s n, 0}) f L spec, X V spec, X ) (11.13) 356 where V X s the color ntensty at V, X beng any of RGB. The addtons to the frst lghtng equaton (11.11) are exactly the two multplcatve terms on the thrd lne of the current equaton, representng dstance attenuaton and spotlght attenuaton, respectvely.

29 cgbook 2018/8/22 0:58 page 357 #385 Remark We must revst Exercse 11.7 at ths tme. Its mplcaton that all ndvdual lght source ambents can be consoldated nto the global ambent s not true any more f one uses Equaton (11.13) nstead of Equaton (11.11), because the same lght source can contrbute dfferent amounts of ambent lght to dfferent vertces owng to dstance and spotlght attenuaton. Nevertheless, the smplfcaton of settng all ndvdual lght source ambents to zero, and adjustng only the global, s almost always worth the mld damage to authentcty. Exercse If there s a sngle drectonal lght source n an OpenGL program, whch s not dstance attenuated, whch of the three ambent, dffuse and specular reflectance components at ts vertces s changed by translatng an object? Exercse If there s a sngle postonal lght source n an OpenGL program, whch s not a spotlght and not dstance attenuated, whch of the three ambent, dffuse and specular reflectance components at an object s vertex can change by movng the lght source? By translatng the object? Exercse Whch of the three components ambent, dffuse and specular of lght reflected from a vertex V are affected f the normal at V s altered? Secton 11.8 OpenGL Shadng Models 11.8 OpenGL Shadng Models A shadng model s a method to shade, or color, the nterors of prmtves. Keep n mnd that Phong s lghtng model, as mplemented through the OpenGL lghtng equaton, determnes colors only at the vertces of prmtves, but says nothng about how to spread them nsde. OpenGL s default shadng model, called smooth shadng or Gouraud shadng, s to lnearly nterpolate color values computed at ts vertces through a prmtve s nteror. In fact, we dscussed at length n Secton 7.2 the mechancs of lnear nterpolaton. An alternate smplstc shadng model, called flat shadng, s avalable, as well, n OpenGL. It s specfed by a call to glshademodel(gl FLAT) The default of smooth shadng s restored by callng glshademodel(gl SMOOTH) When flat shadng, even f the color values dffer across the vertces of a prmtve, OpenGL chooses one of them, called the provokng vertex, and apples ts color to the entre prmtve. For example, the provokng vertex of a trangle s ts frst (accordng to the order of the vertces n the code). In a trangle strp, the provokng vertex of the th trangle s the + 2 th vertex. The reader s referred to the red book for a full descrpton of provokng vertces for each prmtve type. Flat shadng sometmes can be a reasonable alternatve, partcularly n the absence of lghtng. Computatonally t s, of course, far less expensve than smooth shadng as there s no nterpolaton to do. An nterestng applcaton of flat shadng s n applyng dscrete color schemes whch, often, s dffcult wth smooth shadng. The followng experment s an llustraton. Experment Run checkeredfloor.cpp, whch creates a checkered floor drawn as an array of flat shaded trangle strps. See Fgure Flat shadng causes each trangle n a strp to be panted wth the color of the last of ts three vertces, accordng to the order of the strp s vertex lst. End Fgure 11.45: Screenshot of checkeredfloor.cpp. Exercse (Programmng) Try and replcate the checkered floor of the precedng experment usng smooth shadng nstead of flat. 357

30 cgbook 2018/8/22 0:58 page 358 #386 Chapter 11 Color and Lght 11.9 Anmatng Lght There are three ways that the spatal propertes of a lght source can be anmated: 1. By movng ts poston. 2. By changng ts drecton f t s a spotlght. 3. By changng the lght cone angle f t s a spotlght. We ve already seen lght moton n two programs n ths chapter lghtandmateral2.- cpp and spotlght.cpp the lght source beng moved by the arrow keys n both programs, whle the cone angle s altered n spotlght.cpp wth the page up/down keys. Thngs to keep n mnd are: (a) A lght source s poston vector, specfed by a gllghtfv(lght, GL POSITION, lghtpos) statement, s transformed by the value of the current modelvew matrx by multplcaton from the left. (See Secton 4.2 f you need to revew modelvew matrces.) Effectvely, then, modelvew transformatons n the code pror to the gllghtfv- (lght, GL POSITION, lghtpos) statement apply to a lght s poston, exactly as f t were a vertex poston specfed by a glvertex3f() statement. (b) Lkewse, a spotlght source s drecton vector, specfed by the gllghtfv(lght, GL SPOT DIRECTION, spotdrecton) statement, s transformed by the value of the current modelvew matrx by multplcaton from the left. For example, as the lght source of sphereinbox1.cpp s postoned by the gllghtfv(gl LIGHT0, GL POSITION, lghtpos) statement n the ntalzaton routne setup(), t s unaffected by any modelvew transformatons n drawscene(). However, both lghts of lghtandmateral1.cpp are postoned n the dsplay routne followng the vewng command glulookat(), so ther postons are, n fact, transformed by glulookat(), whch means that the lghts stay statc relatve to the scene, no matter f the vewpont s changed by alterng parameters n glulookat(). The lght postons of lghtandmateral2.cpp are smlarly transformed by ts own glulookat(). Pror to the postonng of the whte lght of lghtandmateral2.cpp are a couple of rotaton commands as well, whch, therefore, turn t; lkewse, the spotlght of spotlght.cpp s postoned n the dsplay routne after the vewng transformaton and a user-specfed translaton. Remark We ve dscussed anmatng only spatal attrbutes of a lght source. Obvously, color values can be anmated as well Partal Dervatves, Tangent Planes and Normal Vectors 101 Ths secton s an ntroducton to the calculus sometmes requred to calculate normals to surfaces. It s not mandatory readng. We suggest you skp ths secton ntally and consult t later f need be. Actually, f you know how to compute dervatves of a functon of a sngle varable, e.g., f(x) = x 2 or f(x) = sn x, as we ll assume you do, you already know how to compute partal dervatves. Because Defnton Suppose that f s a functon of more than one varable x, y,.... The partal dervatve of f wth respect to one of these varables, say x, s the dervatve of f as a functon only of x, assumng the other varables all fxed. The partal dervatve of f wth respect to x s denoted f x.

31 cgbook 2018/8/22 0:58 page 359 #387 Example Evaluate the partal dervatves of at the pont (1, 2). f(x, y) = x 2 + y 2 Secton Partal Dervatves, Tangent Planes and Normal Vectors 101 Answer: We have Therefore, f f (x, y) = 2x, x f f (1, 2) = 2, x (x, y) = 2y y (1, 2) = 4 y Remark Often f f x (x, y) s smply wrtten x, e.g., the frst two equatons of the precedng answer could be wrtten f x = 2x, f y = 2y Example Evaluate the partal dervatves of at the pont (1, π/2). f(x, y) = x 2 sn y Answer: We have Therefore, f f = 2x sn y, x f f (1, π/2) = 2, x y = x2 cos y (1, π/2) = 0 y Exercse Evaluate the partal dervatves of at the pont (π/2, π, 0). f(x, y, z) = xz + sn x cos y cos z + y Exercse Evaluate the partal dervatves of at the pont (2, 3). f(x, y) = xy Exercse Evaluate the partal dervatves of at the pont (π/2, 0, π/2). f(x, y, z) = x cos y + y cos z + z cos x The reader may wonder that f the partal dervatve f x, for example, s obtaned by dfferentatng f wth respect to the sngle varable x, assumng the others fxed, then why do those other varables pop up agan n the expresson for f x? Here s the reason. Consder the functon f(x, y) = x 2 sn y of Example 11.7 above. Fxng y at, say, the value π/6 gves the functon f(x, π/6) = x 2 /2, whle fxng y at π/2 gves the functon f(x, π/2) = x 2. Both f(x, π/6) and f(x, π/2) are functons of the one varable x, but they are dfferent functons because y s been fxed at two dfferent values. 359

32 cgbook 2018/8/22 0:58 page 360 #388 Chapter 11 Color and Lght Moreover, d 2 f (x, π/6) = (x /2) = x x dx and d 2 f (x, π/2) = (x ) = 2x x dx are dfferent as well, as they are dervatves of dfferent functons. Ths s why f x depends on y, as well as on x. So far so good. At least calculatng partal dervatves s no dfferent from calculatng ordnary dervatves. But what do partal dervatves mean geometrcally (n real lfe, that s)? To answer ths, let s see frst how ordnary dervatves specfy the tangent to a curve n the case of both mplct and parametrc declaratons. (a) Implct: Suppose a plane curve s gven by the equaton y = f (x) Then the value of df dx at x = a s the gradent of the tangent lne to the curve at the pont (a, f (a)). For example, the gradent of the tangent lne l at the pont (1, 1) of the parabola y = x2 s 2 as d 2 (x ) = 2x dx whch equals 2 when x s 1. See Fgure 11.46(a). Moreover, any non-zero vector along l, e.g., v = [1 2]T, s a tangent vector to the parabola at (1, 1). y y = x2 l (gradent 2) v = [1 2]T y v = [ 1 0 1]T (1, 1) (0, 1, π/2) x x c(t) = (cos t, sn t, t) (a) z (b) Fgure 11.46: Tangents: (a) Tangent lne l and tangent vector v to the parabola y = x2 at (1, 1) (b) Tangent vector v 0 to the helx c(t) = (cos t, sn t, t) at (0, 1, π/2). (b) Parametrc: Suppose a curve n 3-space s gven by c(t) = (f (t), g(t), h(t)) Then the value of the vector c0 (t) = df dt dg dh dt dt T at t = a s a tangent vector to the curve at the pont (f (a), g(a), h(a)). For example, a tangent vector v 0 to the helx 360 c(t) = (cos t, sn t, t)

33 cgbook 2018/8/22 0:58 page 361 #389 at the pont (0, 1, π/2), correspondng to t = π/2, s [ 1 0 1]T, as d d d (cos t) (sn t) (t) dt dt dt T Secton Partal Dervatves, Tangent Planes and Normal Vectors 101 = [ sn t cos t 1]T whch equals [ 1 0 1]T when t = π/2. See Fgure 11.46(b). Remark In the above and n what follows we gnore the possblty of sngulartes where the tangent does not even exst, e.g., f the tangent vector c0 (t) = 0. It turns out that, just as the computaton of partal dervatves s based on computng ordnary dervatves, ther geometrc sgnfcance obtans from that of ordnary dervatves too. Here s how: (a) Implct: Consder z = f (x, y), a functon of two varables. It defnes a surface s n 3-space, called the graph of f. (Note: Ths form s more easly vsualzed than the most general F (x, y, z) = 0 for a surface n 3-space.) Now, f we fx y at, say, the value b, then z = f (x, b) gves a curve c on s; n fact, c s the secton of s by the plane y = b. See Fgure 11.47(a). (In terms of the dscusson n Secton , c s mplct specfcaton conssts of the two equatons z = f (x, y) and y = b.) Now, z = f (x, b) s the equaton of the plane curve c, whch can be thought of as lyng on the xz-plane, for y = b s a copy of the xz-plane. Moreover, by defnton, the value of f x at (a, b) s the value at a of the ordnary dervatve d f (x, b). Therefore, applyng now the geometrc nterpretaton earler of the dx dervatve of a plane curve gven mplctly, we see that the value of f x at (a, b) s the gradent of the tangent lne l1, at the pont P = (a, b, f (a, b)), to the sectonal curve z = f (x, b) of s. In fact, l1 s tangent to the surface s at P, as well, and any non-zero vector t1 along l1 s a tangent vector to s at P. Lkewse, the value of f y at (a, b) s the gradent of the tangent lne l2, at the pont P = (a, b, f (a, b)), to the curve z = f (a, y), whch s the secton of s by the plane x = a (Fgure 11.47(b)); moreover, l2 s tangent to the surface s at P and any non-zero vector t2 along l2 s a tangent vector to s at P. z f(a, l1 y z= plane y=b plane x=a y) z P y P z= t1 f(x, l2 b) x x s: z = f(x, y) (a) t2 s: z = f(x, y) (b) Fgure 11.47: Secton of the graph s of z = f (x, y) by the (a) plane y = b, gvng the tangent lne l1 and the tangent vector t1 at P = (a, b, f (a, b)), (b) plane x = a, gvng the tangent lne l2 and tangent vector t2 at P. 361

34 cgbook 2018/8/22 0:58 page 362 #390 Chapter 11 Color and Lght (b) Parametrc: Consder next the surface s specfed by the parametrc equatons x = f (u, v), y = g(u, v), z = h(u, v), (u, v) W where W = [u1, u2 ] [v1, v2 ] s a rectangle n uv parameter space. The functon (u, v) 7 s(u, v) = (f (u, v), g(u, v), h(u, v)) maps W to the surface s n 3-space. See Fgure v v=b f g h u u u (a, b) s T P = s(a, b) c1(u) = s(u, b) c2(u) = s(a, v) y u=a u W T f g h v v v x z Fgure 11.48: The surface s s the mage of a parameter rectangle W by the map (u, v) 7 s(u, v) = (f (u, v), g(u, v), h(u, v)) wth tangents to the parameter curves on s at the pont P = s(a, b). Fx a pont (a, b) W. The mage of the lne v = b by s s the u-parameter curve c1 n 3-space wth equaton c1 (u) = (f (u, b), g(u, b), h(u, b)), u [u1, u2 ] From the geometrc nterpretaton earler of the ordnary dervatve n the case of a space curve gven parametrcally, the tangent vector to ths curve s c01 (u) d = f (u, b) du d g(u, b) du d h(u, b) du T at u [u1, u2 ]. However, the RHS just above s by defnton equal to f (u, b) u g (u, b) u We conclude that the value of the vector h f u h (u, b) u g u h u T T at the pont (a, b) s a tangent vector to the u-parameter curve c1 (u) = s(u, b) at the pont P = s(a, b) on s; n fact, t s, as well, a tangent vector to the surface s at P. h T g h Lkewse, the value of the vector f at the pont (a, b) s a tangent v v v vector to the v-parameter curve c2 (v) = s(a, v) at the pont P and a tangent vector to s at P. 362 So, we see that, just as an ordnary dervatve on a curve specfes ts tangent, partal dervatves can be used to specfy tangents to a surface. In fact, they can gve even more geometrc nformaton about the surface, n partcular, by determnng the tangent plane, as well as normals, as we see next.

35 cgbook 2018/8/22 0:58 page 363 #391 Defnton If two tangent vectors, say t1 and t2, at a pont P on a surface s are lnearly ndependent n other words, they are not collnear then they span a plane p, called the tangent plane to the surface at P. The lne l perpendcular to p through P s sad to be the normal lne to s at P and any non-zero vector lyng on ths lne a normal vector to s at P. See Fgure A tangent plane to a surface s precsely the analogue of a tangent lne to a curve. A thn straght stck pressed to a plane wre curve algns tself along the tangent lne at the pont of contact; lkewse, a thn flat board pressed to a surface n 3-space algns tself along the tangent plane at the pont of contact. Secton Partal Dervatves, Tangent Planes and Normal Vectors 101 n s Determne the tangent plane and a normal vector at the pont P = (1, 2, 5) to the parabolod s gven by p P Example t1 t2 z = x2 + y 2 Answer : We can do ths n two dfferent ways dependng on f we use the gven mplct form or wrte a parametrc one. Let s do both. See Fgure as we proceed. parabolod s: z = x2 + y2 ep z tangent plan normal vector [ 2 4 1]T tangent vector [0 1 4]T tangent vector [1 0 2]T l Fgure 11.49: Tangent vectors t1 and t2 span the tangent plane p at pont P on the surface s; l s the normal lne and n a normal vector. y P (1, 2, 5) x Fgure 11.50: Tangent vectors, tangent plane and normal vector at the pont (1, 2, 5) to the parabolod z = x2 + y 2. The mplct form of s s z = f (x, y) = x2 + y 2. So, from earler dscusson, a tangent lne to s at P, whch s also a tangent lne to the sectonal curve z = f (x, 2) f at P, has gradent f x (1, 2) = 2, as x = 2x. Therefore, a tangent vector to s at P on T ths tangent lne s [1 0 2], notng that that tangent lne has gradent 2 lyng on (a copy of) the xz-plane, whch mples that any vector on t has z-component twce ts x-component and y-component zero. Lkewse, a vector at P tangent to s, as well as to ts sectonal curve z = f (1, y), s [0 1 4]T. So, we have found two tangent vectors to s at P. Before proceedng further, let s see what we can do wth a parametrc form next. It s easy frst to wrte s n the parametrc form x = f (u, v) = u, y = g(u, v) = v, z = h(u, v) = u2 + v 2 (11.14) the pont P correspondng to the parameter values u = 1 and v = 2. From dscusson earler, we have that a tangent vector to s at P, whch, n fact, s a tangent vector to h T f g h the u-parameter curve on s at P, s the value of u = [1 0 2u]T at (1, 2). u u Ths gves the tangent vector [1 0 2]T. Lkewse, one fnds the vector [0 1 4]T tangent to the v-parameter curve on s at P, as well as to s tself at P. So, we get the same two vectors [1 0 2]T and [0 1 4]T tangent to s at P usng ether the mplct or parametrc form for s. Contnung, then, the tangent plane p to s at P s spanned by these two vectors. Precsely, p conssts of all vectors of the form α[1 0 2]T + β[0 1 4]T, where α and β are any two reals. 363

36 cgbook 2018/8/22 0:58 page 364 #392 Chapter 11 Color and Lght A normal vector to s at P s perpendcular to ts tangent plane there and, therefore, to both spannng vectors [1 0 2] T and [0 1 4] T. It s obtaned, then, as the cross-product of the latter two (cross-products of vectors were revewed n Secton 5.4.3), vz., [1 0 2] T [0 1 4] T = [ 2 4 1] T Remark Computng the tangent plane at a pont of a surface and computng a normal vector there are evdently equvalent. Exercse Determne the tangent plane and a normal vector to the crcular cylnder x = cos u, y = sn u, z = v at the pont correspondng to the parameter values (u, v) = (π/4, 3). Exercse Determne the tangent plane and a normal vector to the saddleshaped surface (hyperbolc parabolod s the mathematcal name) z = xy at the pont (2, 3, 6). Exercse (Programmng) Draw the parabolod of Example 11.8 and ts tangent plane at some pont. The parabolod should be wreframe and the tangent plane a fnely meshed rectangle. Allow the user to press the arrow keys to slde the tangent plane over the parabolod. Normals from Functon Gradents 364 There s a neat way to compute drectly a normal vector at a pont of a surface s gven by an mplct equaton of the most general form F (x, y, z) = 0 wthout determnng the tangent plane frst: a normal vector to s at the pont P s gven by the value at P of the so-called gradent of F, denoted grad(f ) and defned by grad(f ) = [ F x We ll not prove that grad(f ) s ndeed normal to the surface F (x, y, z) = 0, referrng the reader nstead to books on vector calculus, e.g., Schey [125] and Spegel [138], for, not only the proof, but more about the gradent, as well as ts related functons dvergence and curl. Example Determne a normal vector to the parabolod at the pont (1, 2, 5). F y z = x 2 + y 2 Answer: Wrte the mplct equaton n the form Then grad(f ) = F z ] T F (x, y, z) = z x 2 y 2 = 0 [ F x F y F z ] T = [ 2x 2y 1] T Therefore, a normal vector at the pont (1, 2, 5) s [ 2 4 1] T, whch s obtaned from puttng x = 1 and y = 2 n the precedng equaton. Ths result checks wth Example Exercse Verfy your answer to Exercse by fndng a normal vector to the cylnder usng the grad functon. You must wrte an mplct equaton for the cylnder frst.

37 cgbook 2018/8/22 0:58 page 365 # Computng Normals and Lghtng Surfaces Look carefully at the OpenGL lghtng equaton (11.13) once more. Outsde of a bunch of user-specfed color propertes, the only data needed to compute the color ntenstes at a vertex V of an object O conssts of the locaton of V, the locatons of the lght sources and the normal vector n at V. The locaton of V, of course, s part of the user s desgn of O tself. As for the lght sources, typcally, they are few and can be located wth a far amount of flexblty for the desred level of llumnaton. Remanng s the normal vector n, whch the user s free to set as well to whatever value she chooses. However, for authentc lghtng t should actually be perpendcular to the surface of O at V or at least nearly so. For example, the choce of the normal vector n at the vertex V (outward along a radus) of the sphere n Fgure seems good, though ether of the other two vectors drawn could concevably have been pcked as well wthout OpenGL complanng. We ll dscuss computng surface normals followng the nformal taxonomy of 2D objects n Secton 10.2 before movng on to Bézer and quadrc surfaces for whch OpenGL provdes automatc normals Polygons and Planar Surfaces Polygons n partcular, and planar surfaces n general, are the smplest. The normal at each vertex s smply normal to the plane tself contanng the surface. In partcular, unt vertex normals are all dentcal across a gven sde of the surface. So how does one determne the normal drecton to a plane p? If two non-collnear vectors u and v are known to le on p, then the cross-product u v s normal to p (cross-products were revewed n Secton 5.4.3). For example, two adjacent edges of a smple plane polygon, assumng they do not happen to le on one lne, determne noncollnear vectors u and v spannng the plane p contanng the polygon. In Fgure 11.52, u = P 1 P 0 and v = P 4 P 0 span p and n = u v s normal to p. Exercse Determne a normal to the plane p of the trangle wth vertces at P 0 = [0 3 5] T, P 1 = [1 2 0] T, P 2 = [3 3 3] T Secton Computng Normals and Lghtng Surfaces O V n Fgure 11.51: Three vectors at a vertex on a sphere, one of whch has been chosen as the normal. P 4 p n = u x v v P 0 P 3 u P1 P 2 Fgure 11.52: Vector n s normal to the plane p Meshes Polygonal meshes are of nterest next. Let s work wth real examples. Experment Run agan sphereinbox1.cpp. The normal vector values at the eght box vertces of sphereinbox1.cpp, placed n the array normals[], are [±1/ 3 ± 1/ 3 ± 1/ 3] T each correspondng to one of the eght possble combnatons of sgns. End The choce of the normals n sphereinbox1.cpp s easly motvated. The box beng stuated symmetrcally about the orgn, the normal values are chosen as unt vectors along the lnes from the orgn to each of the eght vertces, whch ndeed gve the values above. The box s depcted n Fgure 11.53(a), where only the normal vector at the lower-rght vertex V of the front face s shown: t s the green arrow n drawn by extendng OV a unt dstance from V. In fact, probably a better ratonale for ths partcular choce of normals, not dependng on symmetry, s that the one at each vertex s the normalzed average of the unt outward normals to the three faces meetng at that vertex. For example, n Fgure 11.53(a) the unt outward normals to f 1, f 2 and f 3, the three faces whch meet at V, are [1 0 0] T, [0 0 1] T and [0 1 0] T, respectvely, whose average s [1/3 1/3 1/3] T, whch normalzes to [1/ 3 1/ 3 1/ 3] T, whch one can verfy from the code s ndeed the value of the normal at V n sphereinbox1.cpp. 365

38 cgbook 2018/8/22 0:58 page 366 #394 Chapter 11 Color and Lght y f O 1 f 2 x z f3 normal to f 2 (a) V normal to f 3 n normal to f 1 (b) Fgure 11.53: (a) The box of sphereinbox1.cpp wth the averaged normal vector n at vertex V, together wth the normals to the three faces that meet at V (f 1 rght face, f 2 front face, f 3 bottom face) (b) The unaveraged normals of sphereinbox2.cpp. Although they possess the vrtue of symmetry and beng averages, none of the box normals of sphereinbox1.cpp s even close to perpendcular to a face of the box. Ths consderaton leads to another approach to set the normal at each vertex of a face as a normal to that face tself. Ths s mplemented as an opton n sphereinbox2.cpp. (a) (b) Fgure 11.54: Screenshot of sphereinbox2.cpp: (a) Averaged box normals (b) Unaveraged box normals. 366 Experment Run sphereinbox2.cpp, whch modfes sphereinbox1.cpp. Press the arrow keys to open or close the box and space to toggle between two methods of drawng normals. The frst method s the same as that of sphereinbox1.cpp, specfyng the normal at each vertex as an average of ncdent face normals. The second creates the box by frst drawng one sde as a square wth the normal at each of ts four vertces dentcally specfed to be the unt vector perpendcular to that square, then placng that square n a dsplay lst and, fnally, drawng t sx tmes approprately rotated. Fgure 11.53(b) shows the vertex normals to the three ncdent faces at each vertex. Fgure shows screenshots of the box created wth and wthout averaged normals. End The contrast n output between the two ways of defnng box normals n sphereinbox2.cpp s clear and the reason not hard to understand. The frst method softens the edges because the averaged normal at each vertex s shared by all ts three adjacent faces. Consequently, the nterpolaton of color values n each face s nteror contnues smoothly across ts boundary. The second method s sgnfcantly dfferent. As each face s drawn separately wth the normals at all ts four vertces equal and perpendcular to the face tself,

39 cgbook 2018/8/22 0:58 page 367 #395 nterpolaton n the nteror results n the entre face beng colorzed as f wth that one normal value throughout. Moreover, ths normal value turns abruptly 90 from one face to the next. The upshot s that there s a marked dfference n color ntenstes, as well, from one face to the next, throwng the edges between them nto sharp relef. Whch approach to choose depends on the effect desred. Remark Usng the second method, colors at pxels along an edge are defned dfferently by ts two adjacent faces, whle pxel colors at a vertex are defned dfferently, n fact, by ts three adjacent faces. At these pxels, therefore, code order determnes whch color prevals. Ths s not desrable, but t s not a serous ssue because such ambguous pxels le only on edges and vertces, but not n the nteror of faces, the latter consttutng by far the bulk of the fgure. Versons of the averagng approach mplemented sometmes to acheve greater realsm use a weghted average rather than a straght one. Two possbltes are: (a) Weght the normal to each face ncdent at a vertex wth the angle that face subtends at the vertex. In Fgure 11.55, fve faces meet at the vertex V subtendng angles θ 1, θ 2,..., θ 5, respectvely. Therefore, the angle-weghted average value of the normal at V s: Secton Computng Normals and Lghtng Surfaces n = θ 1n 1 + θ 2 n 2 + θ 3 n 3 + θ 4 n 4 + θ 5 n 5 θ 1 + θ 2 + θ 3 + θ 4 + θ 5 n 2 n 1 n (b) Weght the normal to each face ncdent at a vertex wth the area of that face. The areas of the fve faces n Fgure meetng at V are A 1, A 2,..., A 5, respectvely. The area-weghted average value of the normal at V s then: A 1 θ 1 θ 2 V θ A 5 5 θ A 3 θ 4 3 A 4 A 2 n 5 n = A 1n 1 + A 2 n 2 + A 3 n 3 + A 4 n 4 + A 5 n 5 A 1 + A 2 + A 3 + A 4 + A 5 Important: Whatever approach you adopt to compute normals, make sure, as a last step, to normalze each to unt length (easy enough just dvde each by ts length). The reason s that OpenGL uses the dot product to compute the cosne of the angle between two vectors (see Equaton (11.13)), whch s correct f both are of unt length. Example For the trash can mesh whose vertces are gven n Fgure 11.56, compute the unt normals to the three faces adjacent to the vertex V. Then compute the (unweghted) average of these three normals and normalze to unt length. n 3 n 4 Fgure 11.55: Weghted average of normals: θ are angles, A area, n face normals and n a weghted average normal at V. ( 1.2, 1, 1.2) (1.2, 1, 1.2) ( 1.2, 1, 1.2) (1.2, 1, 1.2) ( 1, 1, 1) u 2 (1, 1, 1) ( 1, 1, 1) u 3 u 1 V (1, 1, 1) n 12 n 23 n 31 n Fgure 11.56: Trash can of fve quadrlateral sdes. The vectors n 12, n 23 and n 31 from V are normals to V s adjacent faces, whle n s the averaged normal. Answer: The three edge vectors emanatng from V are: u 1 = [1 1 1] T [1 1 1] T = 2k u 2 = [ ] T [1 1 1] T = j + 0.2k u 3 = [ 1 1 1] T [1 1 1] T = 2 367

40 cgbook 2018/8/22 0:58 page 368 #396 Chapter 11 Color and Lght Therefore, the outward unt normal to the face wth edges u 1 and u 2 s n 12 = (u 1 u 2 ) / u 1 u 2 = (4 0.4j) / j and that to the face wth edges u 2 and u 3 s n 23 = (u 2 u 3 ) / u 2 u 2 = ( 0.4j + 4k) / j k whle the outward unt normal to the face wth edges u 3 and u 1, the bottom face, s easly seen to be n 31 = j The normalzed average of these normals s n = (n 12 + n 23 + n 31 ) / n 12 + n 23 + n 31 ( j k) / j k Exercse (Programmng) Use data from the precedng example to replace the box of sphereinbox2.cpp wth a trash can. Omt the sphere. Let the user choose between averaged and unaveraged normals. Allow the can to be rotated keepng the lght source fxed. s V Fgure 11.57: Normal vector n to the surface s at a vertex V of ts mesh approxmaton. n General Surfaces As a general surface s drawn by approxmatng t wth a polygonal mesh, the thought comes to mnd to smply use the methods of the precedng secton to fnd normals. Precsely, (a) formulate a mesh approxmaton of the surface and (b) specfy the normal at each vertex as an average of those of ts ncdent faces (we really want to use an average here, especally f the orgnal surface s smooth, to avod lghtng dscontnutes between adjacent faces). Ths approach s perfectly reasonable f the surface s known to the user only by ts mesh approxmaton. However, f one knows, say, a parametrc representaton of the orgnal surface, why not get the normals from the horse s mouth that beng the parametrzaton tself? In other words, use the parametrzaton to analytcally compute the normals at the mesh vertces. Ths makes for stable normals ndependent of the vagares of the partcular mesh approxmaton, not to menton those of the averagng process. For example, workng from the mesh approxmaton of the surface s n Fgure 11.57, the normals to the sx faces ncdent at vertex V must be averaged to determne the normal n at V. However, knowledge of s tself could enable a drect computaton wthout reference to any partcular trangulaton. So let s see how to compute normals analytcally. We re gong to assume n the followng that you know that the tangent plane at the pont s(u, v) to a surface s gven parametrcally by the equatons s spanned by the two vectors x = f(u, v), y = g(u, v), z = h(u, v) [ f u g u ] T h and u [ f v g v ] T h v evaluated at (u, v) (provded they are not collnear). Moreover, a normal vector to s at s(u, v) s the cross-product 368 [ f u g u ] T [ h f u v g v ] T h (11.15) v

41 cgbook 2018/8/22 0:58 page 369 #397 evaluated at (u, v). If you need to brush up, Secton was a revew of the needed calculus. Denote the normalzed value of the vector (11.15) obtaned by dvdng t by ts magntude by [f n (u, v) g n (u, v) h n (u, v)] T (11.16) whch, therefore, s a unt normal to s at s(u, v). Fnally, we ll specfy ether [f n (u, v) g n (u, v) h n (u, v)] T or ts reverse, [ f n (u, v) g n (u, v) h n (u, v)] T, as the unt normal at s(u, v) dependng on whch drecton s approprate for front-facng trangles. There s not much to worry about makng a wrong choce n ths last step, as t ll be plenty clear from the vewable output! Let s get to work on a bengn surface frst. Cylnder Example Consder the crcular cylnder s(u, v) wth parametrc equatons x = cos u, y = sn u, z = v, where (u, v) [ π, π] [ 1, 1] Secton Computng Normals and Lghtng Surfaces We drew t usng these equatons n cylnder.cpp of Experment To color and lght now, let s do normal calculatons. The vectors spannng the tangent plane at s(u, v) are [ x u y u ] T [ z (cos u) = u u (sn u) u ] T v = [ sn u cos u 0] T u and [ x v y v ] T [ z (cos u) = v v (sn u) v ] T v = [0 0 1] T v so a normal vector s [ sn u cos u 0 ] T [ ] T = [ cos u sn u 0] T whch happens to be normalzed already. So, n the termnology of (11.16), for the cylnder, f n (u, v) = cos u, g n (u, v) = sn u, h n (u, v) = 0 We ll add ths normal data to cylnder.cpp next. Experment Run ltcylnder.cpp, whch bulds upon cylnder.cpp usng the normal data calculated above, together wth color and a sngle drectonal lght source. Press x/x, y/y and z/z to turn the cylnder. The functonalty of beng able to change the fneness of the mesh approxmaton has been dropped. Fgure s a screenshot. End Compare the two programs cylnder.cpp and ltcylnder.cpp t s not really a lot of code from the frst to the second. Essentally, the addtons are (a) the fn(), gn() and hn() normal component functons as calculated above, (b) the fllnormalarray() functon to fll the array normals[], and (c) a bunch of routne code specfyng lght and materal propertes, whch can be kept smlar across most programs wth lghtng. Fgure 11.58: So the extra code arsng from analytc normal computaton s really n (a) and (b), Screenshot of ltcylnder.cpp. about 20 lnes all told. Not too bad, huh? And t gets better. As we used the template of cylnder.cpp to draw varous surfaces, smply swappng n new f(), g() and h() functons accordng to the gven parametrzaton, so we can use ltcylnder.cpp as a template for lt applcatons, addtonally swappng n new fn(), gn() and hn() functons for new surfaces. Exercse (Programmng) Reverse the normals of ltcylnder.cpp by changng ther specfcaton n the fllnormalarray() routne as follows: 369

42 cgbook 2018/8/22 0:58 page 370 #398 y Chapter 11 Color and Lght C z V Fgure 11.59: Normal n to a cylnder. x n normals[k++] = -fn(,j); normals[k++] = -gn(,j); normals[k++] = -hn(,j); Not good! As we remarked earler, wrongly-drected normals are easy to spot. Can you fx the problem caused by the normal values above by a mnmal amount of code change only n the drawng routne? Hnt: Thnk orentaton, n partcular, reversng the orentaton of the strp trangles. Exercse It s a bt late now, but do we really need partal dervatves, as n Example 11.11, to determne the normal to the cylnder at the pont V = (cos u, sn u, v)? The outward normal to the cylnder at V evdently les along a radus of the crcle C whch s the secton of the cylnder through V by a plane perpendcular to ts axs. See Fgure Use ths to compute the parametrc equaton for a unt normal vector to the cylnder wthout any calculus. Often, as n the precedng exercse, normals to a surface can be determned by elementary geometrc consderatons. Unfortunately, ths does not seem to be the case wth the doubly-curled cone of Experment Doubly-curled Cone Let s lght the doubly-curled cone of doublycurledcone.cpp. Its parametrc equatons are x = t cos(a + aθ) cos θ, y = t cos(a + aθ) sn θ, z = t sn(a + aθ), where 0 t 1 and 0 θ 4π. A somewhat tedous calculaton gves a normal to the cone as [ ] T [ ] T x y z x y z θ θ θ t t t = [ at sn θ + t sn(a + aθ) cos(a + aθ) cos θ, at cos θ + t sn(a + aθ) cos(a + aθ) sn θ, t cos 2 (A + aθ)] T (11.17) Moreover, the length of ths normal s t a 2 + cos 2 (A + aθ) (11.18) Dvdng the normal (11.17) by ts length (11.18) gves a unt normal to the cone. Fgure 11.60: Screenshot of ltdoubly- CurledCone.cpp. 370 Experment The program ltdoublycurledcone.cpp, n fact, apples the precedng equatons for the normal and ts length. Press x/x, y/y, z/z to turn the cone. See Fgure for a screenshot. As promsed, ltdoublycurledcone.cpp s pretty much a copy of ltcylnder.- cpp, except for the new f(), g(), h(), fn(), gn() and hn() functons, as also the new normn() to compute the normal s length. End Exercse Verfy Equatons (11.17) and (11.18) for the normal and ts magntude of the doubly-curled cone. Programmed Normal Calculaton Exact normals deduced from the equaton of a surface as n the precedng examples of the cylnder and doubly-curled cone are the most honest as we have observed. Nevertheless, f one wshes to avod admttedly often tedous calculatons, then the next program, a reworkng of ltcylnder.cpp, shows a smple programmable way to fnd approxmate normals to a surface mesh.

43 cgbook 2018/8/22 0:58 page 371 #399 Experment Run ltcylnderprogrammednormals.cpp. y/y, z/z to turn the cylnder. Fgure s a screenshot. Press x/x, Secton End Computng Normals and Lghtng Let s understand now the normal calculatons n ltcylnderprogrammedsurfaces Normals.cpp. Refer to Fgure as you read. The chord vector, call t t1(, j), from the vertex wth parameters ( 1, j) to that h T x y z wth parameters ( + 1, j), s taken as the approxmaton to the tangent u u u at the vertex V wth parameters (, j); lkewse, the chord vector t2(, j) from the vertex wth parameters (, j 1) to the one wth parameters (, j + 1) s taken as an h T y z approxmaton to the tangent x at V. Care, of course, must be taken at v v v the boundares of the parameter doman as ± 1 or j ± 1 may got out of bounds. For example, what we do f V has maxmum j-parameter value, so that j + 1 s out of bounds, s take the chord vector from the vertex wth parameters (, j 1) to V tself h T y z (the green arrow n Fgure 11.62) as the approxmaton to the tangent x v v v at V. Next, the approxmate normal un(, j) at V s taken to be the cross-product t1(, j) t2(, j). Dvdng un(, j) by ts length nl(, j) gves a normalzed approxmate normal at V. Evdently, the closer the mesh vertces,.e., the fner the mesh, the better the tangent and normal approxmatons. The neat thng about ltcylnderprogrammednormals.cpp, of course, s that the approxmate normals are calculated automatcally from the base functons f (), g() and h() defnng the surface. Therefore, one can cut and paste n any set of f (u, v), g(u, v) and h(u, v) nto the ltcylnderprogrammednormals.cpp template to nstantly llumnate the correspondng surface, normals done and dusted transparently! It s mportant to note that the method of ltcylnderprogrammednormals.cpp s applcable only f the surface s defned parametrcally by x = f (u, v), y = g(u, v), z = h(u, v) over a (trangulated) rectangular grd mesh as n Fgure 11.63(a). It s not vald for an arbtrary trangular mesh, e.g., an rregular one as n Fgure 11.63(b). However, we can stll take recourse to the suggeston at the start of the secton of approxmatng the normal to a vertex V as an average of the normals of faces ncdent at V a process whch may be automated for all meshes, wth no restrcton, gven only a descrpton of the mesh. We ask the reader to prove ths for the partcular trangulaton of ltcylnderprogrammednormals.cpp. Fgure 11.61: Screenshot of ltcylnderprogrammednormals.cpp. un(, j) V= v( 1, j) v(, j) v(, j+1) t2(, j) t1(, j) v(, j 1) v(+1, j) Fgure 11.62: Approxmate tangents and normal. (a) (b) Remark An rregular mesh may arse, for example, from trangulatng the pont cloud acqured from a laser scan of some real 3D object, such as a statue. Exercse (Programmng) Wrte a new verson of ltcylnderprogrammednormals.cpp where vertex normals are automatcally approxmated as the averages of normals of ncdent faces. Observe that, gven a surface approxmated as a stack of trangle strps, as n ths program, each vertex, typcally, wll have sx ncdent faces (Fgure 11.63(a)). However, ths may not be the case for an arbtrary trangular mesh (Fgure 11.63(b)) Fgure 11.63: A (trangulated) rectangular grd mesh and an rregular trangular mesh. FreeGLUT, Be zer and Quadrc Surfaces Lfe s about to get consderably easer! Normals come for free wth FreeGLUT surfaces OpenGL computes them automatcally wthout beng asked. Here s our workhorse ball and torus from Chapter 4 now lt (and orthographcally shadowed). Experment Run ballandtorusltorthoshadowed.cpp. Press space to start the ball travelng around the torus and the up and down arrow keys to change ts speed. Fgure s a screenshot. Fgure 11.64: Screenshot of ballandtorusltorthoshadowed.cpp. 371

44 cgbook 2018/8/22 0:58 page 372 #400 Chapter 11 Color and Lght The only user-provded normal n the program s the unt vector n the +y-drecton for the checkered floor; normals are automatc for the ball and torus, FreeGLUT objects both. The shadows are the result of smple degenerate scalng calls, as dscussed n Secton End Bézer surfaces are not much harder. All one has to do s type n the command gl- Enable(GL AUTO NORMAL) for OpenGL to automatcally calculate unt normals at the vertces of a Bézer surface whch has been created usng glmap2f(gl MAP2 VERTEX 3,... ) and glenable(gl MAP2 VERTEX 3). Let s see ths n acton. Canoe Experment Run ltbezercanoe.cpp. Press x/x, y/y, z/z to turn the canoe. You can see a screenshot n Fgure Ths program llumnates the fnal shape of bezercanoe.cpp of Experment wth a sngle drectonal lght source. Other than the expected command glenable(gl - AUTO NORMAL) n the ntalzaton routne, an mportant pont to notce about ltbezercanoe.cpp s the reversal of the sample grd along the u-drecton. In partcular, compare the statement Fgure 11.65: Screenshot of ltbezercanoe.cpp. glmapgrd2f(20, 1.0, 0.0, 20, 0.0, 1.0) of ltbezercanoe.cpp wth glmapgrd2f(20, 0.0, 1.0, 20, 0.0, 1.0) of bezercanoe.cpp. Ths change reverses the drectons of one of the tangent vectors evaluated at each vertex by OpenGL and, consequently, that of the normal (whch s the cross-product of the two tangent vectors). Modfy ltbezercanoe.cpp by changng glmapgrd2f(20, 1.0, 0.0, 20, 0.0, 1.0); back to bezercanoe.cpp s glmapgrd2f(20, 0.0, 1.0, 20, 0.0, 1.0); Wrong normal drectons! The change from bezercanoe.cpp s necessary. Another soluton would be to leave glmapgrd2f() as t s n bezercanoe.cpp, nstead makng a call to glfrontface(gl CW). End The lesson to take from ths s that f you obtan normals automatcally from OpenGL, then you mght have to subsequently alter ther orentaton for authentcty, whch s not unreasonable because OpenGL cannot know whch sde was ntended to be the front. Remark If the user wshes to defne her own normals for a Bézer surface, she can do so wth a glmap2f(gl MAP2 NORMAL,...) call. We ll not have occason to do ths ourselves. Quadrcs are smple too. The call gluquadrcnormals(qobj, GLU SMOOTH) 372 automatcally generates a normal at each vertex of the quadrc ponted by qobj. The next program we ll look at s a farly substantal anmaton whch nvokes both glenable(gl AUTO NORMAL) for Bézer surface normals and gluquadrcnormals(qobj, GLU SMOOTH) for quadrc surfaces. It also has a FreeGLUT sold cube for whch OpenGL sets up normals automatcally.

45 cgbook 2018/8/22 0:58 page 373 #401 Move wth a Shp and a Torpedo Experment Run shpmove.cpp. Pressng space starts an anmaton sequence whch begns wth a torpedo travelng toward a movng shp and ends on ts own after a few seconds. Press space agan at any tme to stop the anmaton. Fgure s a screenshot as the torpedo nears the shp. End There are a few dfferent objects n shpmove.cpp. The hull of the shp s obvously nspred by the Bézer canoe of the prevous experment. The deck s a flat Bézer surface lyng parallel to the xz-plane all ts control ponts y-values, n fact, beng dentcal desgned to ft the hull. Each of the shp s three storeys s a cylndrcal quadrc, as s ts chmney. The torpedo should be famlar from the program torpedo.cpp of Experment Each of the four graysh boats n the background s a couple of quads, whle the sea tself s a sold green cube. The smoke from the chmney s a smple-mnded so-called partcle system; n partcular, we render a sequence of quadrc dscs n pont mode and hack n a colorng and anmaton scheme. Remark The reason OpenGL can help wth the normals of FreeGLUT objects, Bézer surfaces and quadrcs s that t knows the equaton of the whole surface n fact, t s drawng the surface based on ths nternally-generated equaton makng t possble, therefore, for OpenGL to calculate normals. For an arbtrary mesh, however, OpenGL has no noton of the global surface the programmer s tryng to approxmate and, moreover, t s certanly not gong to attempt an ad hoc method a la ltcylnderprogrammednormals.cpp Transformng Normals When a surface s transformed by modelvew transformatons, so are ts normals, but not as straghtforwardly as ts vertces (whch we know are smply multpled from the left by the transformaton matrx). Let s see how normals are transformed by each of the fundamental transformatons translaton, rotaton and scalng. Secton Computng Normals and Lghtng Surfaces Fgure 11.66: Screenshot of shpmove.cpp. 1. Translaton: A translaton leaves a normal vector at a vertex unchanged because the normal smply translates parallely (see Fgure 11.67(a)). translate n p V x (b) (a) Fgure 11.67: (a) Vertex normals translate parallely as the torus s translated (b) The normal n at V s perpendcular to any vector x whch les on the tangent plane p at V. 2. Rotaton and Scalng: These cases are not as smple and requre a bt of calculaton. 373

Color in OpenGL Polygonal Shading Light Source in OpenGL Material Properties Normal Vectors Phong model

Color in OpenGL Polygonal Shading Light Source in OpenGL Material Properties Normal Vectors Phong model Color n OpenGL Polygonal Shadng Lght Source n OpenGL Materal Propertes Normal Vectors Phong model 2 We know how to rasterze - Gven a 3D trangle and a 3D vewpont, we know whch pxels represent the trangle

More information

R s s f. m y s. SPH3UW Unit 7.3 Spherical Concave Mirrors Page 1 of 12. Notes

R s s f. m y s. SPH3UW Unit 7.3 Spherical Concave Mirrors Page 1 of 12. Notes SPH3UW Unt 7.3 Sphercal Concave Mrrors Page 1 of 1 Notes Physcs Tool box Concave Mrror If the reflectng surface takes place on the nner surface of the sphercal shape so that the centre of the mrror bulges

More information

Computer Graphics. Jeng-Sheng Yeh 葉正聖 Ming Chuan University (modified from Bing-Yu Chen s slides)

Computer Graphics. Jeng-Sheng Yeh 葉正聖 Ming Chuan University (modified from Bing-Yu Chen s slides) Computer Graphcs Jeng-Sheng Yeh 葉正聖 Mng Chuan Unversty (modfed from Bng-Yu Chen s sldes) llumnaton and Shadng llumnaton Models Shadng Models for Polygons Surface Detal Shadows Transparency Global llumnaton

More information

Physics 132 4/24/17. April 24, 2017 Physics 132 Prof. E. F. Redish. Outline

Physics 132 4/24/17. April 24, 2017 Physics 132 Prof. E. F. Redish. Outline Aprl 24, 2017 Physcs 132 Prof. E. F. Redsh Theme Musc: Justn Tmberlake Mrrors Cartoon: Gary Larson The Far Sde 1 Outlne Images produced by a curved mrror Image equatons for a curved mrror Lght n dense

More information

Lighting. Dr. Scott Schaefer

Lighting. Dr. Scott Schaefer Lghtng Dr. Scott Schaefer 1 Lghtng/Illumnaton Color s a functon of how lght reflects from surfaces to the eye Global llumnaton accounts for lght from all sources as t s transmtted throughout the envronment

More information

REFRACTION. a. To study the refraction of light from plane surfaces. b. To determine the index of refraction for Acrylic and Water.

REFRACTION. a. To study the refraction of light from plane surfaces. b. To determine the index of refraction for Acrylic and Water. Purpose Theory REFRACTION a. To study the refracton of lght from plane surfaces. b. To determne the ndex of refracton for Acrylc and Water. When a ray of lght passes from one medum nto another one of dfferent

More information

Complex Numbers. Now we also saw that if a and b were both positive then ab = a b. For a second let s forget that restriction and do the following.

Complex Numbers. Now we also saw that if a and b were both positive then ab = a b. For a second let s forget that restriction and do the following. Complex Numbers The last topc n ths secton s not really related to most of what we ve done n ths chapter, although t s somewhat related to the radcals secton as we wll see. We also won t need the materal

More information

Scan Conversion & Shading

Scan Conversion & Shading Scan Converson & Shadng Thomas Funkhouser Prnceton Unversty C0S 426, Fall 1999 3D Renderng Ppelne (for drect llumnaton) 3D Prmtves 3D Modelng Coordnates Modelng Transformaton 3D World Coordnates Lghtng

More information

Scan Conversion & Shading

Scan Conversion & Shading 1 3D Renderng Ppelne (for drect llumnaton) 2 Scan Converson & Shadng Adam Fnkelsten Prnceton Unversty C0S 426, Fall 2001 3DPrmtves 3D Modelng Coordnates Modelng Transformaton 3D World Coordnates Lghtng

More information

Lecture 5: Multilayer Perceptrons

Lecture 5: Multilayer Perceptrons Lecture 5: Multlayer Perceptrons Roger Grosse 1 Introducton So far, we ve only talked about lnear models: lnear regresson and lnear bnary classfers. We noted that there are functons that can t be represented

More information

Electrical analysis of light-weight, triangular weave reflector antennas

Electrical analysis of light-weight, triangular weave reflector antennas Electrcal analyss of lght-weght, trangular weave reflector antennas Knud Pontoppdan TICRA Laederstraede 34 DK-121 Copenhagen K Denmark Emal: kp@tcra.com INTRODUCTION The new lght-weght reflector antenna

More information

3D vector computer graphics

3D vector computer graphics 3D vector computer graphcs Paolo Varagnolo: freelance engneer Padova Aprl 2016 Prvate Practce ----------------------------------- 1. Introducton Vector 3D model representaton n computer graphcs requres

More information

A Binarization Algorithm specialized on Document Images and Photos

A Binarization Algorithm specialized on Document Images and Photos A Bnarzaton Algorthm specalzed on Document mages and Photos Ergna Kavalleratou Dept. of nformaton and Communcaton Systems Engneerng Unversty of the Aegean kavalleratou@aegean.gr Abstract n ths paper, a

More information

Surface Mapping One. CS7GV3 Real-time Rendering

Surface Mapping One. CS7GV3 Real-time Rendering Surface Mappng One CS7GV3 Real-tme Renderng Textures Add complexty to scenes wthout addtonal geometry Textures store ths nformaton, can be any dmenson Many dfferent types: Dffuse most common Ambent, specular,

More information

Mathematics 256 a course in differential equations for engineering students

Mathematics 256 a course in differential equations for engineering students Mathematcs 56 a course n dfferental equatons for engneerng students Chapter 5. More effcent methods of numercal soluton Euler s method s qute neffcent. Because the error s essentally proportonal to the

More information

TN348: Openlab Module - Colocalization

TN348: Openlab Module - Colocalization TN348: Openlab Module - Colocalzaton Topc The Colocalzaton module provdes the faclty to vsualze and quantfy colocalzaton between pars of mages. The Colocalzaton wndow contans a prevew of the two mages

More information

TEST-05 TOPIC: OPTICS COMPLETE

TEST-05 TOPIC: OPTICS COMPLETE Q. A boy s walkng under an nclned mrror at a constant velocty V m/s along the x-axs as shown n fgure. If the mrror s nclned at an angle wth the horzontal then what s the velocty of the mage? Y V sn + V

More information

Intro. Iterators. 1. Access

Intro. Iterators. 1. Access Intro Ths mornng I d lke to talk a lttle bt about s and s. We wll start out wth smlartes and dfferences, then we wll see how to draw them n envronment dagrams, and we wll fnsh wth some examples. Happy

More information

6.854 Advanced Algorithms Petar Maymounkov Problem Set 11 (November 23, 2005) With: Benjamin Rossman, Oren Weimann, and Pouya Kheradpour

6.854 Advanced Algorithms Petar Maymounkov Problem Set 11 (November 23, 2005) With: Benjamin Rossman, Oren Weimann, and Pouya Kheradpour 6.854 Advanced Algorthms Petar Maymounkov Problem Set 11 (November 23, 2005) Wth: Benjamn Rossman, Oren Wemann, and Pouya Kheradpour Problem 1. We reduce vertex cover to MAX-SAT wth weghts, such that the

More information

For instance, ; the five basic number-sets are increasingly more n A B & B A A = B (1)

For instance, ; the five basic number-sets are increasingly more n A B & B A A = B (1) Secton 1.2 Subsets and the Boolean operatons on sets If every element of the set A s an element of the set B, we say that A s a subset of B, or that A s contaned n B, or that B contans A, and we wrte A

More information

AP PHYSICS B 2008 SCORING GUIDELINES

AP PHYSICS B 2008 SCORING GUIDELINES AP PHYSICS B 2008 SCORING GUIDELINES General Notes About 2008 AP Physcs Scorng Gudelnes 1. The solutons contan the most common method of solvng the free-response questons and the allocaton of ponts for

More information

Brave New World Pseudocode Reference

Brave New World Pseudocode Reference Brave New World Pseudocode Reference Pseudocode s a way to descrbe how to accomplsh tasks usng basc steps lke those a computer mght perform. In ths week s lab, you'll see how a form of pseudocode can be

More information

Dependence of the Color Rendering Index on the Luminance of Light Sources and Munsell Samples

Dependence of the Color Rendering Index on the Luminance of Light Sources and Munsell Samples Australan Journal of Basc and Appled Scences, 4(10): 4609-4613, 2010 ISSN 1991-8178 Dependence of the Color Renderng Index on the Lumnance of Lght Sources and Munsell Samples 1 A. EL-Bally (Physcs Department),

More information

SLAM Summer School 2006 Practical 2: SLAM using Monocular Vision

SLAM Summer School 2006 Practical 2: SLAM using Monocular Vision SLAM Summer School 2006 Practcal 2: SLAM usng Monocular Vson Javer Cvera, Unversty of Zaragoza Andrew J. Davson, Imperal College London J.M.M Montel, Unversty of Zaragoza. josemar@unzar.es, jcvera@unzar.es,

More information

Chapter 6 Programmng the fnte element method Inow turn to the man subject of ths book: The mplementaton of the fnte element algorthm n computer programs. In order to make my dscusson as straghtforward

More information

Analysis of Continuous Beams in General

Analysis of Continuous Beams in General Analyss of Contnuous Beams n General Contnuous beams consdered here are prsmatc, rgdly connected to each beam segment and supported at varous ponts along the beam. onts are selected at ponts of support,

More information

Slide 1 SPH3UW: OPTICS I. Slide 2. Slide 3. Introduction to Mirrors. Light incident on an object

Slide 1 SPH3UW: OPTICS I. Slide 2. Slide 3. Introduction to Mirrors. Light incident on an object Slde 1 SPH3UW: OPTICS I Introducton to Mrrors Slde 2 Lght ncdent on an object Absorpton Relecton (bounces)** See t Mrrors Reracton (bends) Lenses Oten some o each Everythng true or wavelengths

More information

Monte Carlo Rendering

Monte Carlo Rendering Monte Carlo Renderng Last Tme? Modern Graphcs Hardware Cg Programmng Language Gouraud Shadng vs. Phong Normal Interpolaton Bump, Dsplacement, & Envronment Mappng Cg Examples G P R T F P D Today Does Ray

More information

CMPS 10 Introduction to Computer Science Lecture Notes

CMPS 10 Introduction to Computer Science Lecture Notes CPS 0 Introducton to Computer Scence Lecture Notes Chapter : Algorthm Desgn How should we present algorthms? Natural languages lke Englsh, Spansh, or French whch are rch n nterpretaton and meanng are not

More information

Lecture #15 Lecture Notes

Lecture #15 Lecture Notes Lecture #15 Lecture Notes The ocean water column s very much a 3-D spatal entt and we need to represent that structure n an economcal way to deal wth t n calculatons. We wll dscuss one way to do so, emprcal

More information

Reading. 14. Subdivision curves. Recommended:

Reading. 14. Subdivision curves. Recommended: eadng ecommended: Stollntz, Deose, and Salesn. Wavelets for Computer Graphcs: heory and Applcatons, 996, secton 6.-6., A.5. 4. Subdvson curves Note: there s an error n Stollntz, et al., secton A.5. Equaton

More information

Accounting for the Use of Different Length Scale Factors in x, y and z Directions

Accounting for the Use of Different Length Scale Factors in x, y and z Directions 1 Accountng for the Use of Dfferent Length Scale Factors n x, y and z Drectons Taha Soch (taha.soch@kcl.ac.uk) Imagng Scences & Bomedcal Engneerng, Kng s College London, The Rayne Insttute, St Thomas Hosptal,

More information

Assignment # 2. Farrukh Jabeen Algorithms 510 Assignment #2 Due Date: June 15, 2009.

Assignment # 2. Farrukh Jabeen Algorithms 510 Assignment #2 Due Date: June 15, 2009. Farrukh Jabeen Algorthms 51 Assgnment #2 Due Date: June 15, 29. Assgnment # 2 Chapter 3 Dscrete Fourer Transforms Implement the FFT for the DFT. Descrbed n sectons 3.1 and 3.2. Delverables: 1. Concse descrpton

More information

Wishing you all a Total Quality New Year!

Wishing you all a Total Quality New Year! Total Qualty Management and Sx Sgma Post Graduate Program 214-15 Sesson 4 Vnay Kumar Kalakband Assstant Professor Operatons & Systems Area 1 Wshng you all a Total Qualty New Year! Hope you acheve Sx sgma

More information

FEATURE EXTRACTION. Dr. K.Vijayarekha. Associate Dean School of Electrical and Electronics Engineering SASTRA University, Thanjavur

FEATURE EXTRACTION. Dr. K.Vijayarekha. Associate Dean School of Electrical and Electronics Engineering SASTRA University, Thanjavur FEATURE EXTRACTION Dr. K.Vjayarekha Assocate Dean School of Electrcal and Electroncs Engneerng SASTRA Unversty, Thanjavur613 41 Jont Intatve of IITs and IISc Funded by MHRD Page 1 of 8 Table of Contents

More information

Computer Animation and Visualisation. Lecture 4. Rigging / Skinning

Computer Animation and Visualisation. Lecture 4. Rigging / Skinning Computer Anmaton and Vsualsaton Lecture 4. Rggng / Sknnng Taku Komura Overvew Sknnng / Rggng Background knowledge Lnear Blendng How to decde weghts? Example-based Method Anatomcal models Sknnng Assume

More information

Compiler Design. Spring Register Allocation. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Compiler Design. Spring Register Allocation. Sample Exercises and Solutions. Prof. Pedro C. Diniz Compler Desgn Sprng 2014 Regster Allocaton Sample Exercses and Solutons Prof. Pedro C. Dnz USC / Informaton Scences Insttute 4676 Admralty Way, Sute 1001 Marna del Rey, Calforna 90292 pedro@s.edu Regster

More information

Support Vector Machines

Support Vector Machines /9/207 MIST.6060 Busness Intellgence and Data Mnng What are Support Vector Machnes? Support Vector Machnes Support Vector Machnes (SVMs) are supervsed learnng technques that analyze data and recognze patterns.

More information

Some Tutorial about the Project. Computer Graphics

Some Tutorial about the Project. Computer Graphics Some Tutoral about the Project Lecture 6 Rastersaton, Antalasng, Texture Mappng, I have already covered all the topcs needed to fnsh the 1 st practcal Today, I wll brefly explan how to start workng on

More information

PHYS 219 Spring semester Lecture 20: Reflection of Electromagnetic Radiation: Mirrors and Images Formed by Mirrors

PHYS 219 Spring semester Lecture 20: Reflection of Electromagnetic Radiation: Mirrors and Images Formed by Mirrors PHYS 219 Sprng semester 2014 Lecture 20: eflecton of Electromagnetc adaton: Mrrors and Images Formed by Mrrors on efenberger Brck Nanotechnology Center Purdue Unversty Lecture 20 1 evew: Snapshot of an

More information

LINE ARRAYS CONCEPTS AND MODELING TOOLS. Jeff Berryman May 29, 2010 / Rev. 1

LINE ARRAYS CONCEPTS AND MODELING TOOLS. Jeff Berryman May 29, 2010 / Rev. 1 LINE ARRAYS CONCEPTS AND MODELING TOOLS Jeff Berryman May 29, 2010 / Rev. 1 A lne array s a stack of loudspeaker systems n a sngle lne. The lne s usually curved. Uncurved lnes do not have desrable drectonal

More information

Programming in Fortran 90 : 2017/2018

Programming in Fortran 90 : 2017/2018 Programmng n Fortran 90 : 2017/2018 Programmng n Fortran 90 : 2017/2018 Exercse 1 : Evaluaton of functon dependng on nput Wrte a program who evaluate the functon f (x,y) for any two user specfed values

More information

UNIT 2 : INEQUALITIES AND CONVEX SETS

UNIT 2 : INEQUALITIES AND CONVEX SETS UNT 2 : NEQUALTES AND CONVEX SETS ' Structure 2. ntroducton Objectves, nequaltes and ther Graphs Convex Sets and ther Geometry Noton of Convex Sets Extreme Ponts of Convex Set Hyper Planes and Half Spaces

More information

Real-time. Shading of Folded Surfaces

Real-time. Shading of Folded Surfaces Rhensche Fredrch-Wlhelms-Unverstät Bonn Insttute of Computer Scence II Computer Graphcs Real-tme Shadng of Folded Surfaces B. Ganster, R. Klen, M. Sattler, R. Sarlette Motvaton http://www www.vrtualtryon.de

More information

Range images. Range image registration. Examples of sampling patterns. Range images and range surfaces

Range images. Range image registration. Examples of sampling patterns. Range images and range surfaces Range mages For many structured lght scanners, the range data forms a hghly regular pattern known as a range mage. he samplng pattern s determned by the specfc scanner. Range mage regstraton 1 Examples

More information

2D Raster Graphics. Integer grid Sequential (left-right, top-down) scan. Computer Graphics

2D Raster Graphics. Integer grid Sequential (left-right, top-down) scan. Computer Graphics 2D Graphcs 2D Raster Graphcs Integer grd Sequental (left-rght, top-down scan j Lne drawng A ver mportant operaton used frequentl, block dagrams, bar charts, engneerng drawng, archtecture plans, etc. curves

More information

User Authentication Based On Behavioral Mouse Dynamics Biometrics

User Authentication Based On Behavioral Mouse Dynamics Biometrics User Authentcaton Based On Behavoral Mouse Dynamcs Bometrcs Chee-Hyung Yoon Danel Donghyun Km Department of Computer Scence Department of Computer Scence Stanford Unversty Stanford Unversty Stanford, CA

More information

Hermite Splines in Lie Groups as Products of Geodesics

Hermite Splines in Lie Groups as Products of Geodesics Hermte Splnes n Le Groups as Products of Geodescs Ethan Eade Updated May 28, 2017 1 Introducton 1.1 Goal Ths document defnes a curve n the Le group G parametrzed by tme and by structural parameters n the

More information

REFRACTIVE INDEX SELECTION FOR POWDER MIXTURES

REFRACTIVE INDEX SELECTION FOR POWDER MIXTURES REFRACTIVE INDEX SELECTION FOR POWDER MIXTURES Laser dffracton s one of the most wdely used methods for partcle sze analyss of mcron and submcron sze powders and dspersons. It s quck and easy and provdes

More information

USING GRAPHING SKILLS

USING GRAPHING SKILLS Name: BOLOGY: Date: _ Class: USNG GRAPHNG SKLLS NTRODUCTON: Recorded data can be plotted on a graph. A graph s a pctoral representaton of nformaton recorded n a data table. t s used to show a relatonshp

More information

S1 Note. Basis functions.

S1 Note. Basis functions. S1 Note. Bass functons. Contents Types of bass functons...1 The Fourer bass...2 B-splne bass...3 Power and type I error rates wth dfferent numbers of bass functons...4 Table S1. Smulaton results of type

More information

A Fast Visual Tracking Algorithm Based on Circle Pixels Matching

A Fast Visual Tracking Algorithm Based on Circle Pixels Matching A Fast Vsual Trackng Algorthm Based on Crcle Pxels Matchng Zhqang Hou hou_zhq@sohu.com Chongzhao Han czhan@mal.xjtu.edu.cn Ln Zheng Abstract: A fast vsual trackng algorthm based on crcle pxels matchng

More information

Content Based Image Retrieval Using 2-D Discrete Wavelet with Texture Feature with Different Classifiers

Content Based Image Retrieval Using 2-D Discrete Wavelet with Texture Feature with Different Classifiers IOSR Journal of Electroncs and Communcaton Engneerng (IOSR-JECE) e-issn: 78-834,p- ISSN: 78-8735.Volume 9, Issue, Ver. IV (Mar - Apr. 04), PP 0-07 Content Based Image Retreval Usng -D Dscrete Wavelet wth

More information

DIFFRACTION SHADING MODELS FOR IRIDESCENT SURFACES

DIFFRACTION SHADING MODELS FOR IRIDESCENT SURFACES DIFFRACTION SHADING MODELS FOR IRIDESCENT SURFACES Emmanuel Agu Department of Computer Scence Worcester Polytechnc Insttute, Worcester, MA 01609, USA emmanuel@cs.wp.edu Francs S.Hll Jr Department of Electrcal

More information

Welcome to the Three Ring %CIRCOS: An Example of Creating a Circular Graph without a Polar Axis

Welcome to the Three Ring %CIRCOS: An Example of Creating a Circular Graph without a Polar Axis PharmaSUG 2018 - Paper DV14 Welcome to the Three Rng %CIRCOS: An Example of Creatng a Crcular Graph wthout a Polar Axs Jeffrey Meyers, Mayo Clnc ABSTRACT An nternal graphcs challenge between SAS and R

More information

Assembler. Shimon Schocken. Spring Elements of Computing Systems 1 Assembler (Ch. 6) Compiler. abstract interface.

Assembler. Shimon Schocken. Spring Elements of Computing Systems 1 Assembler (Ch. 6) Compiler. abstract interface. IDC Herzlya Shmon Schocken Assembler Shmon Schocken Sprng 2005 Elements of Computng Systems 1 Assembler (Ch. 6) Where we are at: Human Thought Abstract desgn Chapters 9, 12 abstract nterface H.L. Language

More information

An Approach in Coloring Semi-Regular Tilings on the Hyperbolic Plane

An Approach in Coloring Semi-Regular Tilings on the Hyperbolic Plane An Approach n Colorng Sem-Regular Tlngs on the Hyperbolc Plane Ma Louse Antonette N De Las Peñas, mlp@mathscmathadmueduph Glenn R Lago, glago@yahoocom Math Department, Ateneo de Manla Unversty, Loyola

More information

y and the total sum of

y and the total sum of Lnear regresson Testng for non-lnearty In analytcal chemstry, lnear regresson s commonly used n the constructon of calbraton functons requred for analytcal technques such as gas chromatography, atomc absorpton

More information

Parallel matrix-vector multiplication

Parallel matrix-vector multiplication Appendx A Parallel matrx-vector multplcaton The reduced transton matrx of the three-dmensonal cage model for gel electrophoress, descrbed n secton 3.2, becomes excessvely large for polymer lengths more

More information

Computer models of motion: Iterative calculations

Computer models of motion: Iterative calculations Computer models o moton: Iteratve calculatons OBJECTIVES In ths actvty you wll learn how to: Create 3D box objects Update the poston o an object teratvely (repeatedly) to anmate ts moton Update the momentum

More information

Improvement of Spatial Resolution Using BlockMatching Based Motion Estimation and Frame. Integration

Improvement of Spatial Resolution Using BlockMatching Based Motion Estimation and Frame. Integration Improvement of Spatal Resoluton Usng BlockMatchng Based Moton Estmaton and Frame Integraton Danya Suga and Takayuk Hamamoto Graduate School of Engneerng, Tokyo Unversty of Scence, 6-3-1, Nuku, Katsuska-ku,

More information

Introduction to Geometrical Optics - a 2D ray tracing Excel model for spherical mirrors - Part 2

Introduction to Geometrical Optics - a 2D ray tracing Excel model for spherical mirrors - Part 2 Introducton to Geometrcal Optcs - a D ra tracng Ecel model for sphercal mrrors - Part b George ungu - Ths s a tutoral eplanng the creaton of an eact D ra tracng model for both sphercal concave and sphercal

More information

Global Illumination: Radiosity

Global Illumination: Radiosity Last Tme? Global Illumnaton: Radosty Planar Shadows Shadow Maps An early applcaton of radatve heat transfer n stables. Projectve Texture Shadows (Texture Mappng) Shadow Volumes (Stencl Buffer) Schedule

More information

Any Pair of 2D Curves Is Consistent with a 3D Symmetric Interpretation

Any Pair of 2D Curves Is Consistent with a 3D Symmetric Interpretation Symmetry 2011, 3, 365-388; do:10.3390/sym3020365 OPEN ACCESS symmetry ISSN 2073-8994 www.mdp.com/journal/symmetry Artcle Any Par of 2D Curves Is Consstent wth a 3D Symmetrc Interpretaton Tadamasa Sawada

More information

Harvard University CS 101 Fall 2005, Shimon Schocken. Assembler. Elements of Computing Systems 1 Assembler (Ch. 6)

Harvard University CS 101 Fall 2005, Shimon Schocken. Assembler. Elements of Computing Systems 1 Assembler (Ch. 6) Harvard Unversty CS 101 Fall 2005, Shmon Schocken Assembler Elements of Computng Systems 1 Assembler (Ch. 6) Why care about assemblers? Because Assemblers employ some nfty trcks Assemblers are the frst

More information

2x x l. Module 3: Element Properties Lecture 4: Lagrange and Serendipity Elements

2x x l. Module 3: Element Properties Lecture 4: Lagrange and Serendipity Elements Module 3: Element Propertes Lecture : Lagrange and Serendpty Elements 5 In last lecture note, the nterpolaton functons are derved on the bass of assumed polynomal from Pascal s trangle for the fled varable.

More information

Steps for Computing the Dissimilarity, Entropy, Herfindahl-Hirschman and. Accessibility (Gravity with Competition) Indices

Steps for Computing the Dissimilarity, Entropy, Herfindahl-Hirschman and. Accessibility (Gravity with Competition) Indices Steps for Computng the Dssmlarty, Entropy, Herfndahl-Hrschman and Accessblty (Gravty wth Competton) Indces I. Dssmlarty Index Measurement: The followng formula can be used to measure the evenness between

More information

The Codesign Challenge

The Codesign Challenge ECE 4530 Codesgn Challenge Fall 2007 Hardware/Software Codesgn The Codesgn Challenge Objectves In the codesgn challenge, your task s to accelerate a gven software reference mplementaton as fast as possble.

More information

Assembler. Building a Modern Computer From First Principles.

Assembler. Building a Modern Computer From First Principles. Assembler Buldng a Modern Computer From Frst Prncples www.nand2tetrs.org Elements of Computng Systems, Nsan & Schocken, MIT Press, www.nand2tetrs.org, Chapter 6: Assembler slde Where we are at: Human Thought

More information

Diffuse and specular interreflections with classical, deterministic ray tracing

Diffuse and specular interreflections with classical, deterministic ray tracing Dffuse and specular nterreflectons wth classcal, determnstc ray tracng Gergely Vass gergely_vass@sggraph.org Dept. of Control Engneerng and Informaton Technology Techncal Unversty of Budapest Budapest,

More information

Global Illumination and Radiosity

Global Illumination and Radiosity Global Illumnaton and Radosty CS535 Danel G. Alaga Department of Computer Scence Purdue Unversty Recall: Lghtng and Shadng Lght sources Pont lght Models an omndrectonal lght source (e.g., a bulb) Drectonal

More information

Solving two-person zero-sum game by Matlab

Solving two-person zero-sum game by Matlab Appled Mechancs and Materals Onlne: 2011-02-02 ISSN: 1662-7482, Vols. 50-51, pp 262-265 do:10.4028/www.scentfc.net/amm.50-51.262 2011 Trans Tech Publcatons, Swtzerland Solvng two-person zero-sum game by

More information

The notion of orientation is vitally important in CG when drawing 3D scenes

The notion of orientation is vitally important in CG when drawing 3D scenes cgbook 2018/8/22 0:58 page 249 #277 CHAPTER 9 Orentaton The noton of orentaton s vtally mportant n CG when drawng 3D scenes but, unfortunately, often confusng for the begnner. OpenGL tself makes crtcal

More information

Array transposition in CUDA shared memory

Array transposition in CUDA shared memory Array transposton n CUDA shared memory Mke Gles February 19, 2014 Abstract Ths short note s nspred by some code wrtten by Jeremy Appleyard for the transposton of data through shared memory. I had some

More information

3D Virtual Eyeglass Frames Modeling from Multiple Camera Image Data Based on the GFFD Deformation Method

3D Virtual Eyeglass Frames Modeling from Multiple Camera Image Data Based on the GFFD Deformation Method NICOGRAPH Internatonal 2012, pp. 114-119 3D Vrtual Eyeglass Frames Modelng from Multple Camera Image Data Based on the GFFD Deformaton Method Norak Tamura, Somsangouane Sngthemphone and Katsuhro Ktama

More information

Cluster Analysis of Electrical Behavior

Cluster Analysis of Electrical Behavior Journal of Computer and Communcatons, 205, 3, 88-93 Publshed Onlne May 205 n ScRes. http://www.scrp.org/ournal/cc http://dx.do.org/0.4236/cc.205.350 Cluster Analyss of Electrcal Behavor Ln Lu Ln Lu, School

More information

Lobachevsky State University of Nizhni Novgorod. Polyhedron. Quick Start Guide

Lobachevsky State University of Nizhni Novgorod. Polyhedron. Quick Start Guide Lobachevsky State Unversty of Nzhn Novgorod Polyhedron Quck Start Gude Nzhn Novgorod 2016 Contents Specfcaton of Polyhedron software... 3 Theoretcal background... 4 1. Interface of Polyhedron... 6 1.1.

More information

Inverse Kinematics (part 2) CSE169: Computer Animation Instructor: Steve Rotenberg UCSD, Spring 2016

Inverse Kinematics (part 2) CSE169: Computer Animation Instructor: Steve Rotenberg UCSD, Spring 2016 Inverse Knematcs (part 2) CSE169: Computer Anmaton Instructor: Steve Rotenberg UCSD, Sprng 2016 Forward Knematcs We wll use the vector: Φ... 1 2 M to represent the array of M jont DOF values We wll also

More information

Global Illumination and Radiosity

Global Illumination and Radiosity Global Illumnaton and Radosty CS535 Danel G. Alaga Department of Computer Scence Purdue Unversty Recall: Lghtng and Shadng Lght sources Pont lght Models an omndrectonal lght source (e.g., a bulb) Drectonal

More information

A high precision collaborative vision measurement of gear chamfering profile

A high precision collaborative vision measurement of gear chamfering profile Internatonal Conference on Advances n Mechancal Engneerng and Industral Informatcs (AMEII 05) A hgh precson collaboratve vson measurement of gear chamferng profle Conglng Zhou, a, Zengpu Xu, b, Chunmng

More information

Problem Set 3 Solutions

Problem Set 3 Solutions Introducton to Algorthms October 4, 2002 Massachusetts Insttute of Technology 6046J/18410J Professors Erk Demane and Shaf Goldwasser Handout 14 Problem Set 3 Solutons (Exercses were not to be turned n,

More information

Discussion. History and Outline. Smoothness of Indirect Lighting. Irradiance Caching. Irradiance Calculation. Advanced Computer Graphics (Fall 2009)

Discussion. History and Outline. Smoothness of Indirect Lighting. Irradiance Caching. Irradiance Calculation. Advanced Computer Graphics (Fall 2009) Advanced Computer Graphcs (Fall 2009 CS 29, Renderng Lecture 6: Recent Advances n Monte Carlo Offlne Renderng Rav Ramamoorth http://nst.eecs.berkeley.edu/~cs29-13/fa09 Dscusson Problems dfferent over years.

More information

ROBOT KINEMATICS. ME Robotics ME Robotics

ROBOT KINEMATICS. ME Robotics ME Robotics ROBOT KINEMATICS Purpose: The purpose of ths chapter s to ntroduce you to robot knematcs, and the concepts related to both open and closed knematcs chans. Forward knematcs s dstngushed from nverse knematcs.

More information

An Optimal Algorithm for Prufer Codes *

An Optimal Algorithm for Prufer Codes * J. Software Engneerng & Applcatons, 2009, 2: 111-115 do:10.4236/jsea.2009.22016 Publshed Onlne July 2009 (www.scrp.org/journal/jsea) An Optmal Algorthm for Prufer Codes * Xaodong Wang 1, 2, Le Wang 3,

More information

Machine Learning: Algorithms and Applications

Machine Learning: Algorithms and Applications 14/05/1 Machne Learnng: Algorthms and Applcatons Florano Zn Free Unversty of Bozen-Bolzano Faculty of Computer Scence Academc Year 011-01 Lecture 10: 14 May 01 Unsupervsed Learnng cont Sldes courtesy of

More information

VISUAL SELECTION OF SURFACE FEATURES DURING THEIR GEOMETRIC SIMULATION WITH THE HELP OF COMPUTER TECHNOLOGIES

VISUAL SELECTION OF SURFACE FEATURES DURING THEIR GEOMETRIC SIMULATION WITH THE HELP OF COMPUTER TECHNOLOGIES UbCC 2011, Volume 6, 5002981-x manuscrpts OPEN ACCES UbCC Journal ISSN 1992-8424 www.ubcc.org VISUAL SELECTION OF SURFACE FEATURES DURING THEIR GEOMETRIC SIMULATION WITH THE HELP OF COMPUTER TECHNOLOGIES

More information

Reducing Frame Rate for Object Tracking

Reducing Frame Rate for Object Tracking Reducng Frame Rate for Object Trackng Pavel Korshunov 1 and We Tsang Oo 2 1 Natonal Unversty of Sngapore, Sngapore 11977, pavelkor@comp.nus.edu.sg 2 Natonal Unversty of Sngapore, Sngapore 11977, oowt@comp.nus.edu.sg

More information

An Application of the Dulmage-Mendelsohn Decomposition to Sparse Null Space Bases of Full Row Rank Matrices

An Application of the Dulmage-Mendelsohn Decomposition to Sparse Null Space Bases of Full Row Rank Matrices Internatonal Mathematcal Forum, Vol 7, 2012, no 52, 2549-2554 An Applcaton of the Dulmage-Mendelsohn Decomposton to Sparse Null Space Bases of Full Row Rank Matrces Mostafa Khorramzadeh Department of Mathematcal

More information

S.P.H. : A SOLUTION TO AVOID USING EROSION CRITERION?

S.P.H. : A SOLUTION TO AVOID USING EROSION CRITERION? S.P.H. : A SOLUTION TO AVOID USING EROSION CRITERION? Célne GALLET ENSICA 1 place Emle Bloun 31056 TOULOUSE CEDEX e-mal :cgallet@ensca.fr Jean Luc LACOME DYNALIS Immeuble AEROPOLE - Bat 1 5, Avenue Albert

More information

Lecture 13: High-dimensional Images

Lecture 13: High-dimensional Images Lec : Hgh-dmensonal Images Grayscale Images Lecture : Hgh-dmensonal Images Math 90 Prof. Todd Wttman The Ctadel A grayscale mage s an nteger-valued D matrx. An 8-bt mage takes on values between 0 and 55.

More information

A MOVING MESH APPROACH FOR SIMULATION BUDGET ALLOCATION ON CONTINUOUS DOMAINS

A MOVING MESH APPROACH FOR SIMULATION BUDGET ALLOCATION ON CONTINUOUS DOMAINS Proceedngs of the Wnter Smulaton Conference M E Kuhl, N M Steger, F B Armstrong, and J A Jones, eds A MOVING MESH APPROACH FOR SIMULATION BUDGET ALLOCATION ON CONTINUOUS DOMAINS Mark W Brantley Chun-Hung

More information

Kiran Joy, International Journal of Advanced Engineering Technology E-ISSN

Kiran Joy, International Journal of Advanced Engineering Technology E-ISSN Kran oy, nternatonal ournal of Advanced Engneerng Technology E-SS 0976-3945 nt Adv Engg Tech/Vol. V/ssue /Aprl-une,04/9-95 Research Paper DETERMATO O RADATVE VEW ACTOR WTOUT COSDERG TE SADOWG EECT Kran

More information

A fault tree analysis strategy using binary decision diagrams

A fault tree analysis strategy using binary decision diagrams Loughborough Unversty Insttutonal Repostory A fault tree analyss strategy usng bnary decson dagrams Ths tem was submtted to Loughborough Unversty's Insttutonal Repostory by the/an author. Addtonal Informaton:

More information

NAG Fortran Library Chapter Introduction. G10 Smoothing in Statistics

NAG Fortran Library Chapter Introduction. G10 Smoothing in Statistics Introducton G10 NAG Fortran Lbrary Chapter Introducton G10 Smoothng n Statstcs Contents 1 Scope of the Chapter... 2 2 Background to the Problems... 2 2.1 Smoothng Methods... 2 2.2 Smoothng Splnes and Regresson

More information

Discussion. History and Outline. Smoothness of Indirect Lighting. Irradiance Calculation. Irradiance Caching. Advanced Computer Graphics (Fall 2009)

Discussion. History and Outline. Smoothness of Indirect Lighting. Irradiance Calculation. Irradiance Caching. Advanced Computer Graphics (Fall 2009) Advanced Computer Graphcs (Fall 2009 CS 283, Lecture 13: Recent Advances n Monte Carlo Offlne Renderng Rav Ramamoorth http://nst.eecs.berkeley.edu/~cs283/fa10 Dscusson Problems dfferent over years. Intally,

More information

ELEC 377 Operating Systems. Week 6 Class 3

ELEC 377 Operating Systems. Week 6 Class 3 ELEC 377 Operatng Systems Week 6 Class 3 Last Class Memory Management Memory Pagng Pagng Structure ELEC 377 Operatng Systems Today Pagng Szes Vrtual Memory Concept Demand Pagng ELEC 377 Operatng Systems

More information

Edge Detection in Noisy Images Using the Support Vector Machines

Edge Detection in Noisy Images Using the Support Vector Machines Edge Detecton n Nosy Images Usng the Support Vector Machnes Hlaro Gómez-Moreno, Saturnno Maldonado-Bascón, Francsco López-Ferreras Sgnal Theory and Communcatons Department. Unversty of Alcalá Crta. Madrd-Barcelona

More information

Some material adapted from Mohamed Younis, UMBC CMSC 611 Spr 2003 course slides Some material adapted from Hennessy & Patterson / 2003 Elsevier

Some material adapted from Mohamed Younis, UMBC CMSC 611 Spr 2003 course slides Some material adapted from Hennessy & Patterson / 2003 Elsevier Some materal adapted from Mohamed Youns, UMBC CMSC 611 Spr 2003 course sldes Some materal adapted from Hennessy & Patterson / 2003 Elsever Scence Performance = 1 Executon tme Speedup = Performance (B)

More information

Data Representation in Digital Design, a Single Conversion Equation and a Formal Languages Approach

Data Representation in Digital Design, a Single Conversion Equation and a Formal Languages Approach Data Representaton n Dgtal Desgn, a Sngle Converson Equaton and a Formal Languages Approach Hassan Farhat Unversty of Nebraska at Omaha Abstract- In the study of data representaton n dgtal desgn and computer

More information

BioTechnology. An Indian Journal FULL PAPER. Trade Science Inc.

BioTechnology. An Indian Journal FULL PAPER. Trade Science Inc. [Type text] [Type text] [Type text] ISSN : 0974-74 Volume 0 Issue BoTechnology 04 An Indan Journal FULL PAPER BTAIJ 0() 04 [684-689] Revew on Chna s sports ndustry fnancng market based on market -orented

More information