I'm currently working at university on implementing Light Propagation Volumes. The paper makes extensive use of spherical harmonics while the implementation uses the first two bands.
Below is a visualization of the first 4 bands of the SH basis functions (created using Mayavi):
As you can see the first two bands are 4 functions, so 4 coefficients to store which conveniently fits into one RGBA texture.
One of the main transformations that is performed in the LPV paper is the rotation of the spherical harmonics representation of a clamped cosine lobe (that represents surface lighting) onto a normal vector direction. It took me a while to figure out, but actually it's quite easy, which is why I write about it
The analytical presentation of the first four base functions is simple:




To evaluate lighting with SH for some direction v, you first determine the coefficients/weights of the SH basis functions and then sum them up.

Let's assume we know the coefficients
of the clamped cosine lobe around the z axis, then we can determine the lighting in direction v for the cosine lobe around the normal n by transforming it into the space where the normal coincides with the z axis (ie rotate n onto the z axis):

where
is a rotation matrix that rotates n onto z.
The idea is to expand
and rewrite it in terms of
.
Before doing this, let's first take a look at the coefficients of the clamped cosine lobe:

The y and x direction are 0 because the cosine lobe is centered isotropic around the z axis:
So let's look at the expanded version of this formula if
,
,
are the row vectors of the matrix,
and
, then:


Since
and
:


Now the question is: what is the third row of
? If we look at the inverse matrix instead:
, we can immediately see that its third column has to be n, because
by construction. Since rotations are orthogonal matrices, the inverse is the same as the transposed, so we can deduce that the third row of
is the same as the third column of
, that is: n. Thus with
we get:

So the SH coefficients of the clamped cosine lobe along n are:

This is it
Cheers,
Andreas
PS: a few screenshots from the LPV project:





