0% found this document useful (0 votes)
25 views22 pages

8 - Lighting and Shading

Uploaded by

dawitkebedewoldu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views22 pages

8 - Lighting and Shading

Uploaded by

dawitkebedewoldu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Lighting and Shading

1
Lighting
• Realistic displays need to apply natural
lighting effects to the visible surfaces
• Lighting Model or Shading Model or
illumination model used to calculate the
color of an illuminated position on the surface
of an object
• A surface-rendering method uses the color
calculations from an illumination model to
determine the pixel colors for all projected
positions in a scene 2
Lighting
• lighting effects include light reflections,
transparency, surface texture, and shadows.

• modeling the lighting effects that we see on


an object is a complex process, involving
principles of both physics and psychology

– Empirical models - approximations to observed light


properties

3
Lighting

4
Putting Lights in OpenGL
• 1. glEnable(GL_LIGHTING);
• 2. Set up Light properties
– glLightfv(…)
Ex. glLightfv(GL_LIGHT0, GL_AMBIENT, l_ambient);

• 3. Set up Material properties


– glMaterialfv(…)
Ex. glMaterialfv(GL_FRONT, GL_AMBIENT, m_ambient)

5
Shading
• Shading is how we “color” a triangle.

1. Constant Shading

2. Gouraud Shading

3. Phong Shading
6
Constant Shading
• Constant Intensity or Flat Shading

• One color for the entire triangle

• Fast

• Sudden intensity changes at borders

7
Gouraud Shading
• Intensity Interpolation Shading
• Calculate lighting at the vertices. Then interpolate
the colors as you scan convert
• Relatively fast and No sudden intensity changes

8
Phong Shading
• Interpolate the normal, since that is the information
that represents the “curvature”
• Linearly interpolate the vertex normals.
• For each pixel, as you scan convert, calculate the
lighting per pixel.
• True “per pixel” lighting

9
Light Source Properties
• Color
– We usually assume the light has
one wavelength
• Shape
– point light source - approximate
the light source as a 3D point in
space. Light rays emanate in all
directions.
• good for small light sources

10
Distributed Lights
• Light Source Shape …
– distributed light source - approximating the light source
as a 3D object. Light rays usually emanate in specific
directions
• good for larger light sources
• area light sources

11
Light Source Direction
• In computer graphics, we usually treat lights
as rays emanating from a source. The
direction of these rays can either be:
– Omni-directional (point light source)
– Directional (spotlights)

12
Light Position
• We can specify the position of a light one of
two ways, with an x, y, and z coordinate.
• Light at a pixel from a light = Ambient +
Diffuse + Specular contributions.
Ilight = Iambient + Idiffuse + Ispecular

13
Ambient Term - Background Light

• It represents the approximate


contribution of the light to the
general scene, regardless of
location of light and object

• Iambient = color

14
Diffuse Term
• Contribution that a light has on the
surface, regardless of viewing
direction.

• Diffuse surfaces - a ray of light


coming in has an equal chance of
being reflected in any direction.

15
Lambert’s Cosine Law
• Diffuse surfaces follow Lambert’s Cosine Law
• Lambert’s Cosine Law - reflected energy from a small
surface area in a particular direction is proportional to
the cosine of the angle between that direction and the
surface normal.

16
Specular Reflection
• Specular contribution can be thought of as
the “shiny highlight” of a plastic object.
• On a microscopic level, the surface is very
smooth. Almost all light is reflected.
• depend on
Viewing Direction
Normal of the Surface

17
Snell’s Law
• Specular reflection applies Snell’s Law.
 The incoming ray, the surface normal, and
the reflected ray all lie in a common
plane.
 The angle that the reflected ray forms with
the surface normal is determined by the
angle that the incoming ray forms with the
surface normal, and the relative speeds of
light of the mediums in which the incident
and reflected rays propagate according to:
 We assume l = r
18
Snell’s Law is for IDEAL surfaces

• Think about the amount of light reflected at


different angles.
N
R
L

 V

19
Different for dull vs. shiny objects

20
Combining the terms
• Ambient - the combination of light reflections
from various surfaces to produce a uniform
illumination. Background light.
• Diffuse - uniform light scattering of light rays on a
surface. Proportional to the “amount of light” that
hits the surface. Depends on the surface normal
and light vector.
• Specular - light that gets reflected. Depends on
the light ray, the viewing angle, and the surface
normal. 21
Lighting Equation
I final  I ambientk ambient  I diffusek diffuse N  L   I speculark specular  N  H 
shininess

lights1
I final   I la mb ien tk ambient  I ld iffu sek diffuse N  L   I lsp ecu la rk specular  N  H 
shininess

l 0

Ilambient = light source l’s ambient component


Ildiffuse = light source l’s diffuse component
Ilspecular = light source l’s specular component
kambient = surface material ambient reflectivity
kdiffuse = surface material diffuse reflectivity
kspecular = surface material specular reflectivity
shininess = specular reflection parameter (1 -> dull, 100+ -> very shiny) 22

You might also like