# Projecting cube map on spherical harmonics

This topic is 619 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello guys!

I am having hard time trying to understand the subject.

Sir Sloan in his Stupid Spherical Harmonics (Projection from Cube Maps section) provides pseudo-code for the implementation.
1.He mentions that the result has to be normalized and I do not really understand what he means here (4*PI/fWtSum multiplier).
2.Should not multiplication on the solid angle of the projected cube map texel on the unit sphere be sufficient?

Also, I found another implementation for the procedure in the Physically Based Rendering book by Matt Pharr.
The authors expand more on how solid angle on the unit sphere is related to the texel area in the cube map using formula
dW = dA / (x*x + y*y + 1)^(3/2).

Their implementation looks the following way
Vector w(u, v, 1.0f);
float dA = 1.0f / powf(Dot(w, w), 3.0f / 2.0f);
coeffs[k] += texelColor * Ylm[k] * dA * (4.0f * resolution * resolution);

3.Still I cannot buy how they calculate dA (texel area) in the code snippet. Is it really texel area (if to believe their original notations).
It looks like dA is in fact solid angle dW.
4.Again, I do not really understand the role of multiplier (4.0f * resolution * resolution).

I would be very appreciative if you could provide some insights into the derivation behind the integration process.

Thanks!
Edited by _void_

##### Share on other sites

Hey,

The reason you need to normalize is because the sum of the weights (fWtSum) will probably not be exactly 4pi, like it should be (possibly due to inaccuracies in the equation used to calculate the weight). Multiplying the result by 4pi/fWtSum makes sure that your SH does not have more or less energy than it should.

The implementation you present from "physically based rendering" looks incorrect to me, so going with Stupid Spherical Harmonics,

 1. float f[],s[];
2. float fWtSum = 0;
3. Foreach(cube map face)
4.   Foreach(texel)
5.     float fTmp = 1 + u^2 + v^2;
6.     float fWt = 4 / (sqrt(fTmp) * fTmp);
7.     EvalSHBasis(texel, s);
8.     f += t(texel) * fWt * s; // vector
9.     fWtSum += fWt;
10. f *= 4 * Pi / fWtSum; // area of sphere

On line 6, the weight of the texel is calculated, this is an approximation of it's solid angle, but not entirely accurate. On line 8, each sample/texel is multiplied with its weight, and on line 9, the weights are summed. On line 10, the result is normalized by multiplying by 4pi and dividing by the summed weights. Since the summed weight should be equal to 4pi, multiplying by 4pi/fWtSum (which should be close to 1, since fWtSum should be close to 4pi) will correct the bias introduced by the inaccuracies in the calculated solid angles.

Good luck.

Edited by fries

##### Share on other sites

fries,

Now it is clear. Thanks for great explanation!

Edited by _void_

##### Share on other sites

Hey,

The reason you need to normalize is because the sum of the weights (fWtSum) will probably not be exactly 4pi, like it should be (possibly due to inaccuracies in the equation used to calculate the weight). Multiplying the result by 4pi/fWtSum makes sure that your SH does not have more or less energy than it should.

I don't think that's correct. The reason for the normalization is that the spherical harmonics are themselves normalized (at least in Sloan's formulation) so that the integral over the sphere is 1, so to represent your spherical data (cube map) in the basis you need to compensate with a 4pi factor. Without the 4pi, when you reconstruct the SH data, it will be off by a factor of 4pi. fWtSum contains approximately another 4pi factor, since the integration is occurring over a spherical domain. So you are dividing by the total weight of your samples, then multiplying by exactly 4pi to normalize the basis function coefficients.

##### Share on other sites
Apart from some detail about why the weights need to sum to 4pi, you've said the same thing that I have. Edited by fries

1. 1
Rutin
24
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 9
• 46
• 41
• 23
• 13
• ### Forum Statistics

• Total Topics
631749
• Total Posts
3002032
×