I took my regular panning uv water and added vertex animation to it. There are some special considerations to take into account when doing vertex animation, namely that your vertex normals will no longer be valid. Because of this, I rebuild the normals inside the vertex shader before passing them along. I use 2 adjacent points to each vertex along the tangent and binormal of the vertex to recalculate the normals. I’m sure there is something more efficient to do this with but it works for now.The animation itself is kinda cool. The main animation creates wave crests with 3 sums of a Fourier series. While this gives decent movement, I felt the peaks all looked too soft and there was no back and forth movement. After watching this video, I realized that good looking wave peaks couldn’t be achieved with pure sine waves. In order to achieve this, I would need to push all the verts toward their peaks like in the animation.After a few hours of struggle, I realized that I could get this movement with a cosine function, running on the same frequency as the sine function. Basically the cosine has a similar wave shape as the sine, but reaches its peak and trough a slightly different time than the sine wave. By modifying the vert position in the parallel direction as the wave is travelling, we can push all the verts toward the peaks (for a sine wave traveling down z, add to the z direction according to the cosine wave).

As an added bonus, an object modified with this function would exhibit the same bobbing and back and forth motion as a boat would in real life when a wave hits it, without doing any nasty collision detection. So you could actually make “floating” objects that behave naturally with very little effort 🙂 

Maya CGFX Shader:

phongnormalvertexanim.cgfx
File Size: 14 kb
File Type: cgfx

Download File


Unity SHADER File:

phongnormalvertexanim.shader
File Size: 12 kb
File Type: shader

Download File


Edit: Did a little research and found out there is actually a formula that does exactly this called Gerstner Waves. MFW I discover my  idea has already been done and is so well known it predates computer graphics:

Leave a Reply

Your email address will not be published. Required fields are marked *