Moetman

07-02-2017, 07:36 PM

Hi I have this Gerstner function:

float PI = 3.14159265358979323846264;

P = pos;

for (int i = 0; i < numWaves; ++i) {

float W = length(directions[i]);//wavelengths[i] ; // wavelength

float frequency = 2.0 * PI / wavelengths[i]; // Frequency or k

float phase = speeds[i] * (2/W); // Phase

float Q = steepness[i]/(frequency * W * 4.0); // Steepness / phase

P.x += (speeds[i] * (2/length)) * length * directions[i].x * cos(frequency * dot( directions[i].xy , pos.xy) + (speeds[i] * (2/length)) * time);

P.y += (speeds[i] * (2/length)) * length * directions[i].y * cos(frequency * dot( directions[i].xy , pos.xy) + (speeds[i] * (2/length)) * time);

P.z += length * cos(frequency * dot( directions[i].xy , pos.xy) + (speeds[i] * (2/length)) * time);

So I have a vector function f(x,y,z) -> (P.x,P.y,P.z).

I know I have to calculate the normal analytically as I'm displacing the vertex in the shader. I just have no idea how to go about it. I've tried getting the Jacobian

in Maple and Matlab, but aren't getting the right results. Could someone with a little Calculus knowledge guide me in the right direction..?

Regards

float PI = 3.14159265358979323846264;

P = pos;

for (int i = 0; i < numWaves; ++i) {

float W = length(directions[i]);//wavelengths[i] ; // wavelength

float frequency = 2.0 * PI / wavelengths[i]; // Frequency or k

float phase = speeds[i] * (2/W); // Phase

float Q = steepness[i]/(frequency * W * 4.0); // Steepness / phase

P.x += (speeds[i] * (2/length)) * length * directions[i].x * cos(frequency * dot( directions[i].xy , pos.xy) + (speeds[i] * (2/length)) * time);

P.y += (speeds[i] * (2/length)) * length * directions[i].y * cos(frequency * dot( directions[i].xy , pos.xy) + (speeds[i] * (2/length)) * time);

P.z += length * cos(frequency * dot( directions[i].xy , pos.xy) + (speeds[i] * (2/length)) * time);

So I have a vector function f(x,y,z) -> (P.x,P.y,P.z).

I know I have to calculate the normal analytically as I'm displacing the vertex in the shader. I just have no idea how to go about it. I've tried getting the Jacobian

in Maple and Matlab, but aren't getting the right results. Could someone with a little Calculus knowledge guide me in the right direction..?

Regards