If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

07Dec2006, 20:37  #1 
Junior Member
Join Date: May 2004
Location: Sony Cambridge, UK
Posts: 39

Can anyone explain spherical harmonics to an artist?
Hey guys, the title pretty much sums up what I'd like to ask here. Basically I'm a CG games artist with an interest in technical areas and for quite a while now I've never been able to get my head around what spherical harmonics are and what they are used for in game engines. The only real information I've been able to dig up is very maths heavy and unfortunately most of it goes over my head.
I understand the principles but not necessarily all the code of most rendering techniques like ambient occlusion and global illumination but my understanding of spherical harmonics is very vague. It seems like its a way of precomputing the diffuse component of global illumination of scene elements when lit with a hemisphere sky light but I have no idea what is precomputed and what information is stored and then reused to render at real time. If anyone could explain any of the concepts to me without resorting to the pure maths implementation then I would very much appreciate it. Thanks 
07Dec2006, 21:40  #2 
Member
Join Date: Mar 2004
Location: SoCal
Posts: 287

Well, since no one has yet volunteered, I guess I could give it a shot...
Let's try an analogy. Imagine sound. Sound (music, voice, etc.) can be described from an abstracted point of view as a graph of air pressure (or velocity) vs time. The graph (sound signal) can have pretty much arbitrary shape, but can be described (approximated) by the sum of all the constituent frequencies (with various weights and phases, ie the Fourier transform/decomposition of the signal). In pure math terms, it is like approximating a function using Taylor series or Fourier series or some other series basis. The spherical harmonics are a basis for doing the same thing in two angular dimensions (and one radial dimension). They are a basis of orthogonal/independent functions out of which one can describe an arbitrary angular/radial function as a series of weighted harmonics, for instance the angular distribution of the brighness of a light source. Anyway, this was all from my distant memory, so others please correct my mistakes. Hope this was what you were asking. ERK Pictures of what the shapes look like. 
08Dec2006, 12:21  #3 
Member
Join Date: May 2005
Location: Sweden
Posts: 165

Instead of describing all of space as a cartesian coordinate system with 3 dimensions(x y z) you can use 2 angles( theta and phi ) and a radius(r); this is called spherical coordinates.
If you drop the radius r, the angle pair will give you the coordinates on a sphere(think latitude and longitude). Spherical harmonics are functions defined on a sphere. What it means when functions are ortogonal is something you need to understand to know what spherical harmonics are for. When the scalar product of two vectors is 0 the vectors are said to be orthogonal and they are perpendicular. The regular cartesian coordinate system has 3 normalized mutually ortogonal vectors, usually given the names i, j and k. These 3 vectors are said to span the entire space; I can express any vector r as a linear sum: r = xi + yj + zk, where x y and z are scalars. When you have a coordinate space you usually suppress the reference to i, j and k and simply give x y and z as coordinates: r = (x, y, z). The i, j and k vectors are implicit. In a cartesian coordinate system we can express a scalar(dot) product as the sum of the products of corresponding components: ( x1, y1 ,z1) * (x2, y2, z2 ) = x1*x2 + y1*y2 + z1*z2. The scalar product can be extended to functions. A function f(x) takes any x for which it is defined. For any normal function you'll have some continous range of allowed x values. Since it is continous we can pick an infinite number of different x values. A function is therefor kind of like a vector, with an infinte amount of components. Each x value behaves as a basis vector with f(x) as the coordinate. If we known f(x) for any x we know the full behaviour of the function f. Any function of the type f(x) is fully described by it's 'coordinates' in this infinite dimensional space, wheter it be sin(x) or sqrt(x) or anything we can imagine that is welldefined on our interval of choice on the real axis. As our scalar product for functions('coordinates') one the real axis('basis') we can choose something analogous to the scalar product in cartesian space. Namely we integrate the product of two functions. For each value of x('basis vector') we add f(x) * g(x) to our sum, and we sum over all possible values for x. This would tend to infinity so we have to mutliply by the infinitesimal 'dx' value. I.e. it becomes an integration. Two functions are said to be ortogonal on an interval(e.g. x is between 0 and 2pi) if the scalar product defined above, is 0. These functions are 'perpendicular' if you will. If you find an infinite set of such mutually ortogonal functions, they will also span all space; instead of defining a function in terms of x on the interval [0,2pi] we can define a function in any other basis, such as the set of functions sin(2*pi*n*x) and cos(2*pi*n*x) for integer n. Here sin(2*pi*1142*x) is a 'basis vector' in the same sense that x = 1.234135134 is a basis vector. f then becomes c0 + c1 * sin(2*pi*1*x) + d1cos(2*pi*1*x)+ c2*sin(2*pi*2*x) ... where the coordinates of our function are the parameters cn. Now for finding these coefficients for a function of x. Since we know a function of x can be expressed as a linear sum of our new basis functions, and we now our new basis functions are ortogonal, we can take the scalar product of a basis function and the function who's coefficients we want. In the same way as multiplying (7,8,9) with (0,0,1) gives us the zcomponent, 9, we can get the coefficient for our basis function from a scalar product.(up to some constant that we determine by taking the scalar product of the basis function with itself). To help visualise it: We know we can express f(x) in terms of our basis as f(x) = c0 + c1 * sin(2*pi*1*x) + d1cos(2*pi*1*x)+ c2*sin(2*pi*2*x) ... If we take the scalar product of f(x) this means integrating over the product of f(x) with our basis function. This is a sum of products and we can, we can rewrite it as a sum of integrals, one for each product. But since these basis functions are ortogonal all integrals except one will evaluate to 0; namely , if our basis function is sin(2*pi*n*x) only the integral over cn * sin(2*pi*n*x) * sin(2*pi*n*x) will amount to anything but 0. Evaluating the integral f(x)*sin(2*pi*n*x) therefor gives us cn's value directly up to a constant. With this little trick we can get at all the coefficients by integrating with each basis function in turn. This is the essence of fourier analysis, where a function of time is expressed in terms of angular velocity or frequency. (an interesting result of fourier analysis, that is very zenlike: A single blip on the spacial(x) axis corresponds to all frequencies in equal amounts in frequency space. In quantum physics we can relate pairs of properties as being each other's fourier transform. Position and momentum is related via a fourier transform, therefor, if we know exactly a particles position it's momentum could be anything at all and vice versa. The more frequencies we use, the more exactly we can localize the a wave in space, and the less precisely it will be located in frequency; this is the essence of heisenbergs uncertainty principle.) Spherical harmonics then, are ortogonal functions on the surface of a sphere. We can express any arbitrary function that is defined on the surface of a sphere as a sum of spherical harmonics. This is very useful for such functions as diffuse lighting incident on an object from the scene, precomputed radiance transfer or as a solution for the angular components of electronic orbitals in hydrogen etc. Given a cube map you can transform it into spherical harmonic lighting components and vice versa analogous to fourier transforms with sinusoidal basis functions.
__________________
"A lot of those lobbyists genuinely like people. But then, fleas like people too." 
10Dec2006, 01:35  #4 
Junior Member
Join Date: Apr 2006
Location: Behind you
Posts: 85

http://en.wikipedia.org/wiki/Spherical_harmonics
Ignore the maths... You can express any point in the sphere surface with the vector between the sphere centre and that point. Just see the animated GIF on the right. The white color on the spheres mean where a vector points. The idea is to decompose any point in the sphere in the same manner you do this with simple numbers: 10 = 1 + 2 + 7 So you decompose the sphere in a set of basis vectors, then adding/subtrating/multiplying those vectors you can get any poin in the sphere surface.. .Something like: point in sphere = level1Vector*weight1 + level2Vector*weight2 + .... + levelVectorN*weightN hope that helps 
10Dec2006, 02:12  #5 
Meh
Join Date: Mar 2004
Location: New York
Posts: 10,069

I feel stupid
__________________
What the deuce!? 
10Dec2006, 07:25  #6 
Senior Member
Join Date: Mar 2002
Posts: 3,897

Hi Matt_B,
It's actually a lot simpler than these guys are making it out to be. The best way is to look at it from a linear system point of view. Imagine a black box B that takes input x and gives output y: y = B(x) In our case, B will take the environmental lighting hitting an object as input and output the shadowing an object has. Now suppose you know the following from precomputation: y1 = B(x1) y2 = B(x2) Light is a linear system, and linear systems have the following key property for any numbers a and b (which I will later call coefficients): B(a*x1 + b*x2) = a*y1 + b*y2 Make sense? Basically, a linear combination of the inputs gives a linear combination of the outputs. How does spherical harmonics fit in? Imagine running your model through a radiosity renderer in 3DSMax (or whatever) with each of the following lighting environments: You could save each lighting result in a separate texture. Now there are two keys that make spherical harmonics special: A) You can estimate any lighting environment using a linear combination of these environments. B) Rotating the environment only requires some operations on the coefficients. A) is important because it means you use the same coefficients to recombine the outputs, and voila, you have your final lighting. B) is important because in our 3D world, things rotate! If you have 1000 objects in your scene, you have to figure out the coefficients of the lighting environment for each object from it's own rotated point of view of the world, which would take a long time. Fortunately, B) allows us to figure out the coefficients for only one orientation of the current lighting (which is sort of time consuming), and then do this relatively simple calculation for each object. EDIT: I glossed over some details, but hopefully this gives you the basic idea for now. EDIT2: Fixed the linear function property. 
10Dec2006, 22:50  #7 
Junior Member
Join Date: Aug 2004
Posts: 34


11Dec2006, 09:40  #8 
Junior Member
Join Date: May 2004
Location: Sony Cambridge, UK
Posts: 39

excellent, thanks for all the replies, looks like there's a lot of material for me to get my teeth into. I've done a quick skim through and a lot of the complicated stuff didn't click with me but I'm going to have a proper thorough read through in a bit and then hopefully come back with some more questions.

Thread Tools  
Display Modes  

