» Wave Simulation
This site relies heavily on Javascript. You should enable it if you want the full experience. Learn more.

Wave Simulation

This page explains the algorithm behind grid based wave simulations.

1-Dimensional Case:

Think of a 1-d wave like this:

now the main idea is that a wave can be approximated by a row of individual points, which can just move up and downwards. seen together they will form the wave.

each point can move up- and downwards.
but after what mechanism?

this also not too difficult.

1. newton

every point has a position in y and a velocity with which it is moving up and downwards. positive velocities mean the point is moving upwards, negative downwards.

in each frame a new position is calculated by adding the velocity:

p = p_lastframe + v

now also the velocity is calculated after newtons idea. the velocity of the point can be altered by adding acceleration:

v = v_lastframe + a

so this is just the basic newton model of moving particles in space. and at the moment the points don't influence each other. they are just prepared to be accelerated up- or downwards.

the second step will be to calculate the acceleration of each point.

2. neighbours

the idea is that every point is connected to the neighbour points by springs:

and this is the amazing part: every point is just being pushed around by its neighbour via these strings. with this mechanism energy (like one oscillating point) will be transfered through the whole string system of connected points.

each point just tends to move into the middle of its neighbours so that both springs (to the left and to the right of each point) are perfectly relaxed.

it depends on the strength of the strings (and of the mass of each point) in what amount this force on each particle will influence its acceleration.

  • we need the difference between each point and its neighbours:

delta_p = (p_left - p) + (p_right - p)

        = p_left + p_right - 2*p 
  • we need to accelerate the point into this direction:

a = attack * delta_p

attack is just a global variable which decides how jittery the system is.

  • ah, and the system should slow down after a while

v = (v_lastframe + a) * slowdown

if a value for slowdown like 0.99 is chosen a point will loose 1% of its energy in each frame. (also try 0.999)

3. put all together

p = p_lastframe + v
v = (v_lastframe + a) * slowdown

=>
p = p_lastframe + (v_lastframe + a) * slowdown

a = attack * delta_p
delta_p = p_left + p_right - 2*p

delta_p is also computed with values of the last frame.
p_left means p_left_lastframe ... p means p_lastframe

=>
a = attack * (p_left + p_right - 2*p_lastframe)

p = p_lastframe + (v_lastframe + a) * slowdown
a = attack * (p_left + p_right - 2*p)

=>
p = p_lastframe + (v_lastframe + (attack * (p_left + p_right - 2*p_lastframe))) * slowdown

that's it!

a patch

a patch, which works with a 1-d spread and does exactly the stuff described above is downloadable here:

tiki-download_file.php?fileId=559wave 1d.v4p (18.35 Kb)</a>

some tricks:

  • to modulate the wave we just need a spread of values.
  • to get p_lastframe we put that spread into a framedelay.
  • because we don't want to handle the velocity in a second spread we can substitute v_lastframe:

v_lastframe = p_lastframe - p_beforelastframe (we need another framedelay)

  • to get p_left and p_right we have to shift the spread.

2-Dimensional Case:

in the 2d case everything is the same. only each point has 4 neighbours:

p = p_lastframe + (v_lastframe + (attack * (p_left + p_right + p_top + p_bottom - 4*p_lastframe))) * slowdown

a shader

some tricks:

  • it works with a texture in which every pixel stores its actual wave height = position p.
  • if we put that in a queue (texture) we get p_lastframe.
  • the neighbours can be reached be altering the texturecoordinates when doing the 2D texture lookup in the pixelshader.
  • we also use the trick to substitute v_lastframe with

v_lastframe = p_lastframe - p_beforelastframe

  • that means we need the texture of the last frame and the texture before the last frame. so the queue has to store 2 textures..

download the wave simulation:
tiki-download_file.php?fileId=578wave01.zip (6.50 Kb)</a>
tiki-download_file.php?fileId=1200wave02.zip (13.71 Kb)</a>

3-Dimensional Case

a plugin that extends this algorithm to 3 dimensions can be found in the addonpack at the downloads site.

anonymous user login

Shoutbox

~3d ago

joreg: 6 session beginner course part 2 "Deep Dive" starts January 13th: https://thenodeinstitute.org/courses/ws24-5-vvvv-beginners-part-ii/

~3d ago

joreg: 6 session beginner course part 1 "Playground" starts November 4th: https://thenodeinstitute.org/courses/ws24-5-vvvv-beginners-part-i/

~4d ago

joreg: Save the date: Oktober 17: vvvv meetup in Berlin!

~6d ago

joreg: 12 session online vvvv beginner course postponed to start November 4th: https://thenodeinstitute.org/courses/ws24-5-vvvv-beginners-class/

~17d ago

~25d ago

joreg: Webinar on October 2nd: Rhino meets Realtime with vvvv https://visualprogramming.net/blog/2024/webinar-rhino-meets-realtime-with-vvvv/

~1mth ago

joreg: Introducing: Support for latest Ultraleap hand-tracking devices: https://visualprogramming.net/blog/2024/introducing-support-for-new-ultraleap-devices/

~1mth ago

joreg: 2 day vvvv/fuse workshop in Vienna as part of NOISE festival on Sept. 13 and 14: https://www.noise.ist/vienna

~1mth ago

joreg: New beginner video tutorial: World Cities https://youtu.be/ymzrK7tZLBI

~1mth ago

catweasel: https://colour-burst.com/2023/01/26/macroscopic/ yeah, ' is there anyone who cares about slides anymore...' Well me for a start! :D