lecture6 (1)

download lecture6 (1)

of 42

description

lecture6 (1)

Transcript of lecture6 (1)

  • Illumination and Shading

  • Sampling a sceneideally, need to consider light coming to the viewer from each point on each surface in a scenePoints in a scenepoints are the smallest units of our scene: can think of them having no area or infinitesimal areathere are an infinite number of visible points: mathematically intractableSurface elementsonly consider a finite number of differential pieces of surfacefigure out how much light comes to the viewer from each of these pieces of surface

  • Lights and Shadowsmost light striking a surface element comes directly from emissive light sources in the scene (direct illumination)sometimes light from source is blocked by other objectssurface element is then in shadow from that light source

    Inter-Object Reflectionlight bounces off other objects toward our surface elementwhen 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 elementLocal Illumination does not worry about this.Global/localIlluminationeyelightlightdirect illuminationindirect illuminationobjectobjectobjectfrom Pixars Luxo Jr.

  • In general, behavior of light is simulated by bi-directional reflectance distribution functions (BRDFs)Lambertian and Phong approximations model simple BRDFgiven 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

    BRDFs

  • Illumination and ShadingIllumination (Lighting) modelExpresses the factors determining a surfaces color at a given point (defines the nature of the light emanating from a source geometry of light distribution, etc.)Shading ModelDetermines where the illumination model is applied and the arguments it receivesSome 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 modelsefficient 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

    Each term can be calculated separately and later added together:multiple light sourcesmultiple interactions (diffuse, specular, more later)multiple colors (R-G-B, or per wavelength)

  • Illumination ModelsLocal IlluminationDefines single light and single surface interactionGlobal IlluminationDefines interchange of lights between all surfaces

    irtIncident fluxReflected fluxTransmitted fluxAbsorbed flux

  • Local illumination models

    diffuseSpecularTraditional graphics LIMs are:Fast to computeHeuristic and incomplete (incomplete)Most interested in light in direction of viewpoint

  • Local illumination modelsMost such adhoc illumination models have three components I = ambient + diffuse + specularThe ambient term allows for some global control of brightness in a scene. Typically,I = Ia KaWhere 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 modelComponents of a simple ( non- physically based) illumination modelAmbient reflectionDiffuse reflectionSpecular reflectionAmbient reflectionIndependent of object position and viewer positionConstantExists in most environments some light hits surface from all directions a way of approximating contributions from indirect lighting

  • Reflection characteristics of surfacesAmbient reflection (continued)A total hack, but images without some form of ambient lighting look starkI = Ia KaIa = Intensity of ambient lightKa= Fraction reflected, 0
  • Diffuse reflection

    I Sin ()I Cos ()NLLamberts Cosine LawI = 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 ReflectionSpecular reflection

    Typical of bright and shiny surfacesColor depends on material and how it scatters light energyIn plastics it is color of point source and in metal its the color of metalIn other materials will combine color of light source and color of materialDependant on light source position and viewer position

  • Specular Reflection

    Early model by Phong neglected effect of material color on specular highlight made all surfaces look plasticFor perfect reflector, see light iff = 0For real reflector , reflected light falls off as increasesNLRVTo Point light Source

    Direction of reflection

    Direction of ViewPoint

  • Reflection characteristics of surfacesSpecular reflection (cont)Phong approximation : cosn As n increases , highlight is more concentrated, surface appears glossier

  • Calculating the reflection vector

    R = 2N (N. L) - L R . V = (2N (N. L - L). V NSSNcos RL

  • The Halfway VectorConsider the unit vector halfway between l and v

    h = (l+v)/|l+v|If we use nh rather than rv, 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 ModelThe use of the halfway vector was first suggested by BlinnThe resulting lighting model is known as the Blinn or modified Phong modelOpenGL default is the modified Phong model

  • ExampleOnly differences in these teapots are the parametersin the Phong model

  • Dot productsIf N.L is ve, the light is behind the surface, and so cannot illuminate it.

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

    (both cases, illumination set to zero)

    NLNV

  • Light SourcesIn the Phong Model, we add the results from each light sourceEach light source has separate diffuse, specular, and ambient terms to allow for maximum flexibility even though this form does not have a physical justificationSeparate red, green and blue componentsHence, 9 coefficients for each point sourceIdr, Idg, Idb, Isr, Isg, Isb, Iar, Iag, Iab

  • Material PropertiesMaterial properties match light source propertiesNine absorbtion coefficientskdr, kdg, kdb, ksr, ksg, ksb, kar, kag, kabShininess coefficient a (n)

  • Polygon Mesh ShadingUse 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)ConstantGouraud ( intensity Interpolation)Phong ( Normal Vector Interpolation)

  • How good is Phong Model?

  • Flat vs. Gouraud ShadingglShadeModel(GL_FLAT)glShadeModel(GL_SMOOTH)

  • Constant ShadingSingle Intensity value per polygonIf Polygon mesh is an approximation to curved surface, faceted look is a problemFacets are exaggerated by mach band effect

    IntensityDistance along surfaceIntensityDistance along surface Actual --Perceived

  • Mach band effect: discrepancies between actual and perceived intensities due to bilateral inhibitionA photoreceptor in the eye responds to light according to the intensity of the light falling on it minus the activation of its neighborsMach banding applet :http://www.nbb.cornell.edu/neurobio/land/OldStudentProjects/cs490-96to97/anson/MachBandingApplet/

  • Gouraud ShadingUse for polygon approximations to curved surfacesLinear Interpolation of intensity along scan LinesEliminates intensity discontinuities polygon edges still have gradient discontinuities, so mach banding is improved but not eliminatedMust 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 + N3 + N4)/ ||N1 + N2 + N3 + N4|| Since neighboring polygons sharing vertices and edges are approximations to smoothly curved surfaces and wont have greatly differing surface normals, this approximation is a reasonable oneN3N2N1N4Nv

  • Gouraud ShadingStep 2 Interpolate intensity along polygon edgesStep 3 Interpolate along scan Lines

    Y3Y2YSY1I1I2I3IpIa = 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 ShadingGouraud vs constant shadingIntegrates nicely with scan line algorithmI / y is constant along polygon edge SurfaceIntensityConstant Gouraud -----

  • What Gouraud shading missesGouraud shading can miss specular highlights in specular objects because it interpolates vertex colors instead of vertex normals

    IIaIbNaNcNbIaIbHighlight missed by GouraudGouraudPhongHere Na & Nb would cause no appreciable specular component whereas Nc would. Shading by interpolating between Ia and Ib therefore misses the highlight that evaluating I at C would catch

    Interpolating the normal comes closer to what actual normal of the surface being polygonally approximated would be

    Also, if I at Na or Nb is zero due to the N.L or N.V being negative, we will loose highlight in the in-between.

  • Phong ShadingAlso called normal vector interpolationInterpolate N rather than IEspecially important with specular reflectionComputationally expensive at each pixel toRecompute N ----- must normalize , requiring expensive square rootRecompute I

    Bishop and Weimer developed fast approximation using taylor series expansion ( in SIGGRAPH 86)

  • Pixar Shutterbug images from: www.siggraph.org/education/materials/HyperGraph/scanline/shade_models/shading.htmComparing Shading ModelsFlat or Faceted Shading:Constant intensity over each faceGouraud Shading:Interpolation of intensity across triangles to eliminate edge discontinuity

  • Comparing Shading Models (contd.)Phong Shading:Interpolation of surface normals.Note: specular highlights butno shadows pure local illumination modelGlobal 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

    NN

  • 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 TransparencyModelling refracted light complicates matters!

    iiRefracted (optical) line of sightUnRefracted (Geometrical) line of sightTransparent objectLine of sight

  • Snells Law

    sin t = sin i i / t

    i and t are indices of refraction of the two mediaMedium 1Medium 2

  • Non refractive transparencyFor partially transparent polygonI = (1- kt1) I 1 + k I2

    kt1 transmittance of polygon 1 I 1- intensity calculated for polygon 1 I2 intensity calculated for polygon 2

    Polygon 1Polygon 2