10/20/2011
There are many, many complicated equations in Tessenforf's paper. The first time when I read it, it appeared math-intense. However, most of them are not directly related to building the height field for waves, but are important oceangraphic concept, such as Gerstner Wave. Here, I will try to illustrate it in an as simple as possible way and will only discuss several key equations that's directly related to implementing this algorithm.
This algorithm is based on a statistical model, in which wave height is a random variable of horizontal position and time, h( X,t). It decomposes the wave height field into a set of sinus waves with different amplitudes and phases. The model itself provides us with a method to generate these amplitudes and phases, and we use inverse FFT as a mean to quickly evaluate the sum of these sinus waves.
First, let's take a look at the equation of which we need to perform FFT to evaluate the sum:
We now want to generate a set of time-dependent amplitude and phase with Phillips spectrum. To do that, we first need to create a set of amplitudes and phases at time zero, and then we animate the field. The following equation will finish the first task.
Now, we have a set animated amplitudes and phases to which we can perform FFT to evaluate the sum. We can also perform FFT to other equations to producing the choppy vectors as well as slope vectors of the height field, but they are not discussed here.
The computational cost of performing FFT with dimensions of 512x512 is extremely high on CPU. Therefore I implemented it on the pixel shader on the GPU, the parallel computing ability of which vastly enhances the efficiency of this algorithm, and enable it to run in real-time.
FFT is a delicate algorithm. The basic idea can be illustrated by the figure below:
My implementation is simply to first pre-compute all the indices and weights(W) in the figures above and pack the pre-computed data into a texture. At each stage, these indices and weights are fetched in the pixel shader and used to perform a single butterfly operation. Two Ping-Pong textures are used to write data back and forth between stages. The following is the HLSL code for a basic butterfly operation along the horizontal direction.
oceanmesh1.obj |
can i get the program?
Nice article. I got to the point where I've calculated H(k,t)~. Is it correct that during the real time update I see concentric circles radially leaving the center of the image ? ...
Wonderful! This really cleared up a lot of small -yet complicated- things up for me. After reading Tessendorf's paper, Keith Lantz' implementation, and Eric Bruneton's gpu fft code, this gave me the spark I needed!
Has anyone an example how the pre-computed butterfly texture should look like? Would be really nice, cause i think that is the problem in my implementation.
Thx for this explanation. It helped me a lot to understand how this works. But there is one thing, I still don't understand. As far as I know, additions of complex numbers can't be performed if the complex numbers are given in polar coordinates. So what would I have to do to calculate the following equation?
~h(k,t) = ~h0(k) exp(iwt) + ~H0*(-k) exp(-iwt)
just complex multiply ~h0(k) with exp(iwt) and ~h0*(-k) with exp(-iwt) (note: exp(ix) = cos(x) + isin(x)). then complex add the results, thats all.
Nice article!
But i guess you misuse the term "gravitational constant" which is equal to 6.674e−11 and is notated by Big "G". It should not be confused with "small g" (g), which is the local gravitational field of Earth equal to approx. 9.81
10/20/2011
There are many, many complicated equations in Tessenforf's paper. The first time when I read it, it appeared math-intense. However, most of them are not directly related to building the height field for waves, but are important oceangraphic concept, such as Gerstner Wave. Here, I will try to illustrate it in an as simple as possible way and will only discuss several key equations that's directly related to implementing this algorithm.
This algorithm is based on a statistical model, in which wave height is a random variable of horizontal position and time, h( X,t). It decomposes the wave height field into a set of sinus waves with different amplitudes and phases. The model itself provides us with a method to generate these amplitudes and phases, and we use inverse FFT as a mean to quickly evaluate the sum of these sinus waves.
First, let's take a look at the equation of which we need to perform FFT to evaluate the sum:
We now want to generate a set of time-dependent amplitude and phase with Phillips spectrum. To do that, we first need to create a set of amplitudes and phases at time zero, and then we animate the field. The following equation will finish the first task.
Now, we have a set animated amplitudes and phases to which we can perform FFT to evaluate the sum. We can also perform FFT to other equations to producing the choppy vectors as well as slope vectors of the height field, but they are not discussed here.
The computational cost of performing FFT with dimensions of 512x512 is extremely high on CPU. Therefore I implemented it on the pixel shader on the GPU, the parallel computing ability of which vastly enhances the efficiency of this algorithm, and enable it to run in real-time.
FFT is a delicate algorithm. The basic idea can be illustrated by the figure below:
My implementation is simply to first pre-compute all the indices and weights(W) in the figures above and pack the pre-computed data into a texture. At each stage, these indices and weights are fetched in the pixel shader and used to perform a single butterfly operation. Two Ping-Pong textures are used to write data back and forth between stages. The following is the HLSL code for a basic butterfly operation along the horizontal direction.
oceanmesh1.obj |
can i get the program?
Nice article. I got to the point where I've calculated H(k,t)~. Is it correct that during the real time update I see concentric circles radially leaving the center of the image ? ...
Wonderful! This really cleared up a lot of small -yet complicated- things up for me. After reading Tessendorf's paper, Keith Lantz' implementation, and Eric Bruneton's gpu fft code, this gave me the spark I needed!
Has anyone an example how the pre-computed butterfly texture should look like? Would be really nice, cause i think that is the problem in my implementation.
Thx for this explanation. It helped me a lot to understand how this works. But there is one thing, I still don't understand. As far as I know, additions of complex numbers can't be performed if the complex numbers are given in polar coordinates. So what would I have to do to calculate the following equation?
~h(k,t) = ~h0(k) exp(iwt) + ~H0*(-k) exp(-iwt)
just complex multiply ~h0(k) with exp(iwt) and ~h0*(-k) with exp(-iwt) (note: exp(ix) = cos(x) + isin(x)). then complex add the results, thats all.
Nice article!
But i guess you misuse the term "gravitational constant" which is equal to 6.674e−11 and is notated by Big "G". It should not be confused with "small g" (g), which is the local gravitational field of Earth equal to approx. 9.81