11 lighting
Download
1 / 71

11: Lighting - PowerPoint PPT Presentation


  • 157 Views
  • Updated On :

#11: Lighting. CSE167: Computer Graphics Instructor: Ronen Barzel UCSD, Winter 2006. Outline for today. Overview of lighting Notes on color Local Illumination Light Sources Shading Advanced Lighting. Where we are so far…. We know how to rasterize:

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about '11: Lighting' - apollo


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
11 lighting l.jpg

#11: Lighting

CSE167: Computer Graphics

Instructor: Ronen Barzel

UCSD, Winter 2006


Outline for today l.jpg
Outline for today

  • Overview of lighting

  • Notes on color

  • Local Illumination

  • Light Sources

  • Shading

  • Advanced Lighting


Where we are so far l.jpg
Where we are so far…

  • We know how to rasterize:

    • Given a 3D triangle (or a bunch of triangles)

    • Given a 3D camera…

    • …we know which pixels represent the triangles

  • But what color should those pixels be?


Lighting l.jpg
Lighting

(non-teapot images by Henrik Wann Jensen)


Lighting5 l.jpg
Lighting

  • To create a photorealistic image:

    • Simulate the interaction of light with the objects in the scene

    • Simulate the interaction of light with the eye or camera

    • I.e., simulation of physics and optics

      • Advanced rendering course (CSE168)

      • Many aspects “solved” in principle but still an area of active research

      • Very slow to compute fully

      • Use global illumination techniques: examine the whole scene at once

      • Known as physically-based rendering

  • For interactive computer graphics:

    • Use a simplified model for speed

    • Empirical/perceptual -- approximate interesting observed phenomena

    • Use local illumination techniques:

      • only direct effect of lights on surfaces


Basic components of lighting l.jpg
Basic Components of Lighting

  • Light sources

    • AKA emitters

    • Color and intensity

    • Geometric attributes: Position, Direction, Shape

    • Spatial attenuation

    • Advanced properties: Spectrum, Polarization, …

  • Surfaces

    • Geometric attributes: Position, Orientation

    • Material properties: reflectance

      • color

      • shininess, glossiness, …

      • texture

      • Advanced: translucency, microstructure, sub-surface scattering, …


Lighting vs shading l.jpg
Lighting vs. Shading

  • Lighting: compute the result of light illuminating surfaces

  • Shading: assign colors to pixels

  • For photorealistic rendering:

    • in principle, shading==lighting: perform lighting at every pixel

  • In practice:

    • may take shortcuts

    • may include non-lighting effects

      • fog

      • illustration

      • cartoon shading


Vertex lighting l.jpg
Vertex Lighting

  • Each vertex goes through lighting process

  • Lighting computation determines final color at the vertex

    • Based on initial “unlit” vertex color

    • Based on lights in the scene

    • Based on material properties of the surface

    • Based on surface normal

  • Interpolate colors using Gouraud shading

  • (Same lighting computation for per-pixel lighting)


Outline for today9 l.jpg
Outline for today

  • Overview of lighting

  • Notes on color

  • Local Illumination

  • Light Sources

  • Shading

  • Advanced Lighting


What is light what is color l.jpg
What is light? What is color?

  • Light is electromagnetic energy

    • a continuous range of wavelengths

    • varying intensity at each wavelength

  • Color is a property of the visual system

    • Not an inherent property of light

    • Human eyes have Red, Green, Blue receptors (cones)

      • Each receptor responds to a range of wavelengths

      • Gives rise to “primary colors”:

        • all colors expressed as combination of red, green, blue cone stimulation

      • Lots of perceptual, psychophysical effects:

        • adaptation, inhibition, illusion

  • Physically correct computation

    • requires computing interactions at all wavelengths

  • Perceptually correct computation

    • Requires taking into account psychophysics

  • Pretty good approximation:

    • Separate light into red, green, blue components

    • Process each component independently


Color illusion l.jpg
Color illusion

  • The squares marked A and B are the same shade of gray




Material colors l.jpg
Material Colors

  • Inherent “material color” which is the color that the object reflects

    • Material reflects different wavelengths of light different amounts

    • In RGB, have a reflectivity amount for each of red, green, blue

  • An object can’t reflect more light than it receives

    • Maximum: reflect 100% of light in all wavelengths--bright white

    • Reasonable: reflect 95% of light, material color =(0.95, 0.95, 0.95)

  • Material colors range from 0.0 to 1.0 in RGB


Light color l.jpg
Light Color

  • No limit to total light intensity reflecting from surface

    • Can make individual light source brighter

    • Can add more lights

  • Represent a light source using intensity in RGB

    • Range from 0.0 up

    • There is no upper limit to the intensity of light

    • In other words, a bright white light might have color (10,10,10)

  • Units?

    • physically-based rendering: photon power flux density

    • in practice: arbitrary units (“my light goes up to 11”)


Color intensity l.jpg
Color & Intensity

  • Distinction between material color and light color:

    • Material colors represent the proportion of light reflected

    • Light colors represent the actual intensity of a beam of light

  • We never perceive the inherent material color

    • All we see is the light reflected off of a material

    • Shine a red light…

      • on a white or red surface: the object appears red

      • on a grey surface: the object appears dark red

      • on a blue surface: the object appears black


Exposure and display l.jpg
Exposure and Display

  • What do we mean by “white”?

    • Human eyes (and digital cameras) adjust exposure settings automatically

    • In a moderatly lit room, intensity 0.5 might appear as white

    • In bright sunlight, intensity 100 might appear as (same) white

  • The monitor has an upper limit to the brightness it can display

    • RGB units: 0=no light at the pixel, 1=full intensity at the pixel

    • exact color light that emerges depends on monitor properties

      • brightness, contrast, white point, color balance, …

    • Final result of lighting calculation shouldn’t be more than 1.0

    • Advanced techniques: exposure control, AKA “tone mapping”

  • In practice:

    • Assume intensity (1,1,1) is white

    • clamp all final color values to 0.0-1.0 range before storing in pixel


Outline for today18 l.jpg
Outline for today

  • Overview of lighting

  • Notes on color

  • Local Illumination

  • Light Sources

  • Shading

  • Advanced Lighting


Local illumination l.jpg
Local Illumination

  • AKA Local Lighting Models

  • Light on a point on the surface (vertex)

  • Assume we have an incident ray of light

    • Light coming from a known direction

    • With a given RGB color (intensity)

  • We will build up empirical material properties

    • Fancy name: Bidirectional Reflectance Distribution Function “BRDF”


Reflectivity l.jpg
Reflectivity

  • White sheet of paper might reflect 95% of incident light

  • A mirror might reflect 95% of incedent light

  • Yet, these two things look completely different:

    • They reflect light in different directions

    • The paper is a diffuse reflector

    • The mirror is a specular reflector


Standard lighting model l.jpg
“Standard” Lighting Model

  • Consists of three terms linearly combined:

    • Diffuse component for the amount of incoming light reflected equally in all directions

    • Specular component for the amount of light reflected in a mirror-like fashion

    • Ambient term to approximate light arriving via other surfaces

  • This is very simple approximation

    • particularly good for plastic

    • particularly good for metal

    • That’s why CG images tend to look like plastic and metal


Diffuse reflection l.jpg
Diffuse Reflection

  • An ideal diffuse reflector receives light from some direction and bounces it uniformly in all directions

    • very rough at microscopic level

  • Diffuse materials have a dull or matte appearance

    • example: chalk


Diffuse reflection23 l.jpg
Diffuse Reflection

  • Assume a beam of parallel rays shining on the surface

  • Consider area of the surface covered by the beam

    • varies based on the angle between the beam and the normal

    • The larger this area, the less incident light per area

    • The incident light per unit area is proportional to the cosine of the angle between the normal and the light rays

  • Object darkens as normal turns away from light

    • This is known as Lambert’s cosine law

    • Diffuse surfaces AKA Lambertian surfaces

n



Diffuse reflection25 l.jpg
Diffuse Reflection

  • Notes:

    • Depends on light and normal directions

    • Doesn’t depend on eye position

      • diffuse reflection is same in every direction

    • Don’t want to illuminate from rear

      • use

cl

kd


Diffuse lighting examples l.jpg
Diffuse Lighting Examples

  • A Lambertian sphere at several different lighting angles:

  • Diffuse lighting provides visual cues

    • indicates 3D depth

    • indicates surface curvature


Multiple lights l.jpg
Multiple Lights

  • Can have many light sources in a scene

    • Light (generally) behaves additively

    • Add up the contribution of each light


Ambient light l.jpg
Ambient Light

  • In the real world, light gets bounced all around the environment

    • Resulting light illuminates surface from every direction.

    • Global illumination techniques attempt to compute this. Complex.

  • Simple approximation (hack): Ambient light

    • Assume net effect is a constant color shining from every direction

    • Add to the net color, attenuated by reflectance coefficient

  • Effect of ambient light:

    • Keeps unlit areas from going completely black

    • Makes things look flatter

      • with ambient and no diffuse: object has solid color, is completely 2D

    • kaor ca usually small (.1 or less)


Specular reflection l.jpg
Specular Reflection

  • Shiny surfaces exhibit specular reflection

    • Polished metal

    • Glossy car finish

    • Plastics

  • A light shining on a specular surface causes a bright spot:

    • known as a specular highlight

    • essentially, a rough reflection of the light source

  • Highlight location depends viewer position relative to surface & lights


Specular reflection30 l.jpg
Specular Reflection

  • An ideal specular reflector = mirror

    • perfectly smooth surface

    • bounces an incoming light ray in a single direction

    • angle of incidence equals the angle of reflection


Law of reflection l.jpg
Law of Reflection

  • Angle of reflectance = angle of incidence

p


Specular glossy reflection l.jpg
Specular (Glossy) Reflection

  • Many materials not quite perfect mirrors

    • Glossy materials look shiny and will show specular highlights

    • In CG, this is sometimes referred to as glossy reflection

  • Many formulations for this

    • First: most basic and famous: Phong lighting model (1973)

    • Then: most popular: Blinn lighting model (1977)


Shiny materials l.jpg
Shiny materials

  • The surface roughness will vary from material to material

    • Smooth surfaces have sharp highlights

    • Rougher surfaces have larger, more blurry highlights

  • Assume surface composed of microfacets with random orientation

    • Smooth surfaces: microfacet normals very close to surface normal

    • Rough surfaces: microfacet normals are spread around more

      • on average, microfacet normals close to surface normal

  • Polished:

  • Smooth:

  • Rough:

  • Very rough:


Empirical observation l.jpg
Empirical observation

  • In general, we expect most reflected light to travel in direction of exact reflection

  • But because of microscopic surface variations, some light may be reflected in a direction slightly off the ideal reflected ray

  • So:

    • Most reflected light in direction of ideal reflection

    • Brightest when eye vector (view vector) is aligned with reflection

    • Intensity decreases as eye vector angle from reflection increases

    • Use dot product of eye vector with reflection vector


Phong lighting model l.jpg
Phong Lighting Model

  • parameters:

    • specular reflectance coefficient, ks

    • Phong Exponent p controls the apparent size of the specularity

      • Higher p, smaller highlight

cl

ks


Phong lighting model examples l.jpg
Phong Lighting Model Examples

p=2

p=1

p=4

p=8

p=32

p=16

p=64

p=128

p=256



Blinn lighting model38 l.jpg

cl

ks

Blinn Lighting Model


Complete blinn lighting model l.jpg
Complete Blinn Lighting Model

  • Add to ambient and diffuse

  • Add specular contribution for each light

  • It appears in a few slightly different forms and in a wide variety of notations…


Note on color l.jpg
Note on color

  • Do this in parallel for R,G,B

  • Coefficients ka, kd, ks can be different for each of R,G,B

    • This defines the material ambient color, diffuse color, and specular color.

    • Other (expensive) terms in expression are shared for each of R,G,B

  • Generally, use ambient color = diffuse color

  • For metals, specular color = diffuse color

    • highlight is color of the material

  • For plastics, specular color = white

    • highlight is the color of the light


Note on normals and spaces l.jpg
Note on normals and spaces

  • Lighting depends on angles between normals, vectors

  • Must be in space that preserves angles

    • World Space or Camera Space

    • Not normalized view space: perspective doesn’t preserve angles

  • Conveniently, we can put world-space normals as per-vertex data

    • Doesn’t get transformed by projection.

  • But remember, when taking normals from object to world space:

    • if world transform has nonuniform scale, normals must use inverse-transpose

    • if world transform has uniform scale, normals must be renormalized

    • if world transform has no scales, normals transform like vectors


General lighting models l.jpg
General Lighting Models

  • General form:

    • Bidirectional Reflectance Distribution Function BRDF, B()

  • There are many lighting models

    • Phong

    • Blinn

    • Cook-Torrance

      • includes “roughness”, other parameters

    • Gooch

      • non-photorealistic, for illustrations

    • Ward

      • includes anisotropy

    • etc…




Anisotropy l.jpg
Anisotropy

  • Material reflects differently in different directions

  • E.g., brushed metal; Ward’s model

isotropic

anisotropic


Outline for today46 l.jpg
Outline for today

  • Overview of lighting

  • Notes on color

  • Local Illumination

  • Light Sources

  • Shading

  • Advanced Lighting


Light sources l.jpg
Light Sources

  • In general, light sources can have complex properties

    • Geometric area over which light is produced

    • Anisotropy in direction

    • Variation in color

  • Some very simple light sources models are standard


Light sources48 l.jpg
Light Sources

  • Two aspects of light sources are important for a local shading model:

    • Where is the light coming from (the L vector)?

    • How much light is coming (the I values)?

  • Various light source types give different answers to the above questions:

    • Directional: Light from a specific direction

    • Point light source: Light from a specific point

    • Spotlight: Light from a specific point with intensity that depends on the direction


Directional light l.jpg
Directional Light

  • When light is coming from a distant source

    • light rays are parallel

    • light ray direction is the same everywhere in the scene

    • as if the source were infinitely far away

    • good approximation to sunlight

  • Specified by a unit length direction vector, and a color

csrc

cl


Point lights l.jpg
Point Lights

  • For closer light sources, such as light bulbs

  • Model as a point that radiates light in all directions equally

    • Light vector varies across the surface

    • Intensity from a point light source drops off proportionally to the inverse square of the distance from the light

p

csrc

cl

cl

v

v


Attenuation l.jpg
Attenuation

  • Sometimes, it is desirable to modify the inverse square falloff behavior of point lights

    • A common (although not physically accurate) model for the distance attenuation is:


Spotlights l.jpg
Spotlights

  • Like point source, but intensity depends on direction:

    • Position: the location of the source

    • Spot direction: the center axis of the light

    • Requires falloff parameters:

      • how broad the beam is (cone angle)

      • how light tapers off at edges of he beam (cosine exponent)

p

csrc

cl

v



Outline for today54 l.jpg
Outline for today

  • Overview of lighting

  • Notes on color

  • Local Illumination

  • Light Sources

  • Shading

  • Advanced Lighting


Shading l.jpg
Shading

  • Various techniques:

    • Flat

    • Gouraud

    • Phong

    • Cartoon

    • Procedural


Flat shading l.jpg
Flat shading

  • Compute shading at a representative point and apply to whole polygon

    • OpenGL uses one of the vertices

  • Advantages:

    • Fast - one shading computation per polygon, fill entire polygon with same color

  • Disadvantages:

    • Inaccurate

    • Faceted


Gouraud shading l.jpg
Gouraud Shading

  • Light each vertex with its own location and normal

    • Result is a color at each vertex

  • Interpolate the colors across each triangle

  • Default mode for most hardware

  • Advantages:

    • Fast: incremental calculations when rasterizing

    • Much smoother - use one normal per shared vertex to get continuity between faces

  • Disadvantages:

    • Don’t get smooth specular highlights

    • C1-discontinuities in colorcause Mach bands: perceptualillusions of edges



Phong shading l.jpg
Phong Shading

  • Want to recompute lighting at every pixel

    • Need normal vector at each pixel

  • Interpolate vertex normals

    • Interpolate the normals while scan-converting

    • Typically, bilinearly interpolate x,y,z; then renormalize

    • Also interpolate or transform to get position in world/camera space

  • Known as Phong Shadingor Phong Interpolation

    • Not to be confused with Phong Lighting Model

    • (though both are often used at the same time)

  • Advantages:

    • More accurate

    • Better images

  • Disadvantages:

    • Slow

    • Still not completely accurate

  • Modern GPUs can perform Phong shading via pixel shaders


Gouraud vs phong shading l.jpg
Gouraud vs. Phong shading

  • Gouraud misses specular hilights

  • solution:

    • tessellate more finely: use smaller triangles

    • that would help with the polygonal artifacts on the silhouettes too

Gouraud Phong


Note perspective distortion l.jpg

Imageplane

i

i

i

i

i

i

u

u

u

u

u

u

Z – into the scene

Note: Perspective Distortion

  • Linear interpolation in screen space doesn’t align with linear interpolation in world space

  • Solutions:

    • Do hyperbolic interpolation (see Buss)

    • Break up into smaller triangles


Cartoon shading l.jpg
Cartoon Shading

  • General approach:

    • Compute diffuse or Phong lighting

    • Remap continuous intensityto two (or a few) levels

    • Some trickery to draw dark edges


Procedural shading l.jpg
Procedural Shading

  • Software or hardware renderer calls an arbitrary routine at every pixel (or sub-pixel)

    • Extreme of “do whatever you want”

    • Can typically implement Phong or any other lighting model

    • Used for patterns or other special effects

    • Used for toon shading

  • Routine typically written in a special-purpose language

    • RenderMan Shading Language (Pixar)

    • Cg (Nvidia)

    • HLSL (DirectX)

  • Routine:

    • can get surface normal, position, material properties, light locations, …

    • computes a color value

    • sometimes can even change the surface position (displacement)



Procedural shading65 l.jpg
Procedural Shading

surface turbulence (float Kd=.8, Ka=.2){ float a,scale,sum; point M; M = transform( "marble", P ); scale = 1; sum = 0; a = sqrt(area(M)); while( a < scale ) { sum += scale * float noise(M/scale); scale *= 0.5; } Oi = sum; Ci = Cs * Oi * (Ka + Kd * I.N * I.N /(I.I * N.N));}

xform to object space

fractal

diffuse lighting (variant)


Programmable gpus l.jpg
Programmable GPUs

  • Two kinds of routines:

    • vertex shaders: routine run for each vertex

    • pixel shaders: routine run for each pixel

  • Limits on

    • size of program

    • amount of memory available

    • types of memory and texture access (will talk about texture later)

    • etc.

  • Technology still improving, capabilities keep expanding


Outline for today67 l.jpg
Outline for today

  • Overview of lighting

  • Notes on color

  • Local Illumination

  • Light Sources

  • Shading

  • Advanced Lighting


Lighting review l.jpg
Lighting Review

  • Local Illumination Lighting Models

    • Ambient

      • Normals don’t matter

    • Lambert

      • Angle between surface normal and light

    • Phong

      • Surface normal, light, and viewpoint

  • What they capture:

    • Direct illumination from light sources

    • Diffuse and Specular reflections

    • (Very) Approximate effects of global lighting


What they don t do l.jpg
What they don’t do

  • Shadows

  • Accurate reflection models

  • Translucency, refraction

  • Caustics (light focusing)

  • Global Illumination

  • Area light sources/emitters

  • Atmospheric effects (fog, clouds)

  • Motion blur

  • Depth of field

  • Lens imperfections

  • Exposure & dynamic range



Slide71 l.jpg
Done

  • Next class: more with lighting…

  • Upcoming: Guest Speakers!

    • Check course web page for info


ad