reading
play

Reading Required: Angel 6.1-6.3, 6.5, 6.7-6.8 Optional: Angel 6.4 - PDF document

Reading Required: Angel 6.1-6.3, 6.5, 6.7-6.8 Optional: Angel 6.4 Shading OpenGL red book, chapter 5. cse457-10-shading 1 cse457-10-shading 2 Introduction An abundance of photons So far, weve talked exclusively about


  1. Reading Required: � Angel 6.1-6.3, 6.5, 6.7-6.8 Optional: � Angel 6.4 Shading � OpenGL red book, chapter 5. cse457-10-shading 1 cse457-10-shading 2 Introduction An abundance of photons So far, we’ve talked exclusively about geometry. Properly determining the right color is really hard. � What is the shape of an object? Look around the room. Each light source has � How do I place it in a virtual 3D space? different characteristics. Trillions of photons are pouring out every second. � How do I know which pixels it covers? � How do I know which of the pixels I should These photons can: actually draw? � interact with the atmosphere, or with things Once we’ve answered all those, we have to ask in the atmosphere one more important question: � strike a surface and � To what value do I set each pixel? • be absorbed Answering this question is the job of the shading • be reflected (scattered) model . • cause fluorescence or phosphorescence. � interact in a wavelength-dependent manner Other names: � generally bounce around and around � Lighting model � Light reflection model � Local illumination model � Reflectance model � BRDF cse457-10-shading 3 cse457-10-shading 4

  2. Our problem Setup… We’re going to build up to an approximation of reality called the Phong illumination model . It has the following characteristics: � not physically based � gives a first-order approximation to physical light reflection � very fast � widely used Given: � a point P on a surface visible through pixel p In addition, we will assume local illumination , � The normal N at P i.e., light goes: light source -> surface -> viewer. � The lighting direction, L , and intensity, L 8 ,at P No interreflections, no shadows. � The viewing direction, V , at P � The shading coefficients at P Compute the color, I , of pixel p . Assume that the direction vectors are normalized: N L V 1 = = = cse457-10-shading 5 cse457-10-shading 6 “Iteration zero” “Iteration one” The simplest thing you can do is… Let’s make the color at least dependent on the overall quantity of light available in the scene: Assign each polygon a single color: I k k L = + I = k e a a e where � k a is the ambient reflection coefficient . � I is the resulting intensity • really the reflectance of ambient light � k e is the emissivity or intrinsic shade • “ambient” light is assumed to be equal in all associated with the object directions � L a is the ambient light intensity . This has some special-purpose uses, but not really good for drawing a scene. Physically, what is “ambient” light? [Note: k e is omitted in Angel.] cse457-10-shading 7 cse457-10-shading 8

  3. Wavelength dependence Diffuse reflection Really, k e , k a , and I a are functions over all Let’s examine the ambient shading model: wavelengths λ . � objects have different colors � we can control the overall light intensity Ideally, we would do the calculation on these functions. For the ambient shading equation, we • what happens when we turn off the lights? would start with: • what happens as the light intensity increases? • what happens if we change the color of the lights? I ( ) = k ( ) L ( ) λ λ λ a a So far, objects are uniformly lit. then we would find good RGB values to represent the spectrum I ( λ ). � not the way things really appear � in reality, light sources are localized in Traditionally, though, k a and I a are represented as position or direction RGB triples, and the computation is performed on each color channel separately: Diffuse , or Lambertian reflection will allow I = k L reflected intensity to vary with the direction of the R a,R a,R light. I = k L G a,G a,G I = k L B a,B a,B cse457-10-shading 9 cse457-10-shading 10 Diffuse reflectors Diffuse reflectors Diffuse reflection occurs from dull, matte surfaces, …or picture a surface with little pigment particles like latex paint, or chalk. embedded beneath the surface (neglect reflection at the surface for the moment): These diffuse or Lambertian reflectors reradiate light equally in all directions. Picture a rough surface with lots of tiny microfacets . The microfacets and pigments distribute light rays in all directions. Embedded pigments are responsible for the coloration of diffusely reflected light in plastics and paints. Note: the figures above are intuitive, but not strictly (physically) correct. cse457-10-shading 11 cse457-10-shading 12

  4. Diffuse reflectors, cont. “Iteration two” The reflected intensity from a diffuse surface does The incoming energy is proportional to , not depend on the direction of the viewer. The giving the diffuse reflection equations: incoming light, though, does depend on the direction of the light source: I = k + k L + k L ____ e a a d = k + k I + k L ( ) e a a d where: � k d is the diffuse reflection coefficient � L is the intensity of the light source � N is the normal to the surface (unit vector) � L is the direction to the light source (unit vector) � ( x ) + means max {0, x } [Note: Angel uses L d instead of L .] cse457-10-shading 13 cse457-10-shading 14 Specular reflection Specular reflection “derivation” Specular reflection accounts for the highlight that you see on some objects. It is particularly important for smooth, shiny surfaces, such as: � metal � polished stone For a perfect mirror reflector, light is reflected � plastics about N , so � apples L if V R = � skin  I =  0 otherwise  Properties: For a near-perfect reflector, you might expect the highlight to fall off quickly with increasing angle φ . � Specular reflection depends on the viewing direction V . Also known as: � For non-metals, the color is determined solely by the color of the light. � “rough specular” reflection � For metals, the color may be altered (e.g., � “directional diffuse” reflection brass) � “glossy” reflection cse457-10-shading 15 cse457-10-shading 16

  5. Derivation, cont. “Iteration three” The next update to the Phong shading model is then: cos ns φ N 1.0 1 L R 90 V 60 120 0.8 0.9 n L L I = k + k I + k ( N L ) + k ( V R ) ⋅ ⋅ s 0.6 0.8 150 30 e a a d + s + 0.4 0.7 = 1 ns s = 0.2 0.6 180 0 0.5 0.4 0.3 where: 210 330 0.2 0.1 = 128 128 ns s = � k s is the specular reflection coefficient 240 300 φ 0 100 80 60 40 20 0 20 40 60 80 100 � n s is the specular exponent or shininess � R is the reflection of the light about the One way to get this effect is to take ( R · V ), raised normal (unit vector) to a power n s . � V is viewing direction (unit vector) As n s gets larger, � the dropoff becomes {more,less} gradual [Note: Angel uses α instead of n s , and maintains a separate L d and L s , instead of a single L . This � gives a {larger,smaller} highlight choice reflects the flexibility available in OpenGL.] � simulates a {more,less} mirror-like surface cse457-10-shading 17 cse457-10-shading 18 Intensity drop-off with distance “Iteration four” OpenGL supports different kinds of lights: point, Since light is additive, we can handle multiple directional, and spot. lights by taking the sum over every light. For point light sources, the laws of physics state Our equation is now: that the intensity of a point light source must drop off inversely with the square of the distance. n I = k + k L + f ( d L ) k ( N L ) + k ( V R ) ⋅ ⋅ s   ∑ atten e a a j j d j + s j +   j We can incorporate this effect by multiplying I l by 1/ d 2 . This is the Phong illumination model. Sometimes, this distance-squared dropoff is considered too “harsh.” A common alternative is: Which quantities are spatial vectors? 1 f (d)= a+ bd + cd Which are RGB triples? atten 2 with user-supplied constants for a , b , and c . Which are scalars? cse457-10-shading 19 cse457-10-shading 20

Recommend


More recommend