hawksprite 124 Report post Posted January 9, 2013 So I've been trying to read up on it and I've googled around all day with no success. I just can't figure out what i'm supposed to do for FFT. I've been going off this paper: http://www.limsater.com/files/ocean.pdf But when I get to the equation for FFT there are variables like e that aren't referenced anywhere else, I have no idea what variables i'm supposed to pass to it. Any help/insight would be greatly appreciated. Thanks, Justin. 1 Share this post Link to post Share on other sites
Cornstalks 7030 Report post Posted January 9, 2013 For the Discrete-Fourier Transform [eqn]X_k = \sum \limits_{n = 0}^{N - 1} x_n e^{-i 2 \pi k {n \over N}}[/eqn] You have the following variables/values: X_{k}: An output of the DFT x_{n}: Input values for the DFT N: The number of complex numbers in x = x_{0}, ... , x_{N-1} and X = X_{0}, ... , X_{N-1} n: A summation variable, as denoted by the summation e: The mathematical constant, approximately equal to 2.71828 (sometimes called Euler's number, but don't confuse it with Euler's constant ?!) i: The imaginary unit ?: Pi k: The "index" of X for the current value being computed To take e to an imaginary power (e^{ix}), you use Euler's formula (e^{ix} = cosx + isinx) I hope you're familiar with imaginary numbers, as they're the foundation for the DFT. The FFT is a way of computing the DFT. That is, it's just an algorithm for computing the DFT in O(NlogN) time (computing the DFT by dumbly following the above equation requires O(N^{2}) complexity). 3 Share this post Link to post Share on other sites
hawksprite 124 Report post Posted January 9, 2013 Thank you so much for the explanation of the variables. It's saved me a lot of stress and bafflement. Here's 5 e dollars good sir. 1 Share this post Link to post Share on other sites
Bacterius 13165 Report post Posted January 9, 2013 You might also find those blog posts useful: http://www.keithlantz.net/2011/10/ocean-simulation-part-one-using-the-discrete-fourier-transform/ http://www.keithlantz.net/2011/11/ocean-simulation-part-two-using-the-fast-fourier-transform/ Let's just say it was a godsend when I was rendering some Tessendorf waves about a year ago. 2 Share this post Link to post Share on other sites
hawksprite 124 Report post Posted January 9, 2013 Thanks for the links i'll read through those as well. Will post my results later this evening. 0 Share this post Link to post Share on other sites
hawksprite 124 Report post Posted January 10, 2013 (edited) So I started reading up on DFT, I believe I understand a decent bit of the formula now. Allthough I stick have a good bit to go. It isn't working but this is what I have so far: public float getWaveHeight(int index) { float t = Time.deltaTime; float x_n = waveVerticeList[index].x; float N = meshLength; // Total vertice count float e = 2.71828f; float i = Mathf.Sqrt (-1.0f); float k = index; float sub = (2 * Mathf.PI) * k * N; float DFT = x_n * (Mathf.Cos (sub) + i * Mathf.Sin (sub)); Debug.Log (DFT); // Fallback return DFT; } public void runComputeShader() { for (int i = 0; i < meshLength; i++) { waveVerticeList[i].y = getWaveHeight (i); } parentMesh.vertices = waveVerticeList; //parentMesh.RecalculateNormals (); } Is it even in the right path? I'm not 100% sure what i'm doing hahaha. Edited January 10, 2013 by hawksprite 0 Share this post Link to post Share on other sites
Quat 568 Report post Posted January 10, 2013 NVIDIA DX11 SDK has a compute shader implementation (OceanCS). It follows the paper by Tessendorf. 1 Share this post Link to post Share on other sites
hawksprite 124 Report post Posted January 10, 2013 NVIDIA DX11 SDK has a compute shader implementation (OceanCS). It follows the paper by Tessendorf. I've been reading through that SDK and a few other tutorials online. I think i'm making some progress but I still just don't understand the math behind it. 0 Share this post Link to post Share on other sites
Quat 568 Report post Posted January 11, 2013 The NVIDIA demo has source; take a look at OceanSimulator::updateDisplacementMap and ocean_simulator_cs.hlsl to see the code implementation. The basic idea is that the statistic model given defines the waves directly in the frequency space. That is, it gives the Fourier coefficients. This is the h~(k, t) in Equation 19. Once you know the Fourier coefficients, you can use the inverse FFT to recover the function in the spatial domain. The exp( i*k*x ) is just a combination of sine/cosine written in complex form at some frequency k. So equation 19 is like a "linear combination of sine/cosine waves at different frequencies, where the h~(k, t) denotes "how much" of the sine/cosine wave contributes to the overall function. I would start be deriving the Fourier series using sine/cosine for 1D function f(x). Then use Euler's formula to write it in complex form. The inverse FFT is basically a finite Fourier series. Then study how to extend it to 2D Fourier series. Check out http://freevideolectures.com/Course/2301/Computational-Science-and-Engineering-I/41 Earlier lectures also derive the Fourier series. 0 Share this post Link to post Share on other sites