Assume all light is white, then say i is the intensity of the light.

Point lights emit light from a fixed point in 3D space (their position). They’re also called omnidirectional lights because light comes out equally in every direction. They are light bulbs.

L is the direction from a point in the scene P to the light Q. L is the light vector and L = Q - P. Q is fixed, P can be any point in the scene.

Directional lights is like the sun from earth. Instead of a position, they have a fixed direction. In this case, L is given so it is the same for all points P.

Ambient light is light that is scattered from other objects (not how we’ll do it, but if you treat every object as a light source it is called global illumination). For our raytracer: ambient light is only characterized by its intensity, and it contributed some light to every point in the scene no matter where it is. It’s a lot simpler than doing full GI.

Most scenes will have a single ambient light and an arbitrary number of point and directional lights.

To color a point, we can figure out the intensity i contributed by each light source, sum them up, then multiply that by the color of the surface at that point.

When light hits a matte object, the light is scattered back equally in all directions (a diffuse reflection). We use N to represent the surface normal (a unit vector, length 1) of a surface at P.

Diffuse reflection equation

Light received by point P with normal N in a scene with ambient light I_A and n point or directional lights with intensity I_n and light vectors L_n (known for directional lights or computed for P for point lights).

$I_P=I_A+\sum_{i=1}^{n}I_i\frac{\vec{N}\cdot \vec{L_i}}{|\vec{N}| |\vec{L_i}|}$

The normal of a sphere is N = (P-C) / |P-C|

When light hits a shiny object light is reflected in a certain direction R. This is a specular reflection or highlight. The closer L is to R, the more light is reflected. Use V the view vector pointing from P to the camera. Shininess is the measure of how quickly the reflection function decreases as the angle between V and R increases.

$R=2\vec{N}(\vec{N}\cdot\vec{L})-\vec{L}$

$I_S=I_L(\frac{\vec{R}\cdot\vec{V}}{|\vec{R}||\vec{V}|})^S$

The full illumination equation then comes from ambient, diffuse, and and specular.