Spherical harmonics lighting interpolation

I want to use hardware filtering to smooth out colors in texels of a texture when I'm accessing texels at coordinates that are not directly at the center of the texel, the catch being that the texels store 2 bands of spherical harmonics coefficients (=4 coefficients), not RGBA intensity values.

Can I just use hardware filtering like that (GL_LINEAR with and without mip mapping) without any considerations?

In other terms: If I were to first convert the coefficients back to intensity representations, than manually interpolate between two intensities, would the resulting intensity be the same as if I interpolated between the coefficient vectors directly and then converted the interpolated result to intensities?

• I'm not totally sure, but intuitively if you're using a linear mapping from coefficients to intensity, then yes. Otherwise, probably not. – Mokosha Nov 10 '13 at 16:35

Yeah, I think this is valid and one of the big nice properties of spherical harmonics. Bilinearly or trilinearly filtering the data doesn't have any cross-channel operations so it will preserve the 4 separate sets of coefficients fine.

Basically evaluating the SPH is like this right:

for(i=0..coefficients):
result += coefficient[i] * basis[i]


So in the 1-D case if you have two results resultA and resultB them you linearly interplolte them like this:

result = lerp(resultB, resultA, t)
result = resultA * t + resultB * (1.0 - t)


If you sub this in you get:

for(i=0..coefficients):
resultA = (coefficientA[i] * basis[i])
resultB = (coefficientB[i] * basis[i])
result +=  resultA * t +  resultB * (1.0 - t)


then

for(i=0..coefficients):
result += (coefficientA[i] * basis[i]) * t + (coefficientB[i] * basis[i]) * (1.0 - t)


The the basis is constant w.r.t A vs B so you can factor it out

for(i=0..coefficients):
result += ((coefficientA[i]) * t + (coefficientB[i]) * (1.0 - t))*basis[i]


So coefficients is really

for(i=0..coefficients):
result += lerp(coefficientB[i], coefficientA[i], t)*basis[i]


Which means, yes, you can filter the coefficients texture and get the same result as filtering the result of the evaluation.

Also this implies that you can apply any constant scale or sum up sets of coefficients arbitrarily which is useful.