0 1

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]

Computer GraphicsChapter 9: Illumination and Shading ModelsPhong shading algorithm and procedure

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

AspectAmbient LightDiffuse Reflection
DefinitionConstant background illumination that uniformly lights all surfaces regardless of position or orientationLight reflected equally in all directions from a surface based on the angle of incoming light
Direction DependencyIndependent of light source direction and viewer positionDepends on the angle between light source direction and surface normal
FormulaI_ambient = K_a · I_aI_diffuse = K_d · I_l · cos θ = K_d · I_l · (N̂ · L̂)
Surface NormalNot required for computationRequired to calculate the angle of incidence
AppearanceFlat, uniform illumination with no shading variationShading varies across surface based on orientation
RealismLow: no depth perceptionModerate: gives sense of 3D shape
Light SourceSimulates indirect/scattered light in environmentSimulates direct light hitting a rough/matte surface
Shadow EffectNo shadows producedSurfaces facing away from light appear darker
ExampleAmbient light in a room with no visible sourceChalk 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.