   Sphereical Harmonics
  I keep trying to learn SH, but every time I look it up or read a paper on it, I just get lost in the mathematics, and am still quite unsure as to their purpose. From my basic understanding, its a function that you look up values in using 3d polar coordinates, but thats about as far as it goes.I get the idea that you have this sphere, and every point on the surface contains a different value. These values are then retrived based on polar coordinates. The values stored depends on what you are using SH for. So in the case of lighting, a pre-computed step would be to take some point in space and for very surface point on the unit sphere around that point you compute the radiance that point recieves and store it. But i dont know how this relates to a function, nor how you have you scene provide the data for this function.1. Is it just a function that is stored? or are values stored in some sort of look up table that the function uses? What exactly is the data stored to use SH?2. What exactly do you get back? is it a single value? or a colour? or what?3. What would be the difference in using SHs as opposed to a lookup table that has precomputed values based on position and normal?4. What about position? From my understanding, SH are computed for a fixed point in space. So will using the distance between some moving object and the SH base point produce different results, ie the radius in polar coordinates, or is it just dependant on direction ie normal?
Quote:Original post by hick181. Is it just a function that is stored? or are values stored in some sort of look up table that the function uses? What exactly is the data stored to use SH?The coefficients for a function are stored. The function is always the same, it's (simplified) an interference of spherical standing waves. You store the amplitude and possibly phase of each wave function, which are then combined. This parametrizes the global SH function up to a certain level (the order of the SH), and implicitly encodes data up to a certain frequency limit. What data you store in the SH is entirely up to you. Usually HDR colour values are stored, but it could be anything. Think of it as a heavily low-pass filtered cubemap.Quote:Original post by hick182. What exactly do you get back? is it a single value? or a colour? or what?A single floating point value. If you need an RGB colour, you need three independent coefficient sets.Quote:Original post by hick183. What would be the difference in using SHs as opposed to a lookup table that has precomputed values based on position and normal?SH don't encode position, they only encode direction. A lookup table similar to this would be a cubemap. A SH serves the same purpose (looking up a value associated with a certain direction), but the result is an approximation. The advantage is the considerably smaller memory footprint, and that SH values are easier to interpolate. It's not unlike a polynomial fitted to a set of discrete data samples.SH also have additional advantages. You can combine the effect of two SH sets in a very elegant way, opening the way to PRT (precomputed radiance transfer). This is not easily possible with cubemaps. The data you get out of SH is a very smooth low frequency signal. For certain applications (such as indirect light encoding, for example) this is an advantage over the crude bilinear interpolation of cubemap samples, as they lead to less artifacts.Quote:Original post by hick184. What about position? From my understanding, SH are computed for a fixed point in space. So will using the distance between some moving object and the SH base point produce different results, ie the radius in polar coordinates, or is it just dependant on direction ie normal?Just the normal. Position is hard. You basically have to compute a spatial grid of SH probes, and interpolate between them as you move through the grid. There is also the possibility to store signal gradients, essentially error correction values, so to make this interpolation rather precise. But this takes more memory.   ;  As an example, The US National Geospatial Intelligence Agency models the geoid using spherical harmonics.  If you can read Fortran you can even look at their code (but man is that hideous).   ;  Spherical harmonics are analogous to fourier series but on a sphere. With fourier series, as you add additional fourier terms, you can represent higher frequency signals. So it is with spherical harmonics and higher orders: as you add coefficients for higher orders, you can represent higher frequency signals. Many of the same benefits of working in frequency space apply to spherical harmonics -- you can represent a signal much more compactly, convolution is very fast, etc.   ;  Look at the pictures and images of Wikipedia's article about Fourier series, here.The pictures show that Fourier series and Spherical Harmonics are nothing more than a way to approximate any function using a sum of simpler basis functions (like sines or cosines) with diferent properties (like different frequencies and amplitudes). The accuracy of the approximation depends on the amount of simpler functions you use, the more you use the better the approximation is.To use these kind of approximations you just have to tell the amplitude of each basis function, that is, for each basis function you just have to multiply it by a real value called a coefficient. And that's why these approximations provide a compressed way to store data, because you don't have to store each single value of your original function along the whole domain, you just have to store a reduced set of coefficients that are later used to reconstruct the original function, by multiplying them with each corresponding basis functions.Spherical Harmonics are basically the same thing, but for a spherical domain instead a 2D domain, and that is way they are used to represent light reaching a point. To read from a SH, instead of sampling the function through the X coordinate like a 2D function, you sample it using a 3D vector (or polar coordinates, but 3D vectors are much more intuitive) and in return you get a single real value just like a 2D function. So to represent color, you have to maintain 3 spherical harmonics, one for each of the RGB channels.SH don't encode any information based on position, just direction. But it's possible to create several SHs for different points in space and then interpolate the SH based on positon. But that's just a trick used in games.I understand your troubles learning SHs, I've been through that myself and I really don't understand all the need for the crappy maths since the concept is not that complicated. I hope my explanation was clear and intuitive enough (although not formally correct and complete), but feel free to ask further if you need more info.   