FFT Water Shaders

Started by
7 comments, last by Quat 11 years, 3 months ago

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.

Advertisement

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:

  • Xk: An output of the DFT
  • xn: Input values for the DFT
  • N: The number of complex numbers in x = x0, ... , xN-1 and X = X0, ... , XN-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 (eix), you use Euler's formula (eix = 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(N2) complexity).

[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

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.

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.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Thanks for the links i'll read through those as well.

Will post my results later this evening.

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.

NVIDIA DX11 SDK has a compute shader implementation (OceanCS). It follows the paper by Tessendorf.

-----Quat
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.

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.

-----Quat

This topic is closed to new replies.

Advertisement