BIT304 · 0 · 10 marks
Differentiate Between Ambient Light and Diffuse Reflection. Write Algorithm for Phong Shading.
Differentiate Between Ambient Light and Diffuse Reflection. Write Algorithm for Phong Shading. [10]
Quick answer
Phong Shading is a per-pixel shading method where surface normals are interpolated across the polygon and the illumination model is applied at each pixel to produce smooth, realistic highlights.
Model Answer: Ambient Light vs Diffuse Reflection & Phong Shading Algorithm
Part A: Differentiation Between Ambient Light and Diffuse Reflection
| Aspect | Ambient Light | Diffuse Reflection |
|---|---|---|
| Definition | Constant background illumination that uniformly lights all surfaces regardless of position or orientation | Light reflected equally in all directions from a surface based on the angle of incoming light |
| Direction Dependency | Independent of light source direction and viewer position | Depends on the angle between light source direction and surface normal |
| Formula | I_ambient = K_a · I_a | I_diffuse = K_d · I_l · cos θ = K_d · I_l · (N̂ · L̂) |
| Surface Normal | Not required for computation | Required to calculate the angle of incidence |
| Appearance | Flat, uniform illumination with no shading variation | Shading varies across surface based on orientation |
| Realism | Low: no depth perception | Moderate: gives sense of 3D shape |
| Light Source | Simulates indirect/scattered light in environment | Simulates direct light hitting a rough/matte surface |
| Shadow Effect | No shadows produced | Surfaces facing away from light appear darker |
| Example | Ambient light in a room with no visible source | Chalk piece or matte wall under a bulb |
Part B: Algorithm for Phong Shading
Algorithm Steps:
Step 1: For each polygon, compute normal vectors at each vertex (N̂₁, N̂₂, N̂₃) using the average of normals of adjacent polygons.
Step 2: For each scan line that intersects the polygon, determine the boundary edges (left and right intersection points).
Step 3: Interpolate normals along polygon edges. For each edge, linearly interpolate vertex normals to get the normal at each edge intersection point on the scan line:
$$\hat{N}_a = \frac{y - y_2}{y_1 - y_2}\hat{N}_1 + \frac{y_1 - y}{y_1 - y_2}\hat{N}_2$$
Step 4: Interpolate normals along the scan line. For each pixel between left and right edge, interpolate the normal:
$$\hat{N}p = \frac{x{right} - x}{x_{right} - x_{left}}\hat{N}a + \frac{x - x{left}}{x_{right} - x_{left}}\hat{N}_b$$
Step 5: Normalize the interpolated normal at each pixel:
$$\hat{N}_p = \frac{\hat{N}_p}{|\hat{N}_p|}$$
Step 6: Apply the Phong illumination model at each pixel using the interpolated normal:
$$I = K_a I_a + K_d I_l (\hat{N}_p \cdot \hat{L}) + K_s I_l (\hat{R} \cdot \hat{V})^n$$
Where:
- K_a, K_d, K_s = ambient, diffuse, specular reflection coefficients
- I_a = ambient light intensity
- I_l = light source intensity
- R̂ = reflection vector
- V̂ = viewer direction vector
- n = shininess exponent
Step 7: Assign the computed intensity value to the pixel.
Step 8: Repeat for all scan lines until the entire polygon is rendered.
Advantages:
- Produces realistic specular highlights that appear smooth and correctly positioned
- Eliminates Mach band effect seen in Gouraud shading
- Gives high-quality rendering for curved surfaces
Disadvantage:
- Computationally expensive since illumination model is evaluated at every pixel
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.