# Water Simulation

## The Idea

The goal of this assignment was to write shaders and to learn various techniques for performing surface perturbation and lighting tasks. Our extension animated waves and added a droplet type effect.

## Implementation

We modified our displacement mapping in our vertex shader so it now took in time as a parameter. With this new parameter we could express our height function as a function of position as well as time. The waves are created by a combination of sine and cosine waves and the droplet affect is also a sine wave that is a function of the distance from the center of the texture as well as time.

The following was used to generate the regular waves:

$val1 = a1* cos( 2πf * (u + c1*t)) * cos(2πf *(v + c2*t))$
$val2 = a2 * sin\left( 2\pi f * \left(u + c3*t\right)\right) * sin\left(2\pi f * \left(u + c4 *t\right)\right)$
$val = val1 * \left(t\right) + val2 *\left(1.0 - t\right)$
$val3 = a2* sin\left(2\pi f * \left(\left(c5*u + c6*v\right) + c7*t\right)\right)$
$val = val1 + val2 + val3$

where val is the calculated height of the wave at point u v.

To calculate the droplet-like animation we used the following equation:

$val4 = a* sin\left(dist *2.0\pi f * t\right)$

and this val4 was added to val( the final height of the point). To have the droplet-like effect fade out we used eased it out as we eased the other function in.