PadhaikoAll subjects

Ambient, Diffuse & Specular Reflection; Constant, Gouraud & Phong Shading

Computer Graphics and Visualization (ENCT 201)

Open in the Padhaiko app

6.1 Ambient, Diffuse and Specular Reflection Models

In computer graphics, realistic three-dimensional rendering requires simulating how light interacts with physical surfaces. An illumination model (also referred to as a lighting model or reflection model) calculates the luminous intensity observed at a specific point on an object's surface as a function of light source properties, surface geometry, and material reflectance characteristics.

Light Source Classifications

  1. Point Light Sources: Light rays emanate radially from a localized single coordinate position equally in all directions (e.g. an unfrosted incandescent bulb or candle).
  2. Directional (Distant) Light Sources: Positioned infinitely far away (e.g. the Sun relative to a terrestrial scene). All incident light rays are parallel, defined by a constant direction vector across all points in the scene.
  3. Ambient Light: Uniform, non-directional background illumination resulting from multiple diffuse reflections from walls, floors, and surrounding objects (inter-reflections). It illuminates all surfaces equally from every direction.

1. Ambient Reflection

Ambient light represents the uniform background radiance present in an environment where light has scattered so many times that all directional characteristics are lost.

Definition

Ambient Reflection Model

Ambient reflection produces a uniform level of brightness across all surfaces of an object, regardless of their spatial orientation, surface normal, or the observer's viewing position:

where:

If only ambient reflection were used, 3D curved surfaces would appear as completely flat, silhouette-like two-dimensional shapes, as there is no variation in brightness across faces.


2. Diffuse Reflection (Lambertian Reflection)

Diffuse reflection models the scattering of incident light across rough, matte, or dull surfaces (such as chalk, unfinished wood, clay, or matte paper). Microscopic surface irregularities scatter incoming photons in all directions uniformly.

Definition

Diffuse Reflection and Lambert's Cosine Law

According to Lambert's Cosine Law, the radiant intensity observed from an ideal diffuse (Lambertian) reflector is directly proportional to the cosine of the angle of incidence between the unit surface normal and the unit light direction vector :

where:

Because the apparent projected surface area viewed by an observer also varies with the cosine of the viewing angle, the two cosine factors cancel out: diffuse reflection brightness is completely independent of the observer's viewing position .

Light Source Attenuation

As light travels from a localized point source to a surface across distance , physical energy falls off inversely with the square of distance (). In computer graphics, pure inverse-square attenuation often causes brightness to drop off too steeply. An empirical distance attenuation factor is used instead:

where are user-defined attenuation constants preventing division by zero when .


3. Specular Reflection (Phong Reflection Model)

Specular reflection produces the bright, shiny highlight spots observed on polished, glossy surfaces (such as polished metals, glazed ceramics, plastic, and wet glass). Light is reflected predominantly in the direction of ideal mirror reflection.

Definition

Specular Reflection and Phong Model

Developed by Bui Tuong Phong, the empirical Phong specular reflection model states that specular intensity is concentrated in a cone around the ideal mirror reflection vector , falling off rapidly as the viewing angle between and the viewing vector increases:

where:

The Blinn-Phong Specular Variation

Jim Blinn introduced an efficient alternative that replaces the reflection vector with the halfway vector , defined as the unit vector bisecting the angle between the light vector and viewing vector :

The Blinn-Phong specular term is evaluated as:

When the light source and viewer are distant (directional lighting and orthographic projection), is constant across the entire scene and needs to be computed only once, saving significant computational cycles on GPUs.


4. Combined Illumination Equation

Combining ambient, diffuse, and specular terms for a single point light source yields the complete Phong illumination equation:

For multiple point light sources , their diffuse and specular contributions sum linearly:

For full RGB color rendering, the equation is evaluated independently for each color channel () using channel-specific reflection coefficients (, etc.).

6.2 Shading Models: Constant, Gouraud, Phong and Fast Phong

An illumination model calculates lighting at a specific surface point. A surface rendering (shading) model specifies how that illumination model is applied across the faces of a polygonal mesh to render an entire 3D object on a 2D raster screen.


1. Constant Shading (Flat Shading)

Constant shading (also called flat shading) is the simplest and computationally fastest polygonal surface rendering technique.

Definition

Constant (Flat) Shading

In flat shading, the illumination equation is evaluated exactly once per polygon. The resulting color/intensity is applied uniformly to every pixel covered by the polygon during rasterization.

Flat shading produces physically accurate results under any of the following conditions:

  1. The light source is infinitely distant ( is constant across the entire polygon).
  2. The viewer is infinitely distant ( is constant across the entire polygon).
  3. The polygon is a true planar facet of the object being modeled (e.g. the face of a cube or pyramid), rather than a polygonal approximation of a curved surface.

The Mach Band Effect

When flat shading is applied to a polygonal mesh approximating a curved surface (such as a cylinder or sphere), adjacent polygons have different surface normal orientations and therefore receive different discrete intensities. The human visual system perceives sharp, unnatural intensity steps at polygon boundaries.

Furthermore, an optical illusion known as Mach banding occurs: physiological lateral inhibition in human retinal receptors exaggerates brightness contrast along edges, making the dark side of a boundary appear darker and the bright side appear brighter than their actual physical values. This makes faceted seams stand out prominently.


2. Gouraud Shading (Intensity-Interpolation Shading)

Developed by Henri Gouraud in 1971, Gouraud shading eliminates the faceted appearance of polygon meshes by interpolating illumination intensities smoothly across polygon surfaces.

Theorem

Gouraud Shading Algorithm

The algorithm proceeds in four sequential stages:

  1. Compute Vertex Normal Vectors: At each polygon vertex , compute the average unit normal vector by summing the surface normals of all adjacent polygonal faces sharing that vertex:
  1. Calculate Vertex Intensities: Evaluate the full illumination equation at each vertex using its averaged vertex normal to determine vertex intensities (e.g. for a triangle).
  2. Linearly Interpolate Intensities Along Edges: For each horizontal scanline intersecting an edge between vertices (at ) and (at ):
  1. Linearly Interpolate Intensities Across the Scanline: Between the left edge intersection (intensity ) and right edge intersection (intensity ):

Using incremental additions: , where .

Limitations of Gouraud Shading


3. Phong Shading (Normal-Vector Interpolation Shading)

Developed by Bui Tuong Phong in 1973, Phong shading interpolates surface normal vectors rather than intensity values across polygon surfaces, calculating illumination independently at every rasterized pixel.

Theorem

Phong Shading Algorithm

The algorithm proceeds through the following stages:

  1. Compute Vertex Normals: At each vertex, calculate average unit normals from adjacent face normals.
  2. Interpolate Normals Along Polygon Edges: For each scanline, compute the interpolated edge normal between vertices and :
  1. Interpolate Normals Across the Scanline: Between the left edge normal and right edge normal :
  1. Renormalize and Evaluate Illumination Per Pixel: Because linear interpolation of two unit vectors does not produce a unit vector, normalize the interpolated vector at each pixel:

Evaluate the full illumination equation (ambient + diffuse + specular) using to determine pixel color.

Advantages and Computational Bottleneck


4. Fast Phong Shading

To overcome the per-pixel normalization bottleneck of standard Phong shading, Fast Phong shading (developed by Gary Bishop and David Weimer) approximates the illumination function over a polygon using a Taylor series expansion or a second-degree bivariate polynomial.

Theorem

Fast Phong Shading Algorithm

The per-pixel intensity function across a polygon surface is approximated by a 2D bivariate polynomial:

where coefficients are determined by matching lighting values and partial derivatives evaluated at selected sample points on the polygon.

Scanline Evaluation via Forward Finite Differences: Along any horizontal scanline (), the 2D polynomial simplifies to a 1D quadratic polynomial in :

where , , and .

Evaluating across the scanline requires no square roots, divisions, or multiplications:

  1. First Forward Difference:
  1. Second Forward Difference:

Incremental Forward-Difference Update Loop: At each successive pixel across the scanline:

Each pixel requires only two simple additions, achieving a to speedup over standard Phong shading while preserving specular highlight fidelity.

Comparison of Shading Models
FeatureFlat (Constant) ShadingGouraud ShadingPhong ShadingFast Phong Shading
Normal Calculation1 per polygon (face normal)1 per vertex (averaged)1 per vertex + interpolated per pixelSample points per polygon
Lighting EvaluationOnce per polygonOnce per vertexOnce per pixel (full equation)Bivariate polynomial per pixel
Interpolated QuantityNone (constant color)Pixel intensity Surface normal vector Forward difference intensities
Per-Pixel OperationsNone (copy color)1 addition ()1 inverse square root + 3 divisions + power2 additions ()
Specular HighlightsPoor / facetedDistorted; lost in polygon interiorsHighly accurate anywhereNear-identical to Phong
Mach BandingSevereNoticeable along edgesVirtually eliminatedVirtually eliminated

Worked Examples

Example 6.1

6.1

A point on a 3D surface has unit outward normal . A point light source of intensity is positioned along direction , and the camera viewing direction is . The surface material has ambient reflectivity , diffuse reflectivity , specular reflectivity , and shininess exponent . Ambient illumination intensity is , and distance attenuation is :

  1. Calculate the ambient reflection intensity .
  2. Verify that and are unit vectors, and calculate the diffuse reflection intensity .
  3. Determine the ideal reflection vector .
  4. Calculate the specular reflection intensity .
  5. Compute the total combined surface intensity .

Evaluating ambient reflection:

Checking unit vectors and calculating diffuse reflection: Verify vector magnitudes:

Compute the dot product :

Calculate diffuse intensity:

Evaluating ideal reflection vector : Using :

Check magnitude: .

Calculating specular reflection: Compute the dot product :

Because the reflection vector points directly along the line of sight ():

Computing total combined intensity:

Answer:
  1. .
  2. .
  3. .
  4. .
  5. Total intensity: .
Example 6.2

6.2

A triangle has vertices , , and with computed illumination intensities , , and . Using Gouraud shading:

  1. Determine the intersection coordinates and interpolated intensities on edges and along horizontal scanline .
  2. Compute the interpolated intensity at pixel on this scanline.

Interpolating edge at scanline : Edge spans from to . The fractional height parameter at is:

The -coordinate intersection is:

The interpolated intensity at this intersection is:

Interpolating edge at scanline : Edge spans from down to . The fractional parameter from to is:

The -coordinate intersection is:

The interpolated intensity at this intersection is:

Interpolating across scanline to pixel : The scanline span runs from to , with total span width . At pixel :

Interpolating intensity:

Answer:
  1. Along scanline :
    • Left intersection on : , intensity .
    • Right intersection on : , intensity .
  2. At pixel , interpolated intensity is .
Example 6.3

6.3

In Fast Phong shading, the intensity profile along a horizontal scanline is governed by the quadratic polynomial :

  1. Determine the first forward difference and constant second forward difference .
  2. Starting at , evaluate the exact intensity and initial step .
  3. Use the forward-difference addition equations to calculate intensities for pixels and .

Deriving forward difference equations: For quadratic polynomial with :

Evaluating initial values at :

Stepping across pixels using forward differences:

  • At :
  • At :
  • At :
  • At :
Answer:
  1. , .
  2. Initial values: , .
  3. Successive pixel intensities: , , , .

Exercises

Illumination and Surface Rendering Exercises

Question 1

Differentiate between diffuse reflection and specular reflection with respect to surface physics, governing mathematical laws, directional dependence, and visual appearance.

Contrasting physical mechanisms and governing equations:

  • Diffuse reflection occurs on rough or matte surfaces where microscopic roughness scatters incident photons equally in all directions according to Lambert's cosine law: .
  • Specular reflection occurs on polished or glossy surfaces where incident light is reflected into a narrow cone surrounding the ideal reflection vector governed by Phong's model: .

Comparing viewer dependence and appearance:

  • Viewer Dependence: Diffuse reflection is independent of viewer direction , as perceived projected area and radiant intensity cancel out. Specular reflection depends strongly on viewing direction .
  • Appearance: Diffuse reflection provides baseline shape definition and color. Specular reflection creates bright highlight glints that convey surface glossiness.
Answer:

Diffuse reflection obeys Lambert's cosine law (), scattering uniformly in all directions independently of viewing direction. Specular reflection follows Phong's power law (), forming directional highlight glints that vary with camera position.

Question 2

A light ray with unit vector strikes a surface with unit normal . The light intensity is , diffuse reflection coefficient is , ambient light intensity is , and ambient reflection coefficient is . If specular reflection is neglected:

  1. Compute the angle of incidence .
  2. Calculate the total reflected intensity .

Evaluating the angle of incidence:

Calculating ambient and diffuse contributions:

Wait, checking coefficients: , , total .

Answer:
  1. Angle of incidence: ().
  2. Reflected intensity: .
Question 3

Derive the expression for the unit ideal reflection vector . Using this formula, compute when and .

Deriving vector : Decompose incident vector into components normal and tangent to the surface:

The ideal reflected ray reverses the tangential component while preserving the normal component:

Evaluating numerical reflection vector: Compute the dot product :

Compute :

Check magnitude: .

Answer:
  1. .
  2. .
Question 4

Compare Gouraud shading and Phong shading in detail. Why does Gouraud shading fail to accurately render specular highlights in polygon interiors, and why does Phong shading resolve this issue?

Comparing interpolation mechanisms:

  • Gouraud shading computes lighting strictly at polygon vertices and bilinearly interpolates the resulting scalar intensities across polygon edges and scanlines.
  • Phong shading linearly interpolates the 3D surface normal vectors across edges and scanlines, renormalizes the normal vector at each pixel, and evaluates the complete illumination model at every pixel.

Analyzing specular highlight behavior:

  • In Gouraud shading, if a specular highlight falls within a polygon's interior but does not encompass any vertex, all vertices have near-zero specular values. Linear interpolation between near-zero values yields near-zero values across the entire interior, completely extinguishing the highlight.
  • In Phong shading, the interpolated normal vectors correctly curve across the polygon interior, reproducing the true surface orientation required to align with , thereby capturing the specular highlight at its exact interior location.
Answer:

Gouraud shading interpolates scalar intensities from vertices; if a highlight lies entirely in the polygon interior without touching a vertex, the vertex intensities are low and the interior highlight is lost. Phong shading interpolates normal vectors across pixels and evaluates lighting per pixel, capturing highlights anywhere on the surface.

Question 5

Explain the Fast Phong shading method. How does it eliminate per-pixel vector normalization, and how are pixel intensities evaluated across a scanline using forward differences?

Approximation formulation: Fast Phong shading replaces the expensive per-pixel vector normalization and power computation with a bivariate second-degree polynomial approximation of intensity:

Along a horizontal scanline (), the expression reduces to a 1D quadratic polynomial:

Forward difference mechanics:

  1. Constant second difference: .
  2. Initial first difference: .
  3. Per-pixel scanline update:

This requires only two additions per pixel, completely eliminating divisions, square roots, and exponentiations.

Answer:

Fast Phong shading approximates per-pixel intensity with a bivariate polynomial that simplifies to a 1D quadratic along scanlines. It evaluates intensity incrementally using two additions per pixel via forward finite differences (, ), eliminating vector normalization and powers.

Question 6

A surface point at distance from a point light source () has surface normal making an angle of with the incident light direction (). The material has , ambient intensity is , and attenuation parameters are . Assuming no specular reflection:

  1. Compute the distance attenuation factor .
  2. Calculate the diffuse intensity and total intensity .

Evaluating the distance attenuation factor:

Calculating intensities: Ambient intensity:

Diffuse intensity:

Total intensity:

Answer:
  1. Attenuation factor: .
  2. Intensities: , , total intensity .

Past exam questions for Computer Graphics and Visualization

← Image/Object Space; Back-Face, Z-Buffer, A-Buffer, Scan-LineAnimation Functions, Raster Animation, Key-Frames & Motion Specification →