notesonly.in

One notebook for every subject — open it anywhere.

Log in

Shading and Lighting Models: Complete Beginner's Guide

Shading and lighting models are the math that decides how bright each pixel of a 3D object should be. A 3D model is just geometry — without lighting, everything would look flat and uniformly coloured. Lighting models simulate light hitting surfaces and bouncing toward the viewer, creating the highlights and gradients that make objects look solid.

Lighting does most of the visual heavy lifting: a simple model with great lighting beats a detailed model with bad lighting. Every graphics programmer and 3D artist works with these models daily.

Key Concepts

  • Normal: a vector perpendicular to the surface; lighting depends on angles between the normal, light direction, and viewer.
  • Ambient light: the base illumination present everywhere, preventing pitch-black shadows. A simple constant added to every pixel.
  • Diffuse reflection: matte scattering (like chalk); brightness follows Lambert's law — proportional to the cosine of the angle between normal and light.
  • Specular reflection: shiny highlights (like polished metal), strongest when the viewer aligns with the reflected ray.
  • Phong model: the classic model combining ambient + diffuse + specular, computed per pixel.
  • Blinn-Phong: a cheaper, widely used variant of Phong that replaces the reflection vector with a halfway vector.
  • Gouraud shading: an older technique computing lighting per vertex and interpolating — faster but blurrier highlights than per-pixel Phong.

How It Works

The Phong model computes each pixel's colour in steps:

  1. Add the ambient term: a small constant, so nothing is fully black.
  2. Diffuse term: dot product of normal (n) and light direction (l) — 1 means head-on light, 0 means grazing.
  3. Specular term: reflect the light vector around the normal, dot it with the view direction, raise to a shininess power — higher powers, tighter highlights.
  4. Add all three terms and multiply by the surface colour. Clamp the result so it stays in displayable range.

Worked Example

A surface has normal n = (0, 1, 0), lit from direction l = (0.6, 0.8, 0). Check normalization: 0.6 squared + 0.8 squared = 0.36 + 0.64 = 1.0 — length 1. Diffuse factor = n dot l = (0 × 0.6) + (1 × 0.8) + (0 × 0) = 0.8 — the surface gets 80 percent of diffuse strength. With ambient 0.2 and light colour 1.0, the final brightness = 0.2 + (0.8 × 0.8) = 0.2 + 0.64 = 0.84, or 84 percent brightness — a well-lit surface with a soft gradient as the normal turns away from the light.

Common Misconceptions

  • "More lights always look better." Each light adds computation per pixel, and too many create flat, washed-out scenes. Professionals use few carefully placed lights plus ambient fill.
  • "Specular highlights appear on all materials." Only smooth, shiny surfaces show strong speculars. Rough materials like cloth scatter light diffusely, which is why the shininess exponent matters.
  • "Phong is physically accurate." It is a convincing approximation, not physics. Modern games use PBR (physically based rendering), modelling real properties like metalness and roughness for consistent results under any lighting.

Real-World Applications

Blinn-Phong runs in mobile and indie games where performance matters; PBR powers AAA titles and films for realistic metal, skin, and fabric. 3D tools like Blender let artists tune these models visually, and WebGL product viewers use them so online shoppers see realistic materials. Understanding these models is also the gateway to advanced topics like shadows, reflections, and global illumination.

In short, lighting models turn flat geometry into believable objects: ambient lifts the shadows, diffuse gives matte form, and specular adds shiny highlights. The Phong recipe — with its simple dot products — remains the clearest introduction to how every rendered image gets its light.