CSCI 461: Computer Graphics

Middlebury College, Fall 2023

Lecture 03: Shading

By the end of today's lecture, you will be able to:

  • compute the ambient, diffuse and specular contributions to the color at a surface point,
  • cast a secondary ray to a light source to determine if a point is in a shadow,
  • cast secondary rays off of reflective materials.
Our scenes have looked kind of 2d - shading will make them look like they're in 3d!

Shading is the process of darkening areas that don't face a light source, and brightening those that do.

WARNING: shading versus reality!


From FAQ in Chapter 10 of Fundamentals of Computer Graphics.

How do we see color? Light travels from a source and reflects off of objects.

Two ingredients: light sources and materials.

Ingredient #1: Light sources have a color, and a location or direction.

We'll mostly work with a mix of "point" and "directional" lights.

Area lights are more realistic, but harder (and more expensive) to model.

Ingredient #2: Materials reflect certain light components, absorb others.

Things we need to consider:

  • albedo: fraction of incoming light diffusely reflected,
  • properties: in what direction is light reflected?

We will look at matte-like, plastic-like, mirror-like and also translucent materials.

Our shading equation (Phong Reflection Model):
     ambient + diffuse + specular contributions.

Works really well if we want to render plastic!

The ambient contribution ($I_a$) provides background lighting.

How does the angle between $\vec{n}$ and $\vec{l}$ influence the illumination? Vote at slido.com (event #4076924)!

Light scatters in all directions across diffuse (matte-like) surfaces ($I_d$).

Specular term ($I_s$) adds a highlight to glossy surfaces.

The Phong Reflection Model: how much a surface point is illuminated by light sources.

$$I = c_a k_m + c_l k_m \max\left(0, \vec{n}\cdot\vec{l}\right) + c_l k_s \max(0, \vec{v}\cdot\vec{r})^p$$
  • $\vec{n}$: unit surface normal,
  • $\vec{l}$: unit vector from surface point to light,
  • $\vec{r} = -\vec{l} + 2(\vec{l}\cdot\vec{n})\vec{n}$ (reflection of $\vec{l}$ across $\vec{n}$),
  • $\vec{v}$: unit vector from surface point to eye,
  • $p$: shininess

Practice exercise!

Click to open the editor.

What about shadows?

Cast a ray from intersection point to light source.
No intersection? use $I_a$, otherwise add $I_d$ and $I_s$.

What about mirrors?

Cast a ray from intersection point in reflection direction (reflect ray direction across $\vec{n}$).
Calculate color recursively!

Limit number of bounces in recursive ray tracer.

Computing the reflection direction.

Summary

  • Calculate color = ambient + diffuse + specular terms.
  • Good idea to write a general function to determine intersection of ray with objects in scene (this is why both Sphere and Triangle classes in Lab 2 had a similar intersect function).
  • You will need to return information about the intersection as well (point, normal, material) - not just $t$ anymore!