I'm currently trying to implement a GI system for diffuse lighting and wanted to do so in spherical harmonics.
Now i have read what else i could find and i know the general idea of how to get from cubemap to SH coefficients but there is just one thing that is bugging me a lot.
In Peter-Pike Sloan's "Stupid Spherical Harmonics (SH) Tricks" [1] on page 9 of the pdf he gives this pseudo-code for the process:
float f[],s[];
float fWtSum=0;
Foreach(cube map face)
Foreach(texel)
float fTmp = 1 + u^2+v^2;
float fWt = 4/(sqrt(fTmp)*fTmp);
EvalSHBasis(texel,s);
f += t(texel)*fWt*s; // vector
fWtSum += fWt;
f *= 4*Pi/fWtSum; // area of sphere
The theory, "evaluate sh basis in direction of each texel center and weight by solid angle", okay thus far,
Now comes the stupid part;
what the hell is he doing? What is he taking the euclidean distance for and and what is going on with 4/(sqrt(ftmp)*ftmp) i see no trigeometry so i am not assuming he is calculating the solid angle here? I have also looked at other implementations to derive solid angle from cubemap texels and they are.. different
He further states that EvalSHBasis needs to "normalize the input coordinate (on a cube face) and simply evaluate the sh basis functions in that direction". Now what is he normalizing here? i am lost.
[1]P.-P. Sloan, “Stupid Spherical Harmonics (SH) Tricks” https://www.ppsloan.org/publications/StupidSH36.pdf