View Full Version : Trouble with Gerstner Waves Normals

08-26-2017, 03:17 AM
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 https://developer.nvidia.com/gpugems/GPUGems/gpugems_ch01.html) 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,

08-29-2017, 12:40 PM
I have added a geometry shader in between to draw each normal and each normal per face and this is what i got:

As you can see some normals are being negative for a part of a wave cycle which should never happen, any ideas on why this is happening?

Thank you