I am trying to understand the function computeColorFromSH, which is a part of the differentiable gaussian rasterizer used by the paper 3D Gaussian Splatting for Real-Time Radiance Field Rendering.

I am looking for the formula that the code is based on. Here's an excerpt for the degree > 2 part:

            result = result +
                SH_C3[0] * y * (3.0f * xx - yy) * sh[9] +
                SH_C3[1] * xy * z * sh[10] +
                SH_C3[2] * y * (4.0f * zz - xx - yy) * sh[11] +
                SH_C3[3] * z * (2.0f * zz - 3.0f * xx - 3.0f * yy) * sh[12] +
                SH_C3[4] * x * (4.0f * zz - xx - yy) * sh[13] +
                SH_C3[5] * z * (xx - yy) * sh[14] +
                SH_C3[6] * x * (xx - 3.0f * yy) * sh[15];

It seems to be some kind of polynomial. The Wikipedia article on Spherical Harmonics has only integrals, so I'm guessing that this is a special case and maybe even a well-known one.

Is anyone familiar with this? Where I can read more about it?


1 Answer 1


You can check this out (the appendix of PlenOctree, Section B.1), since the SH implementation of 3D GS is directly borrowed from PlenOctree. I can walk you through it with an example. First, take a look at the real form of SH (I won't use Latex here since, you know it's painful): enter image description here Where $P_l^{|m|}(\cdot)$ is the associative Legendre Polynomial: enter image description here

(From Wikipedia)

So where are those SH_C3? They have some thing to do with: $$ K_{lm} = \sqrt{\frac{2l+1}{4\pi}\frac{(l - |m|)!}{(l+|m|)!}} $$ Ok, so basically, we first get $\theta$ and $\phi$, as the direction $(x, y, z)$ can be easily converted to the spherical coordinates $(\theta, \phi)$. Therefore, the corresponding $\cos(\cdot), \sin(\cdot)$ values can be obtained.

Then we use the formula of associative Legendre Polynomial to get, say $m=0, l = 0$ case: $$ P_0^0=1 $$ We next evaluate SH basis function (given in the first image), for example: $Y_{00}, l=0,m=0$ will be $\sqrt{1 / 4\pi} \approx 0.282095$, which equals to SH_C0 in the code. Other coefficients can be derived similarly: substitute $l, m$ with the order you need, then evaluate the whole formula and store the constant part. With all the precomputed coefficients, now you can multiply your learned SH coefficients with these precomputed ones. Hope this will help.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.