Mmm.. spherical harmonix?
Mmm.. spherical harmonix?
I only studied spherical geometry a little and I totally dont get Spherical Harmonics at all... despite the fact I am 16 I can integrate, differentiate and poop but wikipedia and all the other sites that mention them are totally NOT HELPFUL... I heard Mel did a spherical harmonics render and I would really like to know how to calculate a spherical harmonic from a cubemap and how to read it back Most of all how the whole thing works
-
- Posts: 22
- Joined: Mon Nov 15, 2010 9:18 pm
It's a pretty complicated subject, you have to be unafraid of dealing with alot of mathematics notation to get to grips with it (and really reading it not just skipping past the maths and reading the code).
A couple of things I found helpful:
This book: http://www.amazon.com/Advanced-Lighting ... 1556222920
This paper + source code: http://www-graphics.stanford.edu/papers/envmap/
This paper: http://www.cs.columbia.edu/~cs4162/slid ... ghting.pdf
A couple of things I found helpful:
This book: http://www.amazon.com/Advanced-Lighting ... 1556222920
This paper + source code: http://www-graphics.stanford.edu/papers/envmap/
This paper: http://www.cs.columbia.edu/~cs4162/slid ... ghting.pdf
wait... does it mean that I basically have to go through the environment map, pixel by pixel.... treating them all like diffuse parameters and unprojecting the envmap texcoords as normals/lightdir then adding them to THE 9 xyz/rgb values of a 2nd order spherical harmonic?
Then render a virtual envmap on a plane mapping texcoords as normals using the all mystifying lookup function and compare results?
Then render a virtual envmap on a plane mapping texcoords as normals using the all mystifying lookup function and compare results?
-
- Posts: 22
- Joined: Mon Nov 15, 2010 9:18 pm
Something like that.... Basically its a 3D (in spherical coodinates) equivalent of Fourier transform with the le Grange Polynomials (I think, may have got that name wrong) replacing the usual trig functions.devsh wrote:wait... does it mean that I basically have to go through the environment map, pixel by pixel.... treating them all like diffuse parameters and unprojecting the envmap texcoords as normals/lightdir then adding them to THE 9 xyz/rgb values of a 2nd order spherical harmonic?
Then render a virtual envmap on a plane mapping texcoords as normals using the all mystifying lookup function and compare results?
Its not the difference between AAA and simpletons, its the difference between knowing the lingo or not knowing it
Spherical Harmonics is primarily a scientific phenomenon which uses mathematics to describe atomic properties.
Much like physics and lighting-models, a simplified application of it for games makes it seem like a simple trick in the end, even though there is a lot more to it than you might guess just by looking at it in a gaming context
Spherical Harmonics is primarily a scientific phenomenon which uses mathematics to describe atomic properties.
Much like physics and lighting-models, a simplified application of it for games makes it seem like a simple trick in the end, even though there is a lot more to it than you might guess just by looking at it in a gaming context
-
- Posts: 126
- Joined: Wed Sep 29, 2010 8:23 pm
Or describing electron cloud properties? Don't forget that one, that one's a biggie in S.H.fmx wrote:Its not the difference between AAA and simpletons, its the difference between knowing the lingo or not knowing it
Spherical Harmonics is primarily a scientific phenomenon which uses mathematics to describe atomic properties.
Much like physics and lighting-models, a simplified application of it for games makes it seem like a simple trick in the end, even though there is a lot more to it than you might guess just by looking at it in a gaming context
I am having problems with converting cube maps to SH.... help?
I also posted a topic on gamedev with some example code
http://www.gamedev.net/community/forums ... _id=589393
I also posted a topic on gamedev with some example code
http://www.gamedev.net/community/forums ... _id=589393
No, spherical harmonics are much simpler than that. They are simply functions mapped over a sphere. Just that.
The point is that these functions can be used to represent complex physical phenomena using simple numbers.
WARNING...LONG ASS EXPLANATION AHEAD.
In the case we are dealing with, the physical phenomenom to be described is the irradiance of a given point.
The irradiance is the amount of light that comes to a certain point. And it is complex to sample every point in space, and keep a trace of all of them to transform all those sample in complex formulae. But it was found that this problem could be much easier if the irradiance was represented as the sumatory of these spherical harmonics functions.
Same as using a Fourier transform to recreate a sound wave, these functions can be used to recreate a function over a sphere. Hence their name "harmonic" and "spherical", and the irradiance is a function over a sphere in its definition.
There are many spherical harmonics functions. a constant, X, Y, Z, (X^2-Y^2),.... And they have what it is called "order". This "order" is the maximum exponent an spherical harmonic function has. A constant has order 0, X, Y and Z have order 1, or are of first order,( XX-YY) has order 2 or it is of second order, and so on, in the functions that are spherical harmonics. Not all functions are.
It was then found that with a sumatory of these functions and their respective coeficients up to the second order was enough to represent the irradiance at a given point with an average error below 3% over the original calculations. And these calculations only needed 9 coeficients, which corresponded to the spherical harmonics functions up to the second order.
Giving values to these fuctions (the coeficients c1-c9), and adding up all of them gives us a polynomical function.
Giving values to X, Y and Z (a 3d normalized vector) gives us the value of this function, which is that of the point in the "sphere" where that vector is pointing at.
Spherical harmonics are a form of representation, and can be seen as a vectorial space basis. The coeficients of these equations are 9-dimensional vectors.
Representing the incoming light in the form of SH becomes a matter of inverting the process. We have 9 coeficients to determine, and we have as input a vector and a light intensity.
Lets call the normalized vector XYZ and the intensity I.
Then, directly, without explanations...
Then, also, in the problem we have at hand, apply another constants that were found so the problem mapped exactly to the irradiance. These constans are 5:
And the irradiance function becomes this.
I hope this throws in a bit of knowledge of these odd 9-dimensional dudes...
The point is that these functions can be used to represent complex physical phenomena using simple numbers.
WARNING...LONG ASS EXPLANATION AHEAD.
In the case we are dealing with, the physical phenomenom to be described is the irradiance of a given point.
The irradiance is the amount of light that comes to a certain point. And it is complex to sample every point in space, and keep a trace of all of them to transform all those sample in complex formulae. But it was found that this problem could be much easier if the irradiance was represented as the sumatory of these spherical harmonics functions.
Same as using a Fourier transform to recreate a sound wave, these functions can be used to recreate a function over a sphere. Hence their name "harmonic" and "spherical", and the irradiance is a function over a sphere in its definition.
There are many spherical harmonics functions. a constant, X, Y, Z, (X^2-Y^2),.... And they have what it is called "order". This "order" is the maximum exponent an spherical harmonic function has. A constant has order 0, X, Y and Z have order 1, or are of first order,( XX-YY) has order 2 or it is of second order, and so on, in the functions that are spherical harmonics. Not all functions are.
It was then found that with a sumatory of these functions and their respective coeficients up to the second order was enough to represent the irradiance at a given point with an average error below 3% over the original calculations. And these calculations only needed 9 coeficients, which corresponded to the spherical harmonics functions up to the second order.
Code: Select all
order 0: a Constant:
-----------------------
order 1: maximum exponent = 1
y:
z:
x:
-----------------------
order2: maximum exponent = 2
xy:
yz:
xz:
3zz-1:
xx-yy:
-----------------------
Code: Select all
c1 + c2y +c3z +c4x + c5(xy) + c6(yz) + c7(xz) +c8(3zz-1) + c9(xx-yy)
Spherical harmonics are a form of representation, and can be seen as a vectorial space basis. The coeficients of these equations are 9-dimensional vectors.
Representing the incoming light in the form of SH becomes a matter of inverting the process. We have 9 coeficients to determine, and we have as input a vector and a light intensity.
Lets call the normalized vector XYZ and the intensity I.
Then, directly, without explanations...
Code: Select all
c1 = I
c2 = YI
c3 = ZI
c4 = XI
c5 = XYI
c6 = YZI
c7 = XZI
c8 = (3ZZ-1)I
c9 = (XX-YY)I
Code: Select all
k1=0.429043;
k2=0.511664;
k3=0.743125;
k4=0.886227;
k5=0.247708;
Code: Select all
k4c1 + k2c2(y) + k2c3(z) + k2c4(x) + k1c5(xy) + k1c6(yz) + k1c7(xz) + k3c8(3zz-1) - k1c9(xx-yy) = I;
Last edited by Mel on Mon Dec 06, 2010 11:48 am, edited 1 time in total.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt