# Spherical Harmonics Rotation

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

## Recommended Posts

How am I supposed to rotate 3 bands of spherical harmonics (9 coefficients) into tangent space?
Are there any good papers on that topic, or any code already written, since mine won't differ from the conventional way anyway.

##### Share on other sites
You usually don't have to. If you just want to get diffuse lighting, evaluate the polynomial the SH coordinates represent at the normal vector.

##### Share on other sites
I know... But in my case I have to... I have to multiplicate them with other coefficients that are in tangent space (e.g. PRT).

##### Share on other sites
The SH rotation gritty details paper has a good section on how to do this.

Also, look up "Stupid SH Tricks"

##### Share on other sites
Ok, but what kind of Rotation will I need to rotate them into Tangent Space. ZYZ, ZXZ or ZYX (Yaw, Pitch, Roll)?

I guess it's depending on how I calculate alpha, beta and gamma... And how do I calculate them?

##### Share on other sites
The best and most robust implementation of SH rotations I've found has been in the paper "Algorithms for Spherical Harmonic Lighting" by Ian Lisle and Tracy Huang.

-= Dave

##### Share on other sites
I solved it... I just rotated about Theta (Y) and Phi (Z). And now it's working perfectly fine.

Edit: Well. Or not.

Am I right that I don't need the Binormals nor the Tangents for the rotation into the tangent space, when I'm only using unshadowed radiance transfer?

And most importantly how can a scalar product over 2 pairs of 9 coefficients be the same as the integral? Let's just take a look at (1,-1). It's part of the linear band meaning that it describes if the axis it's describing is more positive or negative. Let's just say it's describing the x axis. If we take unshadowed radiance transfer, we need to parameterize the lighting and max(0, cos(theta)). Since the cosine is neither more right nor more left, the final coefficient will be 0. In fact, it will be non-zero on all (L,0) coefficients. It basically just says that it always blocks off all incident light the same independent of the x-axis. So if the actual incident light is stronger from the right, it will result in an coefficient being non-zero. Now if we multiply those together (since the integral is the same as the scalar product), we get zero since x * 0 = 0. But that's just not correct. There is more incident light from the right, than from the left.

[Edited by - DarkChris on November 16, 2010 12:02:54 PM]

##### Share on other sites
Quote:
 Original post by DarkChrisAnd most importantly how can a scalar product over 2 pairs of 9 coefficients be the same as the integral?

The integral disappears because of the orthonormal nature of the basis. As you may know from linear algebra the dot product of two vector's in an orthonormal basis are 1 when they are the same and 0 when they are not. In a functional basis the integral of the same basis is 1 when they are the same and 0 when they are different. A functional basis has infinite components and an integral is essentially a dot product. More generally, in a functional basis we call it the inner product.

Let's start off with the integral of two functions parameterized over the hemisphere (theta and phi).
$\int_{\Omega}A(\theta, \phi)B(\theta, \phi)d\omega$

Then we project both functions onto a spherical harmonic basis Y and reconstruct using its coefficients.
$A(\theta, \phi)=\sum_{l,m}A_{l,m}Y_{l,m}(\theta, \phi)$
$B(\theta, \phi)=\sum_{l,m}B_{l,m}Y_{l,m}(\theta, \phi)$
Now we have an alternate version of A and B so we can substitute them back into the original integral.
$\int_{\Omega}(\sum_{l,m}A_{l,m}Y_{l,m}(\theta, \phi))(\sum_{l,m}B_{l,m}Y_{l,m}(\theta, \phi))d\omega$
$=\int_{\Omega}\sum_{l,m}\sum_{l,m}A_{l,m}B_{l,m}Y_{l,m}(\theta, \phi)Y_{l,m}(\theta, \phi)d\omega$

Because of the linearality of integrals we can pull the summation outside of the integral and we can pull the constant coefficient multiplies out as well.
$=\sum_{l,m}\sum_{l,m}A_{l,m}B_{l,m}\int_{\Omega}Y_{l,m}(\theta, \phi)Y_{l,m}(\theta, \phi)d\omega$

Now the magic of orthogonality means that if Y_{l,m} != Y_{l,m} we get 0 when we integrate Y against itself. That means if l and m are not equal for both A and B we get 0. This simplifies it down to the integral.
$=\sum_{l,m}A_{l,m}B_{l,m}\int_{\Omega}Y_{l,m}(\theta, \phi)Y_{l,m}(\theta, \phi)d\omega$

Also, because $\int_{\Omega}Y_{l,m}(\theta, \phi)Y_{l,m}(\theta, \phi)d\omega=1$ because the basis are always the same we simplify the original equation down to
$=\sum_{l,m}A_{l,m}B_{l,m}*1$
$=\sum_{l,m}A_{l,m}B_{l,m}$

[Edited by - David Neubelt on November 16, 2010 4:07:27 PM]

##### Share on other sites
Quote:
 Original post by DarkChrisLet's just take a look at (1,-1). It's part of the linear band meaning that it describes if the axis it's describing is more positive or negative. Let's just say it's describing the x axis. If we take unshadowed radiance transfer, we need to parameterize the lighting and max(0, cos(theta)). Since the cosine is neither more right nor more left, the final coefficient will be 0.

No, that's not correct. Cosine has no dependence on its azimuthal angle which means it has the same coefficient no matter the angle of phi. The coefficient for 1,-1 will be same coefficient as it is for 1,0 (because phi doesn't matter!)

The first 9 coefficients of max(cosine(\theta), 0) are the following,

// constant band
A_{0, 0} = 3.141593f

// linear band
A_{1,-1} = 2.095395f
A_{1, 0} = 2.095395f
A_{1, 1} = 2.095395f

A_{2,-2} = 0.785398f
A_{2,-1} = 0.785398f
A_{2, 0} = 0.785398f
A_{2, 1} = 0.785398f
A_{2, 2} = 0.785398f

EDIT: The above is wrong and I will leave for reference.
* You do want to take those 9 coefficients and multiply them by your 9 SH coeffients.
* What I was wrong about was saying that the coefficients would be the same for a clamped cos but in fact if the coefficients had represented clamped cos(\theta) then they would be 0 for any band where m != 0 but these coefficients do not reflect a clamped cos(\theta) read my post further down for details on what the coefficients reflect.

[Edited by - David Neubelt on November 17, 2010 3:18:10 AM]

##### Share on other sites
Quote:
 Original post by DarkChrisAm I right that I don't need the Binormals nor the Tangents for the rotation into the tangent space, when I'm only using unshadowed radiance transfer?

I'm not quite sure how your rendering is setup but when I implemented PRT I never needed to rotate my lighting. The visibility and indirect lighting is implemented by simply scaling the incoming lighting.

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

• 22
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631733
• Total Posts
3001927
×