I'm working in Java, using LWJGL3. I'm creating a 3D world, and would like a quad (that represents water) to have its vertices "fluctuate" away from the center of the terrain, in all directions. I was thinking of having some sort of function in the Vertex Shader, that calculates the y offset based on the Sin graph. It would take in a uniform that would be the center of the terrain, and thus would be able to correctly calculate the new position for each vertex.
Any suggestions on the maths I'd need to calculate this? I've included a few photos to try and exaggerate what I mean.
Green - Terrain
Blue - Water
EDIT: I added this into the Veretx shader, but the quad now vibrates on the spot. However it does look like the sin graph (see photo).
vec4 worldPosition = transformationMatrix * vec4(position, 1.0);
float disX = abs(center.x - worldPosition.x);
float disZ = abs(center.z - worldPosition.z);
float actualTime = time;
float distance1 = sqrt((disX * disX) + (disZ * disZ));
float newY = 20.0 * sin((distance1 - time)/20.0);
worldPosition.y = newY;
This question should perhaps be posted in Game Development SE site. However, I shall try to provide a solution for its mathematical part.
The points of water surface, $P(x,y,z)$ can be modeled to belong to the surface:
$\frac{\sin(x^2 + y^2 - t)}{(x^2 + y^2 + 1)}$ where
A visualization of this can be found here