View Full Version : gerstner waves

ugluk

06-01-2010, 11:21 AM

What I dislike about the Gerstner wave algorithm is that it displaces the point you want to calculate the height of the wave at. It is possible to find such a point that it will be displaced exactly into the point you want the height to be calculated in, but this is cumbersome. Otherwise, the heightmap grid needs to be irregular. What approach do you use to calc the Gerstner wave heightmap?

ugluk

06-02-2010, 04:47 AM

Well, I managed to do it... A nonlinear equation needs to be solved for every vertex in the heightmap. Is there anything obviously wrong with the image below?

screenshot (http://img7.imageshack.us/img7/676/bla1x.png)

http://img7.imageshack.us/img7/676/bla1x.png

karooolek

08-27-2010, 05:14 AM

Hi, that's exactly what i need!

Could you share this equation??

ugluk

08-30-2010, 06:52 PM

you have:

f : R^2 -> R^3

(x, y) |-> (x', y', z')

But you want to find the value of the function at a specific (x', y'), so you need to find the value (x, y) that gets displaced into (x', y'). The displacement of (x, y) is governed by:

x' = x - sum(k_i * A_i * sin(k_i * dot(x, d_i) - omega_i * t))

I set x = x' + c_0 * i + c_1 * j, where i and j are the vectors (1, 0) and (0, 1)

Then I solve the nonlinear equation

0 = c_0 * i + c_1 * j - sum(k_i * A_i * sin(k_i * dot(x, d_i) - omega_i * t))

After I get c_0 and c_1, I can calculate x and verify if it gets displaced into x'. Accuracy usually doesn't matter much.

karooolek

08-31-2010, 12:45 AM

Hi, thanks for reply.

I based my code on equation

http://http.developer.nvidia.com/GPUGems/elementLinks/013equ01.jpg

from this article (http://http.developer.nvidia.com/GPUGems/gpugems_ch01.html)

Please tell me, what exactly is k_i in your formula?

And dot(x, d_i) - how can you calculate dot product of scalar x and vector d_i? Did you mean dot((x,y), d_i)?

ugluk

08-31-2010, 07:23 AM

I was writing the reply quickly, as my wireless is unreliable. Variable x is both a scalar and a vector in my reply, as a scalar, it is a coordinate, as a vector, it equals _x_ = (x, y). I can't denote vectors and scalars differently in these forums.

The equation above is from the NVidia gpugems article, yeah. The only difference is the Q_i constant and a phase shift. I used the tessendorf article for my equation.

k_i is the wave constant, 2 * pi / lambda_i, probably w_i, in the NVidia article.

Actually, I now see an error in my reply:

x' = x - sum(k_i * A_i * sin(k_i * dot(x, d_i) - omega_i * t))

should be

x' = x - sum(d_i * A_i * sin(k_i * dot(x, d_i) - omega_i * t))

so you need to solve:

0 = c_0 * i + c_1 * j - sum(d_i * A_i * sin(k_i * dot(x, d_i) - omega_i * t))

Don't forget to substitute x = x' + c_0 * i + c_1 * j in the above equation. Also the equation is a vector equation, the 0 on the left side is the zero vector. You can make a system of 2 nonlinear equations out of this equation. I'm sorry for the inconvenience.

Even though I've managed to solve the problem, I suggest you consider either IFFT or statistical waves. There's no nonlinear equation solving necessary for those methods.

karooolek

08-31-2010, 12:13 PM

thank you very much ;]

i hope this will help me a lot ;]

ugluk

08-31-2010, 02:30 PM

Just use some minimization algorithm (I use the taxi-cab method) or Newton-Rhapson for the root finding.

Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.