I adapted the WebGL water code from Evan Wallace to work with a terrain, although I was not successful in getting the caustics to render properly. Maybe I will try again later. The way to bounce off terrain was simply to return zero for the neighbouring cell which is terrain when averaging the 4 neighbours of a cell. Easy, right? :) I figured it out after studying the code of this WebGL ripple tank. I experimented with the shader first at ShaderToy but ended up using a different simpler version for the game.

Here is a screenshot of the ShaderToy shader: ShaderToy terrain/water shader:

Here is a screenshot of the water in my game Game water