Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


FFT Water Shaders


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 hawksprite   Members   -  Reputation: 124

Like
1Likes
Like

Posted 08 January 2013 - 09:20 PM

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.



Sponsor:

#2 Cornstalks   Crossbones+   -  Reputation: 6991

Like
3Likes
Like

Posted 08 January 2013 - 09:40 PM

For the Discrete-Fourier Transform

 

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


[ 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 ]

#3 hawksprite   Members   -  Reputation: 124

Like
1Likes
Like

Posted 08 January 2013 - 10:05 PM

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.



#4 Bacterius   Crossbones+   -  Reputation: 9293

Like
2Likes
Like

Posted 08 January 2013 - 10:15 PM

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.


The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#5 hawksprite   Members   -  Reputation: 124

Like
0Likes
Like

Posted 09 January 2013 - 08:51 AM

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

 

Will post my results later this evening.



#6 hawksprite   Members   -  Reputation: 124

Like
0Likes
Like

Posted 10 January 2013 - 11:59 AM

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 by hawksprite, 10 January 2013 - 11:59 AM.


#7 Quat   Members   -  Reputation: 422

Like
1Likes
Like

Posted 10 January 2013 - 02:37 PM

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


-----Quat

#8 hawksprite   Members   -  Reputation: 124

Like
0Likes
Like

Posted 10 January 2013 - 02:54 PM

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.



#9 Quat   Members   -  Reputation: 422

Like
0Likes
Like

Posted 10 January 2013 - 06:53 PM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS