Reading Optional: Angel and Shreiner: chapter 5. Marchner and Shirley: chapter 0, chapter 7. Shading Further reading: OpenGL red book, chapter 5. Brian Curle CSE 457 Spring 207 2 Baic 3D graphic With affine matrice, we can now tranform virtual 3D object in their local coordinate ytem into a global (world) coordinate ytem: Pinhole camera To create an image of a virtual cene, we need to define a camera, and we need to model lighting and hading. For the camera, we ue a pinhole camera. M M 2 [Angel, 20] The image i rendered onto an image plane (uually in front of the camera). To yntheize an image of the cene, we alo need to add light ource and a viewer/camera: Viewing ray emanate from the center of projection (COP) at the center of the pinhole. 3 The image of an object point P i at the interection of the viewing ray through P and the image plane. But i P viible? Thi the problem of hidden urface removal (a.k.a., viible urface determination). We ll conider thi problem later. 4
Shading An abundance of photon Next, we ll need a model to decribe how light interact with urface. Such a model i called a hading model. Other name: Lighting model Light reflection model Local illumination model Reflectance model BRDF Given the camera and hading model, properly determining the right color at each pixel i extremely hard. Look around the room. Each light ource ha different characteritic. Trillion of photon are pouring out every econd. Thee photon can: interact with molecule and particle in the air ( participating media ) trike a urface and be aborbed be reflected (cattered) caue fluorecence or phophorecence. interact in a wavelength-dependent manner generally bounce around and around 5 6 Our problem Setup We re going to build up to a approximation of reality called the Phong and Blinn-Phong illumination model. They have the following characteritic: not phyically correct give a firt-order approximation to phyical light reflection very fat widely ued In addition, we will aume local illumination, i.e., light goe: light ource -> urface -> viewer. No interreflection, no hadow. Given: a point P on a urface viible through pixel p The normal N at P The lighting direction, L, and (color) intenity, I L, at P The viewing direction, V, at P The hading coefficient at P Compute the color, I, of pixel p. Aume that the direction vector are normalized: N L V 7 8
Iteration zero Iteration one The implet thing you can do i Aign each polygon a ingle color: I=k e where I i the reulting intenity k e i the emiivity or intrinic hade aociated with the object Thi ha ome pecial-purpoe ue, but not really good for drawing a cene. Let make the color at leat dependent on the overall quantity of light available in the cene: Ik k I k a i the ambient reflection coefficient. really the reflectance of ambient light ambient light i aumed to be equal in all direction I La i the ambient light intenity. Phyically, what i ambient light? e 9 0 Wavelength dependence Diffue reflector Really, k e, k a, and I La are function over all wavelength. Ideally, we would do the calculation on thee function. For the ambient hading equation, we would tart with: I ( ) =k ( ) I ( ) then we would find good RGB value to repreent the pectrum I (). a La Emiive and ambient reflection don t model realitic lighting and reflection. To improve thi, we will look at diffue (a.k.a., Lambertian) reflection. Diffue reflection can occur from dull, matte urface, like latex paint, or chalk. Thee diffue reflector reradiate light equally in all direction. Picture a rough urface with lot of tiny microfacet. Traditionally, though, k a and I La are repreented a RGB triple, and the computation i performed on each color channel eparately: I =k I I I =k I R R R G G G =k a ILa B B B 2
Diffue reflector Diffue reflector, cont. or picture a urface with little pigment particle embedded beneath the urface (neglect reflection at the urface for the moment): The reflected intenity from a diffue urface doe not depend on the direction of the viewer. The incoming light, though, doe depend on the direction of the light ource: The microfacet and pigment ditribute light ray in all direction. Embedded pigment are reponible for the coloration of diffuely reflected light in platic and paint. Note: the figure in thi and the previou lide are intuitive, but not trictly (phyically) correct. 3 4 Iteration two Specular reflection The incoming energy i proportional to the diffue reflection equation:, giving Specular reflection account for the highlight that you ee on ome object. I=k +k I e d L +k I B =k +k I +k I B( ) e d L where: k d i the diffue reflection coefficient I L i the (color) intenity of the light ource N i the normal to the urface (unit vector) L i the direction to the light ource (unit vector) B prevent contribution of light from below the urface: if NL 0 B= 0 if NL 0 It i particularly important for mooth, hiny urface, uch a: metal polihed tone platic apple kin Propertie: Specular reflection depend on the viewing direction V. For non-metal, the color i determined olely by the color of the light. For metal, the color may be altered (e.g., bra) 5 6
Specular reflection derivation Phong pecular reflection co n φ 0.9 0.8 0.7 0.6 n = 0.5 0.4 0.3 0.2 For a perfect mirror reflector, light i reflected about N, o I L if V R I 0 otherwie For a near-perfect reflector, you might expect the highlight to fall off quickly with increaing angle. Alo known a: rough pecular reflection directional diffue reflection gloy reflection 0. n = 28 0 00 80 60 40 20 0 20 40 60 80 00 One way to get thi effect i to take (R V), raied to a power n. Phong pecular reflection i proportional to: where (x ) + max(0, x ). n pecular ~ B RV I ( ) Q: A n get larger, doe the highlight on a curved urface get maller or larger? φ 7 8 Blinn-Phong pecular reflection Iteration three A common alternative for pecular reflection i the Blinn-Phong model (ometime called the modified Phong model.) We compute the vector halfway between L and V a: The next update to the Blinn-Phong hading model i then: n I=k +k I +k I B( NL ) +k I B( NH) e d L L k e+kai La+ ILBk d( NL ) +k( NH) n where: Analogou to Phong pecular reflection, we can compute the pecular contribution in term of (N H), raied to a power n : n pecular ~ B NH I ( ) k i the pecular reflection coefficient n i the pecular exponent or hinine H i the unit halfway vector between L and V, where V i the viewing direction. where, again, (x ) + max(0, x ). 9 20
Directional light The implet form of light upported by renderer are ambient, directional, and point. Spotlight are alo upported often a a pecial form of point light. We ve een ambient light ource, which are not really geometric. Directional light ource have a ingle direction and intenity aociated with them. Point light The direction of a point light ource i determined by the vector from the light poition to the urface point. E-P L= E-P r =E-P Uing affine notation, what i the homogeneou coordinate for a directional light? 2 Phyic tell u the intenity mut drop off inverely with the quare of the ditance: f atten r 2 Sometime, thi ditance-quared dropoff i conidered too harh. A common alternative i: f atten 2 a+br +cr with uer-upplied contant for a, b, and c. Uing affine notation, what i the homogeneou coordinate for a point light? 22 Spotlight We can alo apply a directional attenuation of a point light ource, giving a potlight effect. A common choice for the potlight intenity i: LS f = 2 pot abrcr 0 otherwie where L i the direction to the point light. S i the center direction of the potlight. i the angle between L and S i the cutoff angle for the potlight e i the angular falloff coefficient Note: co ( LS ) LS co. e 23 Iteration four Since light i additive, we can handle multiple light by taking the um over every light. Our equation i now: I=k +k I + Thi i the Blinn-Phong illumination model (for potlight). Which quantitie are patial vector? Which are RGB triple? Which are calar? ej Lj Sj j n I B NH L,j j k d NLj +k 2 j j a+b j jrj +cjrj e 24
Shading in OpenGL The OpenGL lighting model allow you to aociate different lighting color according to material propertie they will influence. 3D Geometry in the Graphic Hardware Pipeline Graphic hardware applie tranformation to bring the object and lighting into the camera coordinate ytem: Thu, our original hading equation (for point light): I=k +k I + e a+b r +cr NL NH I B k +k 2 L,j j d j j + j j j j j j n become: I=k +k I + e a+b r +cr 2 j j j j j j ki + B ki ( NL ) +ki ( NH ) n,j j d Ld, j j L,j j + where you can have a global ambient light with intenity I La in addition to having an ambient light intenity I La, j aociated with each individual light, a well a eparate diffue and pecular intenitie, I Ld, j and I L, j, repectively. 25 The geometry i aumed to be made of triangle, and the vertice are projected onto the image plane. 26 Raterization Shading the interior of triangle After projecting the vertice, graphic hardware mear vertex propertie acro the interior of the triangle in a proce called raterization. We will be computing color uing the Blinn-Phong lighting model. Let aume (a graphic hardware doe) that we are working with triangle. How hould we hade the interior of triangle? Smearing the z-value and uing a Z-buffer will enable the graphic hardware to determine if a point inide a triangle i viible. (More on thi in another lecture.) If we have tored color at the vertice, then we can mear thee a well. 27 28
Shading with per-face normal Faceted hading (cont d) Aume each face ha a contant normal: For a ditant viewer and a ditant light ource and contant material propertie over the urface, how will the color of each triangle vary? 29 [William and Siegel 990] 30 Gouraud interpolation Facted hading v. Gouraud interpolation To get a moother reult that i eaily performed in hardware, we can do Gouraud interpolation. Here how it work:. Compute normal at the vertice. 2. Shade only the vertice. 3. Interpolate the reulting vertex color. 3 [William and Siegel 990] 32
Gouraud interpolation artifact Phong interpolation Gouraud interpolation ha ignificant limitation.. If the polygonal approximation i too coare, we can mi pecular highlight. To get an even moother reult with fewer artifact, we can perform Phong interpolation. Here how it work:. Compute normal at the vertice. 2. Interpolate normal and normalize. 3. Shade uing the interpolated normal. 2. We will encounter Mach banding (derivative dicontinuity enhanced by human eye). Thi i what graphic hardware doe by default. A ubtantial improvement i to do 33 34 Gouraud v. Phong interpolation Vertex proceor Primitive aembler Old pipeline: Gouraud interpolation Default vertex proceing: Ldetermine lighting direction Vdetermine viewing direction Nnormalize( n e ) cblinn-phong hade with LV,, Nk, d, k, n attach c blinn-phong to vertex a varying v i project v to image 2 3 vi, vi, vi triangle Raterizer Fragment proceor Default fragment proceing: p color c blinn-phong [William and Siegel 990] 35 36
Vertex proceor Primitive aembler Programmable pipeline: Phong-interpolated normal! Vertex hader: attach n e to vertex a varying attach v e to vertex a varying v i project v to image v, v, v 2 3 i i i triangle Chooing Blinn-Phong hading parameter Experiment with different parameter etting. To get you tarted, here are a few uggetion: Try n in the range [0,00] Try k a + k d + k < Ue a mall k a (~0.) n k d k Raterizer Metal Platic large medium Small, color of metal Medium, color of platic Large, color of metal Medium, white Planet 0 varying 0 Fragment proceor Fragment hader: p L determine lighting direction (uing v e ) p Vnormalizev e p N normalize( n e ) color hade with LV,, N, k, k, n d 37 38 BRDF More ophiticated BRDF The diffue+pecular part of the Blinn-Phong illumination model are a mapping from light to viewing direction: L V I= I LB k d( NL) +kn L V I f ( LV, ) L r The mapping function f r i often written in term of incoming (light) direction in and outgoing (viewing) direction out : n [Cook and Torrance, 982] f (, ) or f ( ) r in out r in out Thi function i called the Bi-directional Reflectance Ditribution Function (BRDF). Aniotropic BRDF [Wetin, Arvo, Torrance 992] Here a plot with in held contant: f (, ) r in out in BRDF can be quite ophiticated 39 Artitic BRDF [Gooch] 40
More ophiticated BRDF (cont d) BSSRDF for uburface cattering Hair illuminated from different angle [Marchner et al., 2003] [Jenen et al. 200] Wool cloth and ilk cloth [Irawan and Marchner, 202] 4 42 Summary You hould undertand the equation for the Blinn- Phong lighting model decribed in the Iteration Four lide: What i the phyical meaning of each variable? How are the term computed? What effect doe each term contribute to the image? What doe varying the parameter do? You hould alo undertand the difference between faceted, Gouraud, and Phong interpolated hading. 43