Illumination Models - PowerPoint PPT Presentation

1 / 105
About This Presentation
Title:

Illumination Models

Description:

Advanced Computer Graphics Illumination Models Ayd n zt rk ozturk_at_ube.ege.edu.tr http://www.ube.ege.edu.tr/~ozturk – PowerPoint PPT presentation

Number of Views:179
Avg rating:3.0/5.0
Slides: 106
Provided by: DavidB431
Category:

less

Transcript and Presenter's Notes

Title: Illumination Models


1
UBI 516 Advanced Computer Graphics
  • Illumination Models

Aydin Öztürk ozturk_at_ube.ege.edu.tr http//www.ube.
ege.edu.tr/ozturk
2
Lighting
  • Given a 3-D triangle and a 3-D viewpoint, we can
    set the right pixels
  • But what color should those pixels be?
  • If were attempting to create a realistic image,
    we need to simulate the lighting of the surfaces
    in the scene
  • Fundamentally simulation of physics and optics
  • As youll see, we use a lot of approximations to
    do this simulation fast enough

3
Definitions
  • Illumination the transport of energy from light
    sources to surfaces points
  • Note includes direct and indirect illumination
  • Lighting the process of computing the luminous
    intensity (i.e., outgoing light) at a particular
    3-D point, usually on a surface
  • Shading the process of assigning colors to pixels

4
Definitions
  • Illumination models fall into two categories
  • Empirical simple formulations that approximate
    observed phenomenon
  • Physical models based on the actual physics of
    light interacting with matter
  • We mostly use empirical models in interactive
    graphics for simplicity
  • Increasingly, realistic graphics are using
    physically based models

5
Components of Illumination
  • Two components of illumination
  • Light sources
  • Surface properties

6
Components of Illumination(cont.)
  • Light sources (or emitters)
  • Spectrum of emittance (i.e., color of the light)
  • Geometric attributes
  • Position
  • Direction
  • Shape

7
Components of Illumination(cont.)
  • Surface properties
  • Reflectance spectrum (i.e., color of the surface)
  • Geometric attributes
  • Position
  • Orientation
  • Micro-structure

8
Components of Illumination(cont.)
  • Common simplifications in interactive graphics
  • Only direct illumination from emitters to
    surfaces
  • Simplify geometry of emitters to trivial cases

9
Ambient Light Sources
  • Objects not directly lit are typically still
    visible
  • E.g., the ceiling in this room, undersides of
    desks
  • This is the result of indirect illumination from
    emitters, bouncing off intermediate surfaces
  • Too expensive to calculate (in real time), so we
    use a hack called an ambient light source
  • No spatial or directional characteristics
    illuminates all surfaces equally
  • Amount reflected depends on surface properties

10
Ambient Light Sources
  • For each sampled wavelength, the ambient light
    reflected from a surface depends on
  • The surface properties,
  • The intensity of the ambient light source
    (constant for all points on all surfaces )

11
Ambient Light Sources
  • A scene lit only with an ambient light source

12
Directional Light Sources
  • For a directional light source we make the
    simplifying assumption that all rays of light
    from the source are parallel
  • As if the source were infinitely far away from
    the surfaces in the scene
  • A good approximation to sunlight
  • The direction from a surface to the light source
    is important in lighting the surface
  • With a directional light source, this direction
    is constant for all surfaces in the scene

13
Directional Light Sources
  • The same scene lit with a directional and an
    ambient light source

14
Point Sources
  • Emit light equally in all directions
  • p0 point source location
  • Proportional to the inverse square distance

Point source illuminating a surface
15
Point Sources (cont)
  • Finite size light sources
  • Umbra full shadow
  • Penumbra partial shadow
  • Attenuation

Shadows created by finite-size light source
16
Distant Light Sources
  • Far from the surface ? Vector does not change
  • Location ? Direction

parallel light source
point light source
Parallel light source
17
Point Light Sources
  • Using an ambient and a point light source

18
Other Light Sources
  • Spotlights are point sources whose intensity
    falls off directionally.
  • Requires color, pointdirection,
    falloffparameters
  • Supported by OpenGL

19
Spotlights
  • Characterized by a narrow range of angle through
    which light is emitted
  • ps apex of a cone
  • ls direction of pointing
  • ? angle to determine width
  • s angle between ps and the point on the surface
  • Distribution of light
  • Concentrate in the center. Attennuation
  • Light intensity drop off. Exponent

spotlight
20
Other Light Sources
  • Area Light Sources define a 2-D emissive surface
    (usually a disc or polygon)
  • Good example fluorescent light panels
  • Capable of generating soft shadows

21
The Physics of Reflection
  • Ideal diffuse reflection
  • An ideal diffuse reflector, at the microscopic
    level, is a very rough surface (real-world
    example chalk)
  • Because of these microscopic variations, an
    incoming ray of light is equally likely to be
    reflected in any direction over the hemisphere
  • What does the reflected intensity depend on?

22
Lamberts Cosine Law
  • Ideal diffuse surfaces reflect according to
    Lamberts cosine law
  • The energy reflected by a small portion of a
    surface from a light source in a given direction
    is proportional to the cosine of the angle
    between that direction and the surface normal
  • These are often called Lambertian surfaces
  • Note that the reflected intensity is independent
    of the viewing direction, but does depend on the
    surface orientation with regard to the light
    source

23
Lamberts Law
24
Computing Diffuse Reflection
  • The angle between the surface normal and the
    incoming light is the angle of incidence
  • Idiffuse kd Ilight cos ?
  • In practice we use vector arithmetic Idiffuse
    kd Ilight (n l)

25
Diffuse Lighting Examples
  • We need only consider angles from 0 to 90
    (Why?)
  • A Lambertian sphere seen at several different
    lighting angles

26
Attenuation Distance
  • fatt models distance from light
  • Idiffuse kd fatt Ilight (n l)
  • Realistic
  • fatt 1/(dlight)2
  • Hard to control, so use
  • fatt 1/(c1 c2dlight c3dlight2)

27
Specular Reflection
  • Shiny surfaces exhibit specular reflection
  • Polished metal
  • Glossy car finish
  • A light shining on a specular surface causes a
    bright spot known as a specular highlight
  • Where these highlights appear is a function of
    the viewers position, so specular reflectance is
    view-dependent

28
The Physics of Reflection
  • At the microscopic level a specular reflecting
    surface is very smooth
  • Thus rays of light are likely to bounce off the
    microgeometry in a mirror-like fashion
  • The smoother the surface, the closer it becomes
    to a perfect mirror

29
The Optics of Reflection
  • Reflection follows Snells Laws
  • The incoming ray and reflected ray lie in a plane
    with the surface normal
  • The angle that the reflected ray forms with the
    surface normal equals the angle formed by the
    incoming ray and the surface normal

?(l)ight ?(r)eflection
30
Non-Ideal Specular Reflectance
  • Snells law applies to perfect mirror-like
    surfaces, but aside from mirrors (and chrome) few
    surfaces exhibit perfect specularity
  • How can we capture the softer reflections of
    surface that are glossy rather than mirror-like?
  • One option model the microgeometry of the
    surface and explicitly bounce rays off of it
  • Or

31
Non-Ideal Specular Reflectance An Empirical
Approximation
  • In general, we expect most reflected light to
    travel in direction predicted by Snells Law
  • But because of microscopic surface variations,
    some light may be reflected in a direction
    slightly off the ideal reflected ray
  • As the angle from the ideal reflected ray
    increases, we expect less light to be reflected

32
Non-Ideal Specular Reflectance An Empirical
Approximation
  • An illustration of this angular falloff
  • How might we model this falloff?

33
Phong Lighting
  • The most common lighting model in computer
    graphics was suggested by Phong

v
  • The nshiny term is a purelyempirical constant
    that varies the rate of falloff
  • Though this model has no physical basis, it
    works (sort of) in practice

34
Phong Lighting The nshiny Term
  • This diagram shows how the Phong reflectance term
    drops off with divergence of the viewing angle
    from the ideal reflected ray
  • What does this term control, visually?

35
Calculating Phong Lighting
  • The cos term of Phong lighting can be computed
    using vector arithmetic
  • V is the unit vector towards the viewer
  • R is the ideal reflectance direction
  • An aside we can efficiently calculate R

36
Calculating The R Vector
37
Calculating The R Vector
N
L
R2(NL)N-L
2(NL)N
38
Phong Examples
  • These spheres illustrate the Phong model as L and
    nshiny are varied

39
The Phong Lighting Model
  • Lets combine ambient, diffuse, and specular
    components for a single point light source

40
The Phong Lighting Model
  • Light reflection for more than one light source
  • Commonly called Phong lighting
  • Note once per light
  • Note once per color component
  • Do ka, kd, and ks vary with color component?

41
Color Consideration
  • To incorporate color, we need to write the
    intensity equation as a function of the color
    properties of the light sources and object
    surfaces.
  • We specify the reflectivity coefficients as three
    element vectors( Red, Green and Blue)
  • Taking the blue component as an example,
    expression for the intensity can be written as

42
Utah Teapots with Different Material Properties
43
Transparency
  • A transparent surface produces both reflected and
    transmitted light.
  • The relative contribution of transmitted light
    depends on the degree of transparency of the
    surface and whether any light sources are behind
    the transparent surface.

Incident light
transparent object
44
Transparency(cont.)
N
  • Realistic transparency effect are modeled by
    considering the light refraction.
  • The overall effect of the refraction is to shift
    the incident ligh to a parallel path.

R
L
?i
?i
?i
?r
?r
T
45
Transparency(cont.)
  • Snells law
  • Transmission vector T can be used to locate
    intersections of the refraction pathwith objects
    behind the transparent surface

46
Transparency(cont.)
  • We can combine the transmitted intensity through
    a surface from a background object with the
    reflected intensity from the transparent surface.

47
Phong Lighting Intensity Plots
48
Shadows
  • Hidden surface methods can be use to locate areas
    where light sources produce shadows.
  • By applying a hidden-surface method with a
    light source at the view position, we determine
    which surface section cannot be seen.

49
Displaying Light Intensities
  • Values of intensity calculated by an illimunation
    model must be converted to one of the allowable
    intensity levels for the particular graphics
    system in use.

50
Assigning Intensity Levels
  • We perceive light intensities on a logarithmic
    scale. If the ratio of two intensities is the
    same as the ratio of two other intensities, we
    perceive the difference between each pair of
    intensities to be the same.
  • To display n1 successive intensity levels with
    equal perceived brightness, the intensity levels
    on the monitor should be spaced so that the ratio
    of successive intensities is constant.

51
Assigning Intensity Levels(cont.)
  • Any intermediate intensity can be expressed in
    terms of the initial intensity

intensity
1.0
0.5
1.0
0.5
0
Normalized electron gun voltage
52
Assigning Intensity Levels(cont.)
  • The lowest intensity value I0 depends on the
    charecteristic of the monitor.
  • Typically in the range 0.005 to 0.025.
  • For black and white monitor with 8 bits per pixel
    n 255, I0 0.01, r 1.0182
  • Values for the 256 intensities on this system are

    0.0100, 0.0102, 0.0104, 0.0106,
    0.0107, 0.0109, ... , 0.9821

53
Half-toning and Dithering
  • Half-toning
  • Technique to simulate gray levels by creating
    patterns of black dots of varying size
  • Dithering ( digital half-toning)
  • Use digital halftone to simulate halftoning with
    fixed sized pixels

54
  • Polygon Rendering Methods

55
Polygon Rendering Methods
  • We consider the application of an illumination
    model to the rendering of standard objects with
    polygon surfaces.
  • Two ways of rendering surfaces
  • Each polygon can be rendered with a single
    intensity
  • The intensity can be obtained at each point of
    the surface using an interpolation scheme.

56
Constant Intensity Shading(Flat Shading)
  • The simplest approach, flat shading, calculates
    illumination at a single point for each polygon
  • If an object really is faceted, is this accurate?

flat shading of polygonal mesh
57
Constant Intensity Shading
Is flat shading realistic for faceted object?
  • No
  • For point sources, the direction to light varies
    across the facet
  • For specular reflectance,
  • direction to eye varies
  • across the facet

58
Grauraud Shading(cont.)
  • This method renders a polygon surface by linearly
    interpolating intensity values across the
    surface.
  • To get smoother-looking surfaces we introduce
    vertex normals at each vertex
  • Usually different from facet normal
  • Used only for shading
  • Think of as a better approximation of the real
    surface that the polygons approximate

59
Grauraud Shading(cont.)
  • Vertex Normals
  • Vertex normals may be
  • Provided with the model
  • Computed from first principles
  • Approximated by averaging the normals of the
    facets that share the vertex

60
Grauraud Shading(cont.)
  • A common approach
  • Determine the average unit normal vector at each
    polygon vertex.
  • Apply an illumination model to each vertex to
    calculate vertex intensity.
  • Linearly interpolate the vertex intensities over
    the surface of the polygon.

61
Gouraud Shading(cont.)
N2
N1
N4
V
N3
62
Gouraud Shading(cont.)
c1 t1(c2-c1) t3(c1 t2(c3-c1)- c1 -
t1(c2-c1))
C1
c1 t1(c2-c1)
C3
c1 t2(c3-c1)
C2
63
Gouraud Shading
  • Artifacts
  • Often appears dull
  • Lacks accurate specular component

C1
C3
C2
Cant shade that effect!
64
Gouraud Shading
  • Artifacts
  • Mach Banding
  • Artifact at discontinuities in intensity or
    intensity slope

C1
C4
C3
C2
Discontinuity in rateof color changeoccurs here
65
Wireframe
66
Flat Shading
67
Gouraud Shading
68
Phong Shading
  • Linearly interpolating the surface normal across
    the facet, applying the Phong lighting model at
    every pixel
  • Same input as Gouraud shading
  • Usually very smooth-looking results
  • But, considerably more expensive

69
Phong Shading
  • Linearly interpolate the vertex normals
  • Compute lighting equations at each pixel
  • Can use specular component

N1
Remember Normals used in diffuse and specular
terms Discontinuity in normals rate of change
is harder to detect
N4
N3
N2
70
Shortcomings of Shading
  • Polygonal silhouettes remain

Gouraud Phong
71
Wire-frame
72
Ambient Illumination Only
73
Flat-Shading
74
Gouraud Shading
75
Phong Shading
76
Shadows, Texture Enviromental Mappings
77
Raytracing and Radiosity Methods
78
Ray Tracing
  • Cast a ray from the viewers eye through each
    pixel
  • Compute intersection of this ray with objects
    from scene
  • Closest intersecting object determines color

79
Basic Ray Tracing Algorithm
  • First, we set up a coordinate system with the
    pixel positions dsignated in the x-y plane

y
x
Projection reference point
z
80
Basic Ray Tracing Algorithm(cont.)
  • First, we set up a coordinate system with the
    pixel positions dsignated in the x-y plane

R4
R3
T3
S4
R1
S3
R2
T1
S1
S2
Projection reference point
81
Recursive Ray Tracing
  • Cast a ray from intersected object to light
    sources and determine shadow/lighting conditions
  • Also spawn secondary rays
  • Reflection rays and refraction rays
  • Use surface normal as guide (angle of incidence
    equals angle of reflection)
  • If another object is hit, determine the light it
    illuminates by recursing through ray tracing

82
Recursive Ray Tracing
  • Stop recursing when
  • Ray fails to intersect an object
  • User-specified maximum depth is reached
  • System runs out of memory
  • Common numerical accuracy error
  • Spawn secondary ray from intersection point
  • Secondary ray intersects another polygon on same
    object

83
Recursive Ray Tracing
  • Still producing PhDs after all these years
  • Many opportunities to improve efficiency and
    accuracy of ray tracing
  • Reduce the number of rays cast
  • Accurately capture shadows caused by non-lights
    (ray tracing from the light source)
  • Expensive to recompute as eyepoint changes

84
Radiosity
  • Ray tracing models specular reflection and
    refractive transparency, but still uses an
    ambient term to account for other lighting
    effects
  • Radiosity is the rate at which energy is emitted
    or reflected by a surface
  • By conserving light energy in a volume, these
    radiosity effects can be traced

85
Radiosity
86
Radiosity
87
Radiosity
  • Goal Simulate diffuse inter-object reflections
    and shadows

88
Radiosity
  • Basic Idea Treat every polygon as light source

89
Radiosity
90
Matrix Solution Methods
1 iteration
24 iterations
2 iterations
100 iterations
91
Light Sources in OpenGL
92
Light Sources in OpenGL
  • At least 8 light sources
  • GL_LIGHT0, , GL_LIGHT7
  • glEnable(GL_LIGHTING) // light sources enabled
  • glEnable(GL_LIGHT0) // light source 0 on
  • OpenGL uses phong shading model

93
Light Sources in OpenGL
  • Light source functions in OpenGL
  • glLightf ( GLenum light, GLenum name, GLfloat
    value )
  • glLightfv ( GLenum light, GLenum name, GLfloat
    values )

94
Light Sources in OpenGL
  • Light source position (or direction)
  • glLightfv(GL_LIGHT0, GL_POSITION, light0_pos)
  • Point light source, spotlight position
  • GLfloat light0_pos 1.0, 2.0, 3.0, 1.0
  • Distant light source direction vector
  • GLfloat light0_pos 1.0, 2.0, 3.0, 0.0

95
Light Sources in OpenGL
  • The amount of ambient, diffuse, specular light
  • GLfloat ambient_0 1.0, 0.0, 0.0, 1.0 //
    RGBA rep.
  • GLfloat diffuse_0 1.0, 0.0, 0.0, 1.0
  • GLfloat specular_0 1.0, 1.0, 1.0, 1.0
  • glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_0)
  • glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_0)
  • glLightfv(GL_LIGHT0, GL_SPECULAR, specular_0)

96
Light Sources in OpenGL
  • Global ambient light (if necessary)
  • GLfloat global_ambient 0.1, 0.1, 0.1,
    1.0 // RGBA rep.
  • glLightModelfv ( GL_LIGHT_MODEL_AMBIENT,
    global_ambient )

97
Light Sources in OpenGL
  • Distance attenuation model
  • glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, a)
  • glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, b)
  • glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, c)

98
Light Sources in OpenGL
  • Viewer location
  • Default Infinite viewpoint Direction between
    it and any vertex is constant
  • Enabling of COP
  • glLightModeli ( GL_LIGHT_MODEL_LOCAL_VIEWER,
    GL_TRUE )
  • This places the viewpoint at (0, 0, 0).
  • To change to infinite viewpoint pass GL_FALSE.

99
Light Sources in OpenGL
  • Spot Light
  • GLfloat spot_direction -1.0, -1.0, 0.0
  • glLightf ( GL_LIGHT0, GL_SPOT_CUTOFF, 30.0 )
  • glLightf ( GL_LIGHT0, GL_SPOT_EXPONENT, e )
  • glLightfv ( GL_LIGHT0, GL_SPOT_DIRECTOIN,
    spot_direction )

?
100
Light Sources in OpenGL
  • Two-sided shading
  • Enabling of back face shading
  • glLightModeli(GL_LIGHT_MODEL_TWO_SIDED,
    GL_TRUE)

101
Position and Direction (1/5)
  • Achieving three different effects by changing the
    point in the program at which the light position
    is set.
  • 1. Light Remains Fixed

myReshape(int w, int h) glViewport(0, 0, w,
h) glMatrixMode(GL_PROJECTION)
glLoadIdentity() if (w lt h)
glOrtho(-1.5, 1.5, -1.5h/w, 1.5h/w, -10.0,
10.0) else glOrtho(-1.5w/h, 1.5w/h,
-1.5, 1.5, -10.0,10.0) glMatrixMode(GL_MODELV
IEW) glLoadIdentity( )
  • myInit( )
  • GLfloat light_position 1.0, 1.0, 1.0, 1.0)
  • glLightfv(GL_LIGHT0, GL_POSITION,
    light_position)

102
Position and Direction (2/5)
  • 2. Light Moves Relative to a Stationary Object
  • One way to do this is to set the light position
    after the modeling transformation, which is
    itself changed specifically to modify the light
    position.
  • We can begin with the same series of calls in an
    init( ) routine early in the program.
  • Then, probably within an event loop, we need to
    perform the desired modeling transformation (on
    the modelview stack) and reset the light position.

103
Position and Direction (3/5)
  • The Display () routine causes the scene to be
    redrawn with the light rotated spin degrees
    around the object.
  • void display(GLint spin) GLfloat
    light_position 0.0, 0.0, 1.5, 1.0
    glClear( GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_
    BIT ) glPushMatrix( ) glTranslatef( 0.0,
    0.0, -5.0 ) glPushMatrix( ) glRotatef(
    (GLdouble) spin, 1.0, 0.0, 0.0 ) glLightfv(
    GL_LIGHT0, GL_POSITION, light_position )
    glPopMatrix( ) draw_object( ) / Draws
    the object / glPopMatrix( ) glFlush( )

104
Position and Direction (4/5)
  • 3. Light that moves along with the viewpoint
  • Set the light position before the viewing
    transformation.
  • This way, the viewing transformation effects both
    the light and the viewpoint in the same way.
  • In the myInit( ) routine
  • GLfloat light_position 0.0, 0.0, 1.0,
    1.0glViewport(0, 0, w-1, h-1)glMatrixMode(GL_
    PROJECTION)glLoadIdentity( )gluPerpective(40.0
    , (GLfloat) w / (GLfloat) h, 1.0,
    100.0)glMatrixMode(GL_MODELVIEW)glLightfv(GL_L
    IGHT0, GL_POSITION, light_position)

105
Position and Direction (5/5)
  • When the object is redrawn, both the light
    position and the view point are moved spin
    degrees.
  • void display(GLint spin) glClear(
    GL_COLOR_BUFFER_MASK GL_DEPTH_BUFFER_MASK
    )glPushMatrix( ) glTranslatef( 0.0, 0.0,
    -5.0 ) glRotatef( (GLfloat) spin, 1.0, 0.0,
    0.0 ) draw_object( )glPopMatrix( )glFlush(
    )
Write a Comment
User Comments (0)
About PowerShow.com