Hello all,
I have been implementing Gerstner Waves in my engine and i have encontered a problem that as kept me from moving on :D.
The positions are being computed correctly but the computed normals (using equation 12 in this paper Chapter 1. Effective Water Simulation from Physical Models) do not seem to be correctly interpolating in the fragment shader.
Here is the code:
// Normal
for(int i = 0; i < nGerstnerWaves; i++)
{
float WA = waveFrequency[i] * waveAmplitude[i];
float waveNormal = waveFrequency[i] * dot(waveDirection[i], totalPosition.xz) + (wavePhaseConstant[i] * timeStep);
totalNormal.x += waveDirection[i].x * WA * cos(waveNormal);
totalNormal.y += waveCrest[i] * WA * sin(waveNormal);
totalNormal.z += waveDirection[i].y * WA * cos(waveNormal);
}
totalNormal.x = -totalNormal.x;
totalNormal.y = 1 - totalNormal.y;
totalNormal.z = -totalNormal.z;
totalNormal = normalize(totalNormal);
And the Wave parameters are these (just one wave for now)
{"amplitude": 1.5, "direction": [1.0, 0.0], "steepness": 0.8, "speed": 0.9, "length": 10.0}
And heres two quick videos of the issue:
Thanks in advance,
André