0% found this document useful (0 votes)
71 views42 pages

Lighting and Shading Updated 03

Computer graphics uses lighting and shading models to realistically render 3D scenes. Ray tracing accurately traces light rays but is computationally expensive. The Phong illumination model approximates light-surface-viewer interactions faster using ambient, diffuse, and specular components. Shading refers to altering colors based on lighting. Flat shading uses one color per polygon, while smooth shading interpolates intensities across polygons in Gouraud or interpolates normals in Phong shading for more realism. OpenGL supports various lighting models and light sources.

Uploaded by

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

Lighting and Shading Updated 03

Computer graphics uses lighting and shading models to realistically render 3D scenes. Ray tracing accurately traces light rays but is computationally expensive. The Phong illumination model approximates light-surface-viewer interactions faster using ambient, diffuse, and specular components. Shading refers to altering colors based on lighting. Flat shading uses one color per polygon, while smooth shading interpolates intensities across polygons in Gouraud or interpolates normals in Phong shading for more realism. OpenGL supports various lighting models and light sources.

Uploaded by

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

Lighting and Shading

Computer Graphics
Lighting & Shading
• Ray tracing: ray tracing is a rendering technique for generating an image
by tracing the path of light as pixels in an image plane and simulating the
effects of its encounters with virtual objects.
– Follow light rays through a scene
– Accurate, but expensive
• Phong Illumination model (this lecture): Illumination model is used to
calculate the intesitiy of the light that is reflected given point on surface
– Approximate only interaction light, surface, viewer
– Relatively fast , supported in OpenGL
Geometric Ingredients
• Three ingredients
– Normal vector m at point P of the surface
– Vector v from P to the viewers eye
– Vector s from P to the light source

P
Types of Light Sources
• Ambient light: no identifiable source or direction
• Diffuse light - Point: given only by point
• Diffuse light - Direction: given only by direction
• Spot light: from source in direction
– Cut-off angle defines a cone of light
– Attenuation function (brighter in center)
• Light source described by a luminance
– Each color is described separately
– I = [I r I g I b ] T (I for intensity)
– Sometimes calculate generically (applies to r, g, b)
Ambient Light
• Global ambient light
– Independent of light source
– Lights entire scene
• Local ambient light
– Contributed by additional light sources
– Can be different for each light and primary color
• Computationally inexpensive
Diffuse Light
• Point Source
– Given by a point
– Light emitted equally in all directions
– Intensity decreases with square of distance
– Point source [x y z 1]T
• Directional Source
– Given by a direction
– Simplifies some calculations
– Intensity dependents on angle between surface
normal and direction of light
– Distant source [x y z 0]T
Spot Lights

• Spotlights are point sources whose intensity


falls off directionally.
– Requires color, point
direction, falloff
parameters
Phong illumination model
Based on modeling surface reflection as a
combination of the following components:

Used to model objects that glow

A simple way to model indirect reflection

The illumination produced by dull smooth surfaces

The bright spots appearing on smooth shiny


surfaces
Diffuse 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?


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 viewer’s
position, so specular reflectance is view dependent
Shading
Shading

Shading refers to the process of altering the color of an


object/surface/polygon in the 3D scene..

 It distance from lights, its angle to the camera and material


properties to create a photorealistic effect.
 Shading is performed during the rendering process by a
program called a shader.
Illumination
Illumination, an observable property and effect of light, may
also refer to Lighting, the use of light sources. Illumination
(image), the use of light and shadow in art.

 An illumination model, also called a lighting model and


sometimes referred to as a shading model, is used to
calculate the intensity of light that we should see at a
given point on the surface of an object.
Intensity
Intensity is a measurable amount of brightness, color, lighting..

Example:

 Illumination models is used to calculate the intensity of light that is


reflected at a given point on a surface.

 Rendering methods use the intensity calculations from the illumination


model to determine the light intensity at all pixels in the image.
Interpolation
Interpolation is in-betweening, or filling in frames
between the frames. It typically calculates the in
between frames to draw images semi-
automatically.

 It defines the stating point and end point. It also


defines the point between start and end point.
Interpolation
Vertex, Vertex Normal
 Vertex

Vertex is a data structure that describes certain attributes,


like the position of a point in 2D or 3D space, at multiple
points on a surface.

 Vertex Normal

A vertex normal at a vertex is a directional vector


associated with a vertex.
Polygon Shading
Types of Shading Model

Flat Shading Smooth Shading

Gouraud Shading Phong Shading


Flat Shading
• For each polygon
– Determines a single intensity
value
– Uses that value to shade the
entire polygon

• Assumptions
– Light source at infinity
– Viewer at infinity
– The polygon represents the
actual surface being modeled
How to do shading
 Find the intensity of the pixel. Then using the Intensity
coloring the whole object
Drawback flat shading
• Match Bone effect
Flat Shading

Wire-frame Model
Flat Shading
Smooth Shading
• 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
• Two types
– Gouraud Shading
– Phong Shading (do not confuse with Phong Lighting
Model)
Smooth Shading
1.Determine average unit normal vector at each
vertex of the polygon
2. Apply an illumination model at each polygon
vertex to obtain the light intensity at the
position
3. Linearly interpolate the vertex intensities over
the projected area of the polygon
Gouraud Shading
• This is the most common approach
– Perform Phong lighting at the vertices
– Color are appropriated across polygon
How to do Gouraud Shading
• Step 1: To obtain average unit normal Vector
• Step 2: Apply Illumination model for
calculating intensity for finding the vertex
intensity.
• Step 3: Intensity Interpolation
Gouraud Shading

Wire-frame
Gouraud
Flat Shading
Shading
Model
Phong Shading
 Instead of interpolating vertex intensities

Phong shading – interpolate vertex normal

 This results in

• More accurate calculation of intensity


values
• More realistic display of surface
highlights
• Greater reduction in the mach band
effect
Phong Shading
Phong Shading
Phong Shading
Phong Shading

Wire-frame
Gouraud
Phong
Flat Shading
Shading
Shading
Model
Complexity of Phong Shading..
Requires more computation than Gouraud shading…

But Advent of programmable GPUs now made this possible


Phong vs Gouraud
If a highlight Shading
does not fall on a vertex
Gouraud shading may miss it completely,
but Phong shading does not.
Shading Models (Direct lighting)

• Flat Shading
– Compute Phong lighting once for entire polygon
• Gouraud Shading
– Compute Phong lighting at the vertices and
interpolate lighting values across polygon
• Phong Shading
– Interpolate normals across polygon and perform
Phong lighting across polygon
Lighting in OpenGL
Lighting in OpenGL [1/2]
• Enabling shading
– glShadeModel(GL_FLAT)
– glShadeModel(GL_SMOOTH); // Gouraud Shading
only
• Using light sources
– Up to 8 light sources
– To create a light
• GLfloat light0_position[] = { 600, 40, 600, 1.0};
• glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
• glEnable(GL_LIGHT0);
• glEnable(GL_LIGHTING);
Lighting in OpenGL [2/2]
– Changing light properties
• GLfloat light0_ambient[] = { 0.4, 0.1, 0.0, 1.0 };
• GLfloat light0_diffuse[] = { 0.9, 0.3, 0.3, 1.0 };
• GLfloat light0_specular[] = { 0.0, 1.0, 1.0, 1.0 };
• glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
• glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
• glLightfv(GL_LIGHT0, GL_SPECULAR, light0_specular);

• For more detail


– See Red Book (Ch 5)
References
• Schaum’s outline – chapter 11
• Foley and Van Dam – Chapter 16

You might also like