Basic Shading

How to 3D

Chapter 6: Lighting

Basic Shading

Pick up a book and hold it under a nearby light source. Rotate the book around. When does the cover of the book shine brightest? When does the cover appear darkest?

When the cover is perpendicular to the light source, its surface is brightest. When the cover is facing to the side or away from the light source, its surface is not illuminated by the light source at all—at least not directly. To recreate in a virtual world the lighting that we experience in the physical world, we must come up with a scheme to measure how much a surface faces a light source.

In computer graphics, we describe the direction a surface faces using a normal—a vector perpendicular to the surface. Explore how this triangle's illumination changes based on the alignment of its normal to the yellow light source:

Click and drag on the triangle to rotate just it. Click and drag on the background to rotate the whole scene. If you see red, you are looking at the unilluminated back face of the triangle.

Modifying a triangle's color based on its relationship to light sources is called shading. The work of shading is performed in a shader; thus its name. In this chapter, we examine one common shading algorithm. By its end, you'll be able to answer the following questions:

Many modern renderers use shading algorithms that are more physically accurate than the one we'll discuss. Physically-based rendering (PBR) is a common one. These algorithms are more complex and expensive, and they often depend on textures—a topic that we haven't discussed yet. Our basic shading algorithm is a reasonable place to start.

Diffuse Term →