# How to represent a point using spherical harmonics?

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

## Recommended Posts

Hi guys!

I have a new interesting question for us today:
Given the direction to a point light source (e.g. [0 0 1]), how do we find the spherical harmonics representation of it?

Let's assume the degree of approximation is 2, i.e. there are 9 coefficients for each color channel.
Here's a link to an excellent tutorial on this topic: http://www.cs.columbia.edu/~cs4162/slides/spherical-harmonic-lighting.pdf
Unfortunately though, it does not answer my question.

Thanks and looking forward to your suggestions!

##### Share on other sites
Short answer: You can't really. Representing a point-light requires an infinite number of coefficients.

Long answer: You can approximate it using a circular shape. The paper "Algorithms for Spherical Harmonic-Lighting" By Ian G. Lisle and S.-L. Tracy Huang gives a method for calculating the coefficients for this directly.

##### Share on other sites
You'd also have to know the distance to the light.

##### Share on other sites
Short answer: You can't really. Representing a point-light requires an infinite number of coefficients. Long answer: You can approximate it using a circular shape. The paper "Algorithms for Spherical Harmonic-Lighting" By Ian G. Lisle and S.-L. Tracy Huang gives a method for calculating the coefficients for this directly.

Hey ginkgo! Well, yes - but isn't that exactly the idea behind spherical harmonics - approximating a function using a polynomial of a finite degree (e.g. degree 2 already gives an error rate less than 1%).

I have found several methods for computing the coefficients, amongst others, the original project page for irradiance computation:
Link, which provides the function prefilter.c to compute coefficients.

But the input to this function is an environment map (an image), for which the lighting is computed.

You'd also have to know the distance to the light.

Well, as I mentioned, let's take the direction vector [0 0 1], with an infinite point light source.

Further suggestions? Edited by opengl_beginner

##### Share on other sites
Short answer: You can't really. Representing a point-light requires an infinite number of coefficients. Long answer: You can approximate it using a circular shape. The paper "Algorithms for Spherical Harmonic-Lighting" By Ian G. Lisle and S.-L. Tracy Huang gives a method for calculating the coefficients for this directly.

Hey ginkgo! Well, yes - but isn't that exactly the idea behind spherical harmonics - approximating a function using a polynomial of a finite degree (e.g. degree 2 already gives an error rate less than 1%).
I have found several methods for computing the coefficients, amongst others, the original project page for irradiance computation: Link, which provides the function prefilter.c to compute coefficients.
But the input to this function is an environment map (an image), for which the lighting is computed.

You'd also have to know the distance to the light.

Well, as I mentioned, let's take the direction vector [0 0 1], with an infinite point light source.

Further suggestions? Edited by opengl_beginner

##### Share on other sites

Well, as I mentioned, let's take the direction vector [0 0 1], with an infinite point light source.
Ah ok. The confusion was because an infinite/directional and a point/omni light are different things.
The details for directional lights are contained in the Stupid SH Tricks paper in the "Analytic Models" section. Edited by Hodgman

##### Share on other sites

[quote name='opengl_beginner' timestamp='1353232912' post='5001996']
Well, as I mentioned, let's take the direction vector [0 0 1], with an infinite point light source.
Ah ok. The confusion was because an infinite/directional and a point/omni light are different things.
The details for directional lights are contained in the Stupid SH Tricks paper in the "Analytic Models" section.
[/quote]

Hey Hodgman!

Thanks a lot for the reference. I had seen the tutorial before, but never managed to notice the relevant chapter!

Directional lights are trivial to compute, you simply evaluate the SH basis functions in the given direction and scale appropriately (see Normalization section.) Spherical Light sources can be efficiently evaluated using zonal harmonics. Below is a diagram showing an example scene, we want to compute the incident radiance, a spherical function, at the receiver point P. Given a spherical light source with
center C, radius r, what is the radiance arriving at a point P d units away? The sin of the half-angle subtended by the light source is r/d, so you just need to compute a light source that subtends an appropriate part of the sphere. The ZH coefficients can be computed in closed form as a function of this angle: ? = integral ( integral (y_l, \theta, 0, 2Pi ) ,\theta, 0, a ) where a is the half-angle d subtended. See Appendix A3 ZH Coefficients for Spherical Light Source for the expressions through order 6.
[/quote]

I assume a = r/d, where d is infinite and thus a = 0.
I've looked into the Appendix for L = 1, ...., 6:

L=0: ?sqrt(?)(?1+cos(a))
L =1: 1/2 sqrt(3) sqrt(?) sin(a)2
L=2: ?1/2 * sqrt(5) * sqrt(?) * cos(a) (?1 + cos(a)) (cos(a) + 1)
L=3 ?1/8 *sqrt(7)* sqrt(?) (?1 + cos(a)) (cos(a) + 1) (5 cos(a)^2 ? 1)
L=4 ?3/8*sqrt(?)*cos(a) (?1 + cos(a)) (cos(a) + 1) (7 cos(a)2 ? 3)
L=5 ? 1/16* sqrt(11)*sqrt(?)* (?1 + cos(a)) (cos(a) + 1) (21 cos(a)4 ? 14 cos(a)2 + 1)

[/quote]

So, clearly, all coefficients will be 0 due to the term (-1 + cos(a)), which is 0 for a = 0.

Where is the flaw in my derivation?

##### Share on other sites

Hey ginkgo! Well, yes - but isn't that exactly the idea behind spherical harmonics - approximating a function using a polynomial of a finite degree (e.g. degree 2 already gives an error rate less than 1%).

Yes, you generally use spherical harmonics as a means of approximating some function defined about a sphere using a compact set of coefficients. The issue that ginkgo was alluding to has to do with the fact that spherical harmonics are essentially a frequency-space representation of a function, where lower coefficients correspond lower-frequency components of the function and the higher coefficients correspond to higher-frequency components. With your typical "punctual" light source (point light, directional light, etc.) the incoming radiance in terms of a sphere surrounding some point in space (such as the surface you're rendering) is essentially a dirac delta function. A delta function would require infinite coefficients to be represented in spherical harmonics, so it's basically impossible. You can get the best approximation for some SH order by directly projecting the direction of the delta onto the basis functions (which is mentioned in Stupid SH tricks), but if you were to display the results for 2nd-order SH you'd find that you basically end up with a big low-frequency blob oriented about the direction. This is why "area" lights that have some volume associated with them work better with SH, since they can be represented better with less coefficients. The same goes for any function defined about a sphere, for instance a BRDF or an NDF. Edited by MJP

##### Share on other sites
MJP's explanation is exactly right. It would be much easier to develop some intuition for this using Fourier series to approximate a delta function.

"Projecting the direction of the delta onto the basis functions" is the same thing as evaluating the basis functions at the point where the delta is centered, so in the case of Fourier series, you just get cos(x) + cos(2x) + cos(3x) + cos(4x) + ... as an approximation to the delta function centered at 0.

You can see it here expanded up to cos(10x): http://fooplot.com/plot/k49yaatz5z

I expect the equivalent situation in spherical harmonics will also have funny ripples that it would take many terms to make small. A delta function is just not something that can be well approximated with low-frequency functions.

##### Share on other sites

I expect the equivalent situation in spherical harmonics will also have funny ripples that it would take many terms to make small.

Indeed. The visual artifacts caused by this sort of "ringing" can actually be very severe when you're working with HDR intensities. Edited by MJP

1. 1
Rutin
26
2. 2
3. 3
4. 4
5. 5

• 9
• 13
• 19
• 14
• 9
• ### Forum Statistics

• Total Topics
632940
• Total Posts
3009328
• ### Who's Online (See full list)

There are no registered users currently online

×