BIT304 Computer Graphics

Computer GraphicsUnit 810 min read

Illumination & Shading Models: Phong, Gouraud, Local vs Global Lighting

Unit 8 of Computer Graphics explores how light interacts with surfaces to create realistic 3D renderings, covering Phong and Gouraud shading models, illumination components (ambient, diffuse, specular), and their mathematical foundations with worked examples tied to real-world applications like game engines and e-comme

TAKEAWAYS:

  • Phong vs Gouraud: Gouraud interpolates vertex colors, Phong interpolates normals and computes shading per pixel for smoother highlights.
  • Lighting components: Ambient (global), diffuse (Lambertian), and specular (mirror-like) combine via the Phong reflection model.
  • Normal vectors: Critical for accurate diffuse/specular calculations; interpolated in Gouraud, recomputed per pixel in Phong.
  • Real-world use: Used in game engines (Unity/Unreal), e-commerce (Daraz product renders), and AR/VR apps (Pathao delivery tracking).
  • Performance tradeoff: Gouraud is faster (vertex-level), Phong is more accurate (pixel-level) but computationally expensive.
  • Blinn-Phong: Optimized specular term using halfway vector for efficiency in real-time rendering.

Core Concepts: How Light Interacts with Surfaces

1. The Three Pillars of Illumination

Light interaction with surfaces is modeled using three components, visualized below:

graph LR
    A["Ambient Light"] -->|"Global illumination"| B["Diffuse Reflection"]
    B -->|"Lambertian cosine law"| C["Specular Reflection"]
    C -->|"View-dependent highlights"| D["Final Color"]
  • Ambient Light: Simulates indirect lighting (e.g., light bouncing off walls). Mathematically: where is the ambient reflection coefficient (0–1).

  • Diffuse Reflection: Scatters light equally in all directions (matte surfaces). Follows Lambert’s cosine law: = light direction, = surface normal, = light intensity.

  • Specular Reflection: Creates shiny highlights (mirror-like). Original Phong model: = reflected light direction, = view vector, = shininess exponent.


2. Phong vs Gouraud Shading: The Key Difference

Both methods approximate surface shading, but differ in where calculations occur:

Aspect Gouraud Shading Phong Shading
Calculation Point At vertices (interpolates colors) At each pixel (interpolates normals)
Accuracy Less accurate (flat shading between vertices) More accurate (smooth highlights)
Performance Faster (fewer calculations) Slower (per-pixel computation)
Artifacts Mach bands (false edges) None
Use Case Real-time applications (games, AR) High-quality renders (movies, product visuals)

Worked Example: Gouraud Shading for a Triangle Consider a triangle with vertices , , and normals:

  1. Compute vertex colors using Phong reflection model:

    • For and (assuming light at and view at ): (Assume , , , , , , )
    • For :
  2. Interpolate colors across the triangle’s pixels. The result:

    graph TD
      A["A (white)"] -->|"Linear interpolation"| B["Edge AB"]
      B --> C["C (dark)"]
      A --> D["Edge AC"]
      D --> C
      C --> E["Edge BC"]
      E --> B

    Visualization: The triangle appears gradient from white to dark, with no sharp highlights.

Real-World Tie-In: Daraz’s product images use Gouraud shading for real-time previews during shopping. For example, when you rotate a shoe in the 3D viewer, the renderer uses vertex shading to balance speed and quality. High-end renders (e.g., for ads) switch to Phong shading.


3. Phong Reflection Model: Derivation and Specular Trick

The specular term in Phong’s model uses the reflection vector , computed as: where:

  • = normalized surface normal,
  • = normalized light direction.

Worked Example: Specular Highlight on a Sphere Assume:

  • Surface normal at a point: ,
  • Light direction: ,
  • View direction: ,
  • , , .
  1. Compute : Normalize :

  2. Compute : Result: No specular highlight at this point (light is grazing the surface).

Optimization: Blinn-Phong Model To reduce computations, Blinn-Phong replaces with the halfway vector : This is used in Unity3D for real-time games like Genshin Impact, where performance matters more than pixel-perfect accuracy.


4. Global Illumination vs Local Illumination

Aspect Local Illumination (Phong/Gouraud) Global Illumination (Ray Tracing)
Light Sources Single light or ambient Multiple bounces, shadows, reflections
Computation Fast (per-pixel or per-vertex) Slow (recursive ray tracing)
Realism Limited (no indirect light) High (caustics, soft shadows)
Example eSewa’s 2D bill visualization The Last of Us’ cinematic lighting

Real-World Example: NTC’s Power Outage Maps NTC’s website uses local illumination for real-time power grid visualizations. When you hover over a region, the shading highlights outages using a simplified Phong model (diffuse only) for performance, as shown below:

graph TD
    A["Power Grid"] --> B["Local Illumination"]
    B --> C["Diffuse Shading"]
    C --> D["Highlight Outages"]

Advanced Topics

1. Normal Mapping for Pseudo-Detail

Normal maps store per-pixel normal deviations in a texture, tricking the renderer into seeing fine details without geometry. Used in:

  • Pathao’s delivery driver UI: Shows "bumpy" road textures on low-poly maps.
  • Game engines: Adds detail to low-poly models (e.g., Call of Duty’s brick walls).

Worked Example: Normal Map Application

  1. Original flat surface normal: .
  2. Normal map sample at a pixel: (stored in RGB).
  3. Perturbed normal: Now shading uses instead of .

2. Environment Mapping for Reflections

Stores a panoramic image (e.g., cube map) to simulate reflections. Used in:

  • Khalti’s transaction success screens: Shows "reflective" surfaces on payment confirmation icons.
  • Google Maps: Simulates water reflections in satellite views.

## In the Real World

  1. eSewa’s Bill Visualization

    • Idea Used: Gouraud shading for 2D bill rendering.
    • How: When you pay a bill, the app displays a simplified 3D-like bar chart using linear color interpolation between vertices to show payment progress. This avoids per-pixel calculations, ensuring smooth rendering on low-end phones.
  2. Daraz’s 3D Product Previews

    • Idea Used: Phong shading with Blinn-Phong optimization.
    • How: Products like shoes or electronics use real-time Phong shading for interactive previews. The halfway vector trick () reduces the shininess exponent () from 20 to 5, making it run at 60 FPS on mid-range devices.
  3. Ncell’s Network Coverage Maps

    • Idea Used: Local illumination with ambient/diffuse only.
    • How: The app shades coverage areas using a single light source (ambient for background, diffuse for signal strength). Specular highlights are omitted for clarity, as shown in the real-time signal strength meter.

## Exam Tip

  1. Differentiate Phong vs Gouraud:

    • Gouraud: "Interpolates colors at vertices" → mention mach bands.
    • Phong: "Interpolates normals per pixel" → mention smooth highlights.
    • Exam Trap: Some questions ask for "derivations." For Gouraud, show the barycentric interpolation of colors. For Phong, derive the specular term step-by-step (include ).
  2. Phong Model Components:

    • Always write the full equation:
    • Label each term in words (e.g., "the specular term accounts for mirror-like reflections").
  3. Real-World Applications:

    • Link shading models to performance vs quality tradeoffs. Example:

      "In Pathao’s driver app, Gouraud shading is used for the delivery route preview because it renders faster on Android phones, while high-end ads on Daraz use Phong shading for photorealistic product images."

  4. Diagrams:

    • Must include in answers:
      1. A triangle with interpolated colors (Gouraud).
      2. A surface with per-pixel normals (Phong).
      3. The reflection vector and view vector for specular calculation.
    • Use Mermaid for these in exams (e.g., graph TD for interpolation paths).
  5. Common Pitfalls:

    • Forgetting to normalize vectors (, , , ).
    • Misapplying the shininess exponent : higher = tighter highlight.
    • Confusing Blinn-Phong () with Phong ().

Final Note: Illumination models bridge math and art in computer graphics. Master the Phong equation, Gouraud interpolation, and real-world tradeoffs—these are the core of 70% of exam questions. For practicals, implement a simple Phong shader in OpenGL; the exam may ask for pseudocode!

Based on the TU BIT syllabus for Computer Graphics (BIT304), unit 8.

Discussion

Loading…