Cosine distributed sampling is important to implement soft shadow and ray tracing global illumination. But to find out why, let's go back to the rendering equation.
The reflected radiance is given by
For a perfectly diffuse surface,
For ease of notation we can drop the first incident direction. Now ω represents reflected direction term of BRDF for notation, we can write
Take the Monte Carlo importance sampling estimator.
Thus, it is possible to sample uniformly and average over contributions of all light and then multiply by the cos(theta) OR sample cosine distribution.
However, according to experiments done by others like here it is more efficient to sample cosine distribution for smaller n because for uniform, you are wasting on samples that contribute very little ie. small cos(theta).
Let u1,u2 be random uniformly distributed variable in interval [0,1].
This produces a scatterplot of 100 points bellow.
Using cosine distributed sampling
Penumbras(soft shadow) achieved using distributed ray tracing.When light source is a single point, tracing a shadow ray from a spot on the object to a light either intersects or does not intersect. This produces distinct difference between shadow and lit-areas.
See left. I implemented attenuation on the 2 light sources so the shadow of the object from light source 1 is darker than shadow from light source 2.
With the objective, light is modeled as a sphere. The shadow ray can be traced to a radius around the light. However, the number of light rays from the light source is distributed by cosine distribution. The farther away from the center point of the sphere, the less bright the light source. I learned in CS488, to implement soft shadow the idea is to perturb a shadow ray by a angle in a cosine distribution centered around the location of the light source.
Let's call light source 1 in behind of the viewer and and light source 2 in front of the viewer both on the right side.
The right picture is the same as the left with exception of tracing 50 distributed shadow rays. The light has a radius of 50m. Notice the harsh transition of the shadow for the dodecahedron. The picture on the right has gradual change of gradiant.
References:
[1] Eric P. Lafortune, Yves D. Willems Using the Modified Phong Reflectance Model for Physically Based Rendering. Department of Computer Science, K.U Leuven. Report CW 197, November 1994,