vec2 xz = vec2(0.0,0.0);
float y = 0.0;
for (int D = 10; D < 30; D+=2.0) // wavelength
{
float A = 0.9; // amplitude
float k = 2*3.1415/D; // k length
float K = vec2(0.5,0.5)*k; // k
float w = sqrt(9.82*k); // frequency
float w0 = 2*3.14/10.0;
w = ceil(w/w0)*w0;
xz += K/k*A*sin(K*WorldPos.xz-w*Time);
y += A*cos(K*WorldPos.xz-w*Time);
}
WorldPos.xz = WorldPos.xz - xz;
WorldPos.y = y;
🔒 Locked
Gerstner waves help
Advertisement
Original Post
im tryin to implement grestner waves as explain in "Simulating Ocean Waves", Tessendorf in my vertex shader... but it doesnt work 2 well i get very visible waves in x direction and almost none in z direction even though im using 05,05 as the direction vector... and even if i use an amplitude of 0.9 i get rolls on the top of the waves even if i according the papar shouldnt get rolls below 1.0 amplitude.. [Edited by - Dragon_Strike on January 1, 2007 11:59:30 AM]
since im lardy on the topic.. ive also looked at the fft waves... but the equation doenst make sense to me
h(x,t) = sum ( h(k,t) exp(ik * x) )
this wont give a wave form but only an expontitial form that increase with each x.. how can one use this for waves.. and also what does "i" mean?
h(x,t) = sum ( h(k,t) exp(ik * x) )
this wont give a wave form but only an expontitial form that increase with each x.. how can one use this for waves.. and also what does "i" mean?
I assume since you're talking about FFT's, this 'i' is the 'i' in Complex Numbers. ie. i = sqrt(-1)
:)
:)
Quote:
Original post by FReY
I assume since you're talking about FFT's, this 'i' is the 'i' in Complex Numbers. ie. i = sqrt(-1)
:)
thx... but how can i use sqrt(-1) in aprogram.. wouldnt that just give an error?
and also back to the other question how can a e^x equation generate waves? ive been readin around on the net but i stil ldont quite get.. ill do some more readin meanwhile..
Quote:
Original post by Dragon_Strike Quote:
Original post by FReY
I assume since you're talking about FFT's, this 'i' is the 'i' in Complex Numbers. ie. i = sqrt(-1)
:)
thx... but how can i use sqrt(-1) in aprogram.. wouldnt that just give an error?
and also back to the other question how can a e^x equation generate waves? ive been readin around on the net but i stil ldont quite get.. ill do some more readin meanwhile..
You need to do some reading about complex numbers. The square root of -1 is a complex number, and is defined to be 'i'. You can think of complex numbers as 2d vectors, where the simple (x) coordinate is on the regular number line you learned about in school, and the complex (y) coordinate is on an 'imaginary' number line. Hence the use of the letter i for imaginary.
The exponential equation doesn't generate waves in itself. You need to understand the concept of the fast fourier transform. Basically an fft reduces any function to a sequence of sin waves of different frequencies. The useful thing about this is that the result (what we call the function in 'frequency space') shows you information about the different frequencies present in that function.
The tessendorf wave function is defined in frequency space (it's based on a frequency analysis of real video footage of deep water waves). The exponential function is the distribution of frequencies of waves. You fill a big square image with that function, then transform (with the fftw library probably) that frequency image back to 'simple' space using the inverse fft. The result of transformation should look like a heightmap for waves if you've done everything correctly.
ok.. thx... im tryin to write a shader that will do this in real time... here is what i got.. heklp me out a bit?
its based on tessendorf's paper
its based on tessendorf's paper
float h(vec2 x, float Time){ float D = 10.0; // wavelength float k = 2*PI/D; // K length vec2 K = 2*PI*WorldPos.xz*1.0/vec2(Size,Size) * k; // Size = mapsize, worldpos = x,z position (unsure about Lx,Lz and n,m ???) float h = h1(K,Time) * exp(sqrt(-1)*K*WorldPos.xz)}float h1(vec2 K, Time){ float w = sqrt(9.18*length(K)); return h0(K)*exp(sqrt(-1)*w*Time) + h0(-K)*exp(-sqrt(-1)*w*Time);}float h0(vec2){ float random1 = texture2D(perlinnoise, randomcoord1).a; // gaussian noisemap float random2 = texture2D(perlinnoise, randomcoord2).a; return 1/sqrt(2)*(random1 + sqrt(-1)*random2)*sqrt(Ph(K));}float Ph(vec2 K){ float a = 1.0; // amplitude vec2 w = vec2(1.0,0.0); // winddirection float v = 1.0; / windspeed float L = v*v/9.18; return a*exp(-1/pow(K*L,2))/pow(K,4)*dot(normalize(K), w); }
If you want to do the whole thing in realtime you'll need to calculate the inverse fft on the gpu. Not sure if this is possible, but maybe you should check out gpgpu.org to see if someone's already done it
You cannot simply substitute sqrt(-1) in for i. Complex numbers have different results to real numbers under various operations such as multiplication and addition. That's the *whole point* of complex numbers.
There's no way around this, I'm afraid you'll have to do some reading up on complex numbers here.
There's no way around this, I'm afraid you'll have to do some reading up on complex numbers here.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement