1D Height Field Fluid

This is a 1D implementaion of Matthias Müllers Height Field Fluid algorithm presented at the Games Developers Conference 2008. It is based on the 2D wave equation $$ u_{tt}=c^2\nabla^2u $$ in form of a partial differential equation of second order. \( u_{tt}=c^2u_{xx} \) for the 1D case.
In short, the algorithm steps are based on particle calculations in respect to Newtons second law of motion \( a=f/m \)
                
                    LOOP
                        compute force
                        velocity += force/mass * time step
                        position += velocity * time step
                    ENDLOOP
                
            
which translates to the actual program code
                
                    FORALL i
                        f = c^2*(u[i-1] + u[i+1] – 2u[i])/h^2
                        v[i] = v[i] + f*dt
                        u_new[i] = u[i] + v[i]*dt
                    ENDFOR
                    u = u_new
                 
             
This implementaion uses WebGL and was built with the help of webglfundamentals.org. Feel free to change the parameters.

Parameters

    

(wave velocity, condition: c < h/dt)
(wave column width)
(damping scaling, condition: s < 1)
(simulation delta time, condition: dt < h/c)
This changes the height of a column. There will be no water loss or gain because the implementation will add or substract water to the surrounding columns.
This changes the velocity of a column. There will be water loss or gain. No implementation to stop this is in place.

Simulation

Click on a column to create a wave.