Docstoc

Illumination and Shading

Document Sample
Illumination and Shading Powered By Docstoc
					Illumination and Shading
 Sampling a scene
     ideally, need to consider light coming to the viewer from each
      point on each surface in a scene
 Points in a scene
     points are the smallest units of our scene: can think of them
      having no area or infinitesimal area
     there are an infinite number of visible points: mathematically
      intractable
 Surface elements
     only consider a finite number of differential pieces of surface
     figure out how much light comes to the viewer from each of these
      pieces of surface
         Global/local
         Illumination
                                                                                   from Pixar’s “Luxo
 Lights and Shadows                                                               Jr.”
     most light striking a surface element comes directly from emissive
      light sources in the scene (direct illumination)
     sometimes light from source is blocked by other objects
     surface element is then in “shadow” from that light source
                                                  object
                          eye
    direct illumination                            indirect illumination
 light                          object   object                            light
    Inter-Object Reflection
     light bounces off other objects toward our surface element
     when that light reaches our surface element, it brightens it (indirect
       illumination)

    Global Illumination simulates what happens when other objects affect
       the light reaching a surface element
    Local Illumination does not worry about this.
  BRDFs


• In general, behavior of light is simulated by bi-directional reflectance
  distribution functions (BRDFs)
      - Lambertian and Phong approximations model simple BRDF
      - given incoming light ray at surface point, BRDF is used
        to calculate how much of that light ray will be reflected in
        a particular outgoing direction (function of incoming and
        outgoing angles)
      - can be obtained from analytical model
      - or measurements of actual surfaces
     Illumination and Shading
 Illumination (Lighting) model
   Expresses the factors determining a surface’s color at a
    given point (defines the nature of the light emanating
    from a source – geometry of light distribution, etc.)
 Shading Model
   Determines where the illumination model is applied and
    the arguments it receives
   Some shading models invoke an illumination model for
    each pixel; others invoke an illumination model for
    selected points, shading the rest by interpolation

  Reflection models calculate light intensity at a given point.
Graphics: A Hack!
 Caveat : Most illumination models used in graphics
 (especially in interactive 3D graphics h/w) are
 approximations picked for efficiency not accuracy- they
 are not physically based)
     An important reseach goal – develop
     models…efficient and physically correct

    The intensity and wavelength of light reflected from a
    surface depends on the incident wavelength, angle of
    incidence, nature (roughness) of the surface
    material, and its electrical properties (permittivity,
    permeability and conductivity). (road example..)
 Light energy is simply sum of all
  contributions
                   I  k I k
 Each term can be calculated separately and
  later added together:
   multiple light sources
   multiple interactions (diffuse, specular, more
    later)
   multiple colors (R-G-B, or per wavelength)
           Illumination Models
 Local Illumination
   Defines single light and single surface interaction
 Global Illumination
   Defines interchange of lights between all surfaces



     Incident flux                   Reflected
                       θi   θr
                                     flux


      Absorbed                   Transmitted
      flux                       flux
                            θt
     Local illumination models



      diffuse                                        Specular

Traditional graphics LIMs are:
Fast to compute
Heuristic and incomplete (incomplete)
Most interested in light in direction of viewpoint
     Local illumination models
 Most such adhoc illumination models have
  three components
   I = ambient + diffuse + specular
 The ambient term allows for some global
  control of brightness in a scene. Typically,
  I = Ia Ka
 Where Ia is an ambient illumination constant
  defined once the entire scene and ka is an
  ambient reflection coefficient, usually restricted
  to lie in [0,1]
     Reflection Characteristics of
    Surfaces – Illumination model
 Components of a simple ( non- physically
  based) illumination model
   Ambient reflection
   Diffuse reflection
   Specular reflection
 Ambient reflection
   Independent of object position and viewer position
   Constant
   Exists in most environments – some light hits surface
    from all directions – a way of approximating
    contributions from indirect lighting
     Reflection characteristics of
               surfaces
 Ambient reflection (continued)
   A total hack, but images without some form of
    ambient lighting look stark
           I = Ia Ka
   Ia = Intensity of ambient light
   Ka= Fraction reflected, 0<= Ka<=1

 Diffuse (Lambertian) reflection
   Typical of dull matte surfaces
   Independent of viewer position
   Dependant of light source position (in this case a
    point source again a non-physical abstraction)
                Diffuse reflection
                     I Sin (θ)

         I Cos (θ)            ‾N
                          θ
                     ‾L

Lamberts Cosine Law
       I = Ipkd cos θ         I = Ip kd (‾N . ‾L )
  Ip = intensity of the point light source
  kd = diffuse reflection coefficient; specifies fraction
        of Ip reflected
Add an ambient term I = Ia Ka + Ip kd (‾N . ‾L )
           Specular Reflection
 Specular reflection

   Typical of bright and shiny surfaces
   Color depends on material and how it scatters light
    energy
   In plastics it is color of point source and in metal its
    the color of metal
   In other materials will combine color of light source
    and color of material
   Dependant on light source position and viewer
    position
                Specular Reflection
                                                           Direction of
                               ‾N
                                                           reflection
    To Point light‾L                                 ‾R
    Source
                                               α             Direction of
                                 θ   θ                    ‾V ViewPoint




    Early model by Phong neglected effect of material color on
     specular highlight – made all surfaces look plastic
    For perfect reflector, see light iff α = 0
    For real reflector , reflected light falls off as α increases
        Reflection characteristics of
                  surfaces
   Specular reflection (cont)
       Phong approximation : cosn
        α
       As n increases , highlight is
        more concentrated, surface
        appears glossier
Calculating the reflection vector
                       ‾N
              ‾S       ‾S
                       ‾Ncos θ
        ‾L                       ‾R
                   θ   θ




             ‾R = 2‾N (‾N. ‾L) - ‾L
       ‾R . ‾V = (2‾N (‾N. ‾L - L). ‾V
The Halfway Vector
Consider the unit vector halfway between l and
 v

h = (l+v)/|l+v|
If we use n·h rather
than r·v, we avoid
calculation of r


(if the normal to the surface were oriented along h,
  the viewer would see the brightest specular light)
(psi is double of phi if all vectors are co-planar)
Modified Phong Model
The use of the halfway vector was first
 suggested by Blinn
The resulting lighting model is known
 as the Blinn or modified Phong model
OpenGL default is the modified Phong
 model
Example



Only differences in
these teapots are
the parameters
in the Phong model
Dot products
        N
               If N.L is –ve, the light is
               behind the surface, and so
               cannot illuminate it.


  L
               If N.V is –ve, the viewer
               is beneath the surface, and
         N
               so cannot see the illumination.

               (both cases, illumination set to
                        zero)
                  V
Light Sources
In the Phong Model, we add the results from
 each light source
Each light source has separate diffuse, specular,
 and ambient terms to allow for maximum
 flexibility even though this form does not have a
 physical justification
Separate red, green and blue components
Hence, 9 coefficients for each point source
   Idr, Idg, Idb, Isr, Isg, Isb, Iar, Iag, Iab
Material Properties
Material properties match light source
 properties
 Nine absorbtion coefficients
   kdr, kdg, kdb, ksr, ksg, ksb, kar, kag, kab
 Shininess coefficient a (n)
         Polygon Mesh Shading
 Use any illumination model
 Three methods ; each treats a single polygon
  independent of all others ( a huge oversimplification;
  really want global illumintaion , e.g. for shadows)
   Constant
   Gouraud ( intensity Interpolation)
   Phong ( Normal Vector Interpolation)
How good is Phong Model?
Flat vs. Gouraud Shading




glShadeModel(GL_FLAT)   glShadeModel(GL_SMOOTH)
                     Constant Shading
      Single Intensity value per polygon
      If Polygon mesh is an approximation to curved
       surface, faceted look is a problem
      Facets are exaggerated by mach band effect
                                    Intensity


Intensity

                             -    Actual
            Distance along   ---Perceived       Distance along
            surface                             surface
              • Mach band effect: discrepancies between actual and perceived
                intensities due to bilateral inhibition
              • A photoreceptor in the eye responds to light according to the
                intensity of the light falling on it minus the activation of its
                neighbors

                                I (c j )  e(c j )  a k e(ck )      0  ak  1
                                                    k j




Mach banding applet :
http://www.nbb.cornell.edu/neurobio/land/OldStudentProjects/cs490-96to97/anson/MachBandingApplet/
              Gouraud Shading
 Use for polygon approximations to curved surfaces
 Linear Interpolation of intensity along scan Lines
 Eliminates intensity discontinuities polygon edges – still
  have gradient discontinuities, so mach banding is
  improved but not eliminated
 Must differentiate real ( desired) creases from those
  induced by polygonal approximations (e.g, shared edges
  of a cuboid vs edges in polygonized sphere)

 Step 1
  Calculate bogus vertex normals as average of
  surrounding polygons’ noormals
              Gouraud Shading

                        ‾Nv‾N1
                                   ‾N2

                      ‾N4

                             ‾N3




   Nv = (‾N1 + ‾N2 + ‾N3 + ‾N4)/ ||‾N1 + ‾N2 + ‾N3 + ‾N4||
   Since neighboring polygons sharing vertices and edges are
    approximations to smoothly curved surfaces and won’t have
    greatly differing surface normals, this approximation is a
    reasonable one
                        Gouraud Shading
   Step 2
    Interpolate intensity along polygon edges
   Step 3
    Interpolate along scan Lines
                                       I1
   Y1

   YS
                                            Ip
   Y2              I2

   Y3                                                            I3

Ia = I1* Ys-y2/y1-y2 + I2 * y1-ys /y1-y2         Ib = I1* Ys-y3/y1-y3 + I3 * y1-ys /y1-y3
                        Ip = Ia* xb-xp/xb-xa + Ib * xp-xa /xb-xa
              Gouraud Shading
 Gouraud vs constant shading
 Integrates nicely with scan line algorithm
 ΔI / Δy is constant along polygon edge



         Surface


      Intensity

  Constant
  Gouraud -----
          What Gouraud shading misses
              Gouraud shading can miss specular highlights in specular objects
               because it interpolates vertex colors instead of vertex normals

                                           Here ‾Na & ‾Nb would cause no appreciable
                   ‾Nc                     specular component whereas ‾Nc would.
                                           Shading by interpolating between Ia and Ib
‾Na                          ‾Nb           therefore misses the highlight that
          Ia                               evaluating I at C would catch
                     Ib
  I                        Gouraud         Interpolating the normal comes closer to
                                           what actual normal of the surface being
                                           polygonally approximated would be
                      Ib
          Ia                  Highlight
                              missed by
                              Gouraud      Also, if I at Na or Nb is zero due to the N.L
                                           or N.V being negative, we will loose
                           Phong
                                           highlight in the in-between.
                 Phong Shading
 Also called normal vector interpolation
       Interpolate ‾N rather than I
       Especially important with specular reflection
       Computationally expensive at each pixel to
         Recompute ‾N ----- must normalize , requiring
           expensive square root
         Recompute Iλ

   Bishop and Weimer developed fast approximation using taylor
    series expansion ( in SIGGRAPH ’86)
                 Comparing Shading Models

Flat or Faceted Shading:
Constant intensity over each face




 Gouraud Shading:
 Interpolation of intensity across
 triangles to eliminate edge
 discontinuity

  Pixar “Shutterbug” images from:
  www.siggraph.org/education/materials/HyperGraph/scanline/
  shade_models/shading.htm
        Comparing Shading Models (contd.)

Phong Shading:
Interpolation of surface normals.
Note: specular highlights but
no shadows – pure local illumination
model




Global Illumination:
Global illumination model with texture,
bump, and reflection mapping
 Should also model inverse square law energy density fall
  off
  I = Ia ka * (Ip kd)(‾N. ‾L), where fatt = 1 / (dL)2
  dL= path length from light to object to viewer

 This makes surfaces with equal kd(‾N. ‾L) differ in
  appearance – important if overlap

                ‾N
                       ‾N
 Formula often creates harsh effects – we do not often
  see objects illuminated by point lights

 Instead use fatt = min(1 / c1 + c2dL + c3 (dL)2, 1)

 Where c1 , c2 and c3 are user defined constants

 This is a heuristic!
       Refractive Transparency
 Modelling refracted light complicates matters!
   UnRefracted                 Refracted (optical)
   (Geometrical) line          line of sight
   of sight

                             θi
                                      Transparent object
                        θi


               Line of sight
                      Snell’s Law

                                                Medium 1


                                                Medium 2


                    sin θt = sin θi ηiλ / ηtλ

ηiλ and ηtλ are indices of refraction of the two media
   Non refractive transparency
 For partially transparent polygon
     Iλ = (1- kt1) I λ1 + k Iλ2

      kt1 – transmittance of polygon 1
      I λ1- intensity calculated for polygon 1
      Iλ2 – intensity calculated for polygon 2




       Polygon 1

       Polygon 2

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:1
posted:11/8/2012
language:English
pages:42