The Phong Reflection Model - PowerPoint PPT Presentation

1 / 36
About This Presentation
Title:

The Phong Reflection Model

Description:

Specular reflection: Models shiny surface reflection. The Relevant Vectors ... diffuse and specular energy of the light source (which are typically. equal to ... – PowerPoint PPT presentation

Number of Views:1236
Avg rating:3.0/5.0
Slides: 37
Provided by: Eza5
Category:

less

Transcript and Presenter's Notes

Title: The Phong Reflection Model


1
The Phong Reflection Model
  • chapter 8 in Hill

2
Recall
The Phong reflection model is a local
illumination model in which the light coming off
of an object is grouped into one of the following
categories Emission Light emanating from the
object, irrespective of any Light
sources Ambient reflection light which reflect
uniformly from all Objects in all
direction Diffuse reflection Models matte
(unshiny) reflection Specular reflection Models
shiny surface reflection
3
The Relevant Vectors
The shading of s point on a surface is a function
of the relationship between the viewer, light
sources and surface. This is due to the local
illumination model ( other objects of the scene
are ignored) The vectors that are relevant to
shading are shown in figure 1. Basically, we can
think of them (vectors) as being centered on The
point whose shading we wish to compute
4
The Relevant Vectors
NB all vectors shown are unit length
5
Normal vector (n)
A vector that is perpendicular to the surface and
directed outwards from the surface. To determine
normal vector, we can use vector cross
product operation. Given any collinear points,
P0, P1, P2 on a polygon, the normal can be
computed n normalise ((P1 P2) x (P2
P0)) n will be directed outwards if the triple
P0P1 P2 has a counter- clockwise orientation when
seen from outside
6
View vector (v )
A vector v that points in the direction of
the viewer (or camera)
7
Light vector (l )
A vector that points towards the light source
8
Reflection vector ( )
A vector that indicates the direction of
pure reflection of the light vector (Based on the
law of the angle of incidence with respect to
the surface normal equals the angle
of reflection) To compute reflection vector,
first observe that the orthogonal projection of
onto is (all vectors are unit
length) The vector directed from the tip of
to the tip of is
9
Reflection Vector (cont.)
To get observe that we need to add two
copies of Thus we have
10
Halfway vector
A vector h that is the midway between vectors l
and v. Since this is halfway between l and v and
both have been normalised to unit length, we can
compute this by
h normalise (l v)
11
Phong Lighting Equations
In reality, there are no objects that are pure
diffuse reflectors or pure specular
reflectors. The Phong reflection model is based
on the simple modeling assumption that we can
model any (nontextured) objects surface to a
reasonable extent as some mixture of
purely diffuse and purely specular components of
reflection along emission and ambient
reflection The surface material properties of
each object will be specified by a number of
parameters, indicating the intrinsic color of
the object and its ambient, diffuse and specular
reflectance
12
Phong Lighting Equations (cont.)
Let C denote the RGB factors of the objects base
color. In the previous lecture, we assume that
the lights energy is given by two RGB vectors
La, its ambient component and Lp its point
component For consistency with OpenGL, we will
assume that we differentiate Lp into two
subcomponents Ld and Ls for the diffuse and
specular energy of the light source (which are
typically equal to each other) Typically, all
three will have the same proportion of red to
green to blue since they all derive from the same
source
13
Ambient Light
Ambient light is the simplest to deal with. Let
Ia denote the intensity of reflected ambient
light. For each surface, let Denote the
surfaces coefficient of ambient reflection, that
is the fraction of the ambient light that is
reflected from the surface. The ambient component
of illumination is
14
Diffuse Reflection
Diffuse reflection arises from the assumption
that light from any direction is reflected
uniformly in all directions. This kind of
reflector is called a pure Lambertian reflector
15
Diffuse Reflection
The reason that Lambertian reflectors appear
brighter in some parts that others is that if the
surface is facing (I.e perpendicular to) the
light source, then the energy is spread over the
smallest possible area and thus this part of the
surface appears brightest. As the angle of the
surface normal increases with respect to the
angle of the light source, then an equal amount
of the lights energy is spread out over a
greater fraction of the surface and hence each
point of the surface receives (and hence
reflects) a smaller amount of light.
16
Lamberts Cosine Law
Figure 2 Lamberts Cosine Law
17
Lamberts Cosine Law
Figure 2 shows that as the angle between the
surface normal and the vector to the light
source increases (up to a maximum of 90
degrees) then amount of light intensity hitting a
small differential area of the surface dA is
proportional to the area of the perpendicular
cross-section of the light beam, dA cos . This
law is called Lamberts Cosine Law
18
Diffuse Reflection
The key parameter of surface finish that controls
diffuse reflection is , the surfaces
coefficient of diffuse reflection. Let Id denote
the diffuse component of the light source. If we
assume that and are both normalised,
then we have If , then the
point is on the dark side of the object. The
diffuse component of reflection is This is
subject to attenuation depending on the distance
of the object from the light source
19
Specular Reflection
Most objects are not perfect Lambertian
reflectors. One of the most common deviations is
for smooth metallic or highly polished
objects.These objects tend to have specular
highlights (or shiny spots). In OpenGL, the
halfway vector (h) is used for computation of
specular reflection The parameters of surface
finish that control specular reflection are
the surfaces coefficient of specular reflection
and Shininess denoted .
20
Specular Reflection
The formula for the specular component is And
as with diffuse, this is subject to attenuation.
Figure 3 Diffuse and specular reflection
21
Combining Lights Contributions
Combining all of this together with Ie (the light
emitted from an object), the total reflected
light from a point on an object of color C, being
illuminated by a light source L, where the
point is distance d from the light source using
this model
22
Lighting and Shading in OpenGL
To describe lighting in OpenGL there are three
major steps that need to be performed 1.
Setting the lighting and shade model (smooth or
flat) 2. Defining the lights (their positions
and properties) 3. Defining object material
properties
23
Shading
  • Shading uses information obtained from the normal
    vector
  • at each vertex
  • There are two kinds of shading named
  • Flat shading a shading method that accentuates
    the
  • individual polygons (every point in the
    polygon
  • having the same shading)
  • 2. Smooth shading a shading method that blends
    the faces
  • to de-emphasize the edges between
  • polygons (shading varies across the surface
  • by interpolating the vertex shading)

24
Painting a face (polygon)
A face is coloured using a very simple
polygon-fill routine. Sometimes this routine is
called a Tiler because it moves over the polygon
pixel by pixel, coloring each pixel as
appropriate. The pixels in polygon are visited in
a regular order, usually scan line by line from
bottom to the top of the polygon and across each
scan line from left to right.
25
Painting a face
Figure 4
26
Polygon-fill routine
Figure 4 shows a convex quadrilateral where a
face is being filled with a colour. The lowest
and highest points on the face are ybott and
ytop respectively The Tiler first fills in the
row at y ybott ( a single pixel), then the one
at ybott 1, incrementally. At each scan line,
say ys as in the figure, there is a leftmost
pixel xleft and a rightmost pixel xright. The
Tiler moves from xleft to xright, placing the
desired colour in each pixel
27
Polygon-fill routine
The implementation of the Tiler uses a simple
double loop For (int y ybott y lt ytop
y) //for each scan line find xleft and
xright for (int x xleft x lt xright x)
//fill across the scan line find the colour
c for this pixel put c into the pixel at (x, y)

The principle difference between flat and smooth
shading is the manner in which the color c is
determined at each pixel
28
Flat Shading
OpenGL offers a rendering mode in which the
entire face is drawn with the same colour Flat
shading is established in OpenGL by using the
command glShadeModel (GL_FLAT)
29
Smooth Shading
Smooth shading attempts to de-emphasize edges
between faces by computing colours at more points
on each face The two principle types of smooth
shading are Gouroud shading and Phong
shading OpenGL uses Gouroud shading.
30
Gouroud Shading
Computes a different value of c for each
pixel For the scan line at ys (figure), it finds
the colour at the leftmost pixel colorleft, by
interpolation of colour at the top and bottom of
the left edge of the polygon. For the same scan
line, the colour at the top is color4 and the at
the bottom is color1. Therefore colorleft would
be calculated as colorleft lerp (color1,
color4, f) Where the fraction f ys ybott/y4
- ybott varies between 0 and 1 as ys varies from
ybott to y4

31
Gouroud Shading
Similarly, colorright is found by interpolating
the colors at the top and bottom of the right
edge. The Tiler will then fills across the scan
line, linearly interpolating between colorleft
and colorright to obtain the colour at pixel
x c(x) lerp (colorleft, colorright, x-
xleft/xright xleft)
NB the funtion lerp has the following
definition lerp ( a, b, t) a (b a)t
32
Gouroud Shading
Gouroud shading is established in OpenGL using
the function glShadeModel (GL_SMOOTH) Basicall
y, in the program, just before a vertex is given
(with glVertex()), the vertex normal should be
specified (with glNormal())
33
Defining the lights
This step have been discussed in the previous
lecture. Basically, we specify the lights
position and their properties at this stage.
34
Define Surface Materials
When lighting is in effect, rather than
specifying colors using glColor(), we set the
material properties of the objects to
be rendered Surface material properties are
specified by glMaterialf() or glMateriafv(). glMa
terialf (GLenum face, GLenum pname, GLfloat
param) glMaterialfv (GLenum face, GLenum pname,
const Glfloat params)
35
Define Surface Materials
It possible to color front and back faces
separately. The first argument indicates which
face we are colouring (GL_FRONT, GL_BACK or
GL_FRONT_AND_BACK). The second argument
indicates the parameter name (GL_DIFFUSE GL_SPECUL
AR, GL_EMISSION, GL_AMBIENT) The last parameter
is the value (either scalar or vector)
36
GL_NORMALIZE
Normals are used in shading computations and we
need to supply these normal to OpenGL either
manually or through formula. In Phong model,
these normals are assumed to be normalized to
unit length. Enabling this option causes all
normal vectors to be normalized automatically.
Thus, saving our time from having to do extra
work
Write a Comment
User Comments (0)
About PowerShow.com